我有一个问题,在python中,我想在 "pi2 "上面显示情节标题,我怎么做?
问题的例子。
f = plt.figure()
ax = f.add_subplot(polar=True)
N = 120
angles = np.random.uniform(0,2*np.pi,8000)
distribution = np.histogram(angles, bins=N, range=(0.0, 2*np.pi))[0]
theta = (np.arange(N)+0.5)*2*np.pi/N
width = 2*np.pi / N # Width of bars
colors = plt.cm.hsv(theta/2/np.pi)
ax.bar(theta, distribution, width=width, color=colors)
ax.set_rticks([]) # Hides radius tics
ax.set_xticklabels([r'$0$', r'$\frac{\pi}{4}$', r'$\frac{\pi}{2}$',r'$\frac{3\pi}{4}$',
r'$\pi$',r'$\frac{5\pi}{4}$',r'$\frac{3\pi}{2}$',r'$\frac{7\pi}{4}$'])
ax.tick_params(labelsize=15)
ax.set_title('Polar histogram over angles')
plt.show()
你可以使用 pad
关键字,它决定了情节和标题之间的空间。
ax.set_title('Polar histogram over angles', pad=20)