Polar Matplotlib图中的箭头
问题内容:
我正在尝试绘制串联RLC电路中电阻,电容器和电感器两端电压的相量。我已经完成了所有的计算,我可以得到仅正常的体面图ax.plot(theta,r,....)
。
我想使相量矢量看起来像箭头。我一直在尝试使用,ax.arrow(0,0,theta,magnitude)
但看起来仍然像是一条线。我编写的代码的要点在这里:GIST
我尝试遵循在此列表中找到的示例,因为它与我要完成的操作非常相似,它产生以下图像:
当我在计算机上运行他们的代码时,我得到
我在Xubuntu 14.04上并运行matplotlib 1.3.1。我确实看到我正在使用的示例在2009年使用matplotlib 0.99。
任何帮助将非常感激。
问题答案:
箭头大小太大,这是:
import matplotlib
import numpy as np
import matplotlib.pyplot as plt
print "matplotlib.__version__ = ", matplotlib.__version__
print "matplotlib.get_backend() = ", matplotlib.get_backend()
# radar green, solid grid lines
plt.rc('grid', color='#316931', linewidth=1, linestyle='-')
plt.rc('xtick', labelsize=15)
plt.rc('ytick', labelsize=15)
# force square figure and square axes looks better for polar, IMO
width, height = matplotlib.rcParams['figure.figsize']
size = min(width, height)
# make a square figure
fig = plt.figure(figsize=(size, size))
ax = fig.add_axes([0.1, 0.1, 0.8, 0.8], polar=True, axisbg='#d5de9c')
r = np.arange(0, 3.0, 0.01)
theta = 2*np.pi*r
ax.plot(theta, r, color='#ee8d18', lw=3)
ax.set_rmax(2.0)
plt.grid(True)
ax.set_title("And there was much rejoicing!", fontsize=20)
#This is the line I added:
arr1 = plt.arrow(0, 0.5, 0, 1, alpha = 0.5, width = 0.015,
edgecolor = 'black', facecolor = 'green', lw = 2, zorder = 5)
# arrow at 45 degree
arr2 = plt.arrow(45/180.*np.pi, 0.5, 0, 1, alpha = 0.5, width = 0.015,
edgecolor = 'black', facecolor = 'green', lw = 2, zorder = 5)
plt.show()
产生:
更好?:)