编程语言
首页 > 编程语言> > python-Polar Matplotlib图中的箭头

python-Polar Matplotlib图中的箭头

作者:互联网

我正在尝试绘制串联R-L-C电路中电阻器,电容器和电感器两端电压的相量.我完成了所有计算,仅使用普通的ax.plot(theta,r,….)就可以得到一个不错的图.

我想使相量矢量看起来像箭头.我一直在尝试使用ax.arrow(0,0,theta,magnitude),但看起来还是一条线.我编写的代码要点在这里:GIST

我创建的图像是

我尝试遵循在this list上找到的示例,因为它与我要完成的操作非常相似,它产生以下图像:

当我在计算机上运行他们的代码时,我得到

我在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()

产生:

更好?

标签:matplotlib,plot,polar-coordinates,python
来源: https://codeday.me/bug/20191029/1960423.html