极坐标图
极坐标上的柱状图
在极坐标上绘柱状图
import matplotlib.pyplot as plt
import numpy as np
def plot_polar():
# Fixing random state for reproducibility
np.random.seed(19680801)
# Compute pie slices
N = 5
theta = np.linspace(0.0, 2 * np.pi, N, endpoint=False)
radii = 10 * np.random.rand(N)
width = np.pi / 4 * np.random.rand(N)
radii = [5, 6, 8, 5, 7]
width = [0.6, 0.9, 0.7, 0.5, 0.6]
colors = ["blue","green","#7F007F","magenta", "yellow"]
ax = plt.subplot(projection='polar')
ax.bar(theta, radii, width=width, bottom=0.0, color=colors, alpha=0.5)
plt.show()
if __name__ == "__main__":
plot_polar()
极坐标画线
在极坐标上画线
import matplotlib.pyplot as plt
import numpy as np
def plot_polar_line():
r = np.arange(0, 2.0, 0.02)
theta = 2 * np.pi * r
ax = plt.subplot(projection='polar')
ax.set_facecolor('lightyellow')
ax.plot(theta, r, color="red")
ax.set_rmax(1.5)
ax.set_rticks([0.5, 1.0, 1.5])
ax.set_rlabel_position(15)
plt.show()
if __name__ == "__main__":
plot_polar_line()
极坐标图例
在极坐标上绘制图例
import matplotlib.pyplot as plt
import numpy as np
def plot_polar_line():
ax = plt.subplot(projection="polar", facecolor="lightgoldenrodyellow")
r = np.linspace(0, 3, 301)
theta = 2 * np.pi * r
ax.plot(theta, r, color="red", lw=3, label="red line")
ax.plot(theta+1.5, r, color="blue", ls="-.", lw=3, label="blue line")
angle = np.deg2rad(60.5)
ax.legend(loc="lower left",
bbox_to_anchor=(.5 + np.cos(angle)/2, .5 + np.sin(angle)/2))
plt.show()
if __name__ == "__main__":
plot_polar_line()