python画极坐标图:matplotlib
标签:
pythonmatplotgnuradio |
pylab_examples example code: polar_demo.py
(Source
code,
""" Demo of a line plot on a polar axis. """ import numpy as np import matplotlib.pyplot as plt r = np.arange(0, 3.0, 0.01) theta = 2 * np.pi * r ax = plt.subplot(111, polar=True) ax.plot(theta, r, color='r', linewidth=3) ax.set_rmax(2.0) ax.grid(True) ax.set_title("A line plot on a polar axis", va='bottom') plt.show()
极坐标系中的点由一个夹角和一段相对于中心位置的距离来表示。其实在plot()函数里面本来就有一个polar的属性,让他为True就行了。下面绘制一个极坐标图像:
1 import numpy as np 2 import matplotlib.pyplot as plt 3 4 theta=np.arange(0,2*np.pi,0.02) 5 6 plt.subplot(121,polar=True) 7 plt.plot(theta,2*np.ones_like(theta),lw=2) 8 plt.plot(theta,theta/6,'--',lw=2) 9 10 plt.subplot(122,polar=True) 11 plt.plot(theta,np.cos(5*theta),'--',lw=2) 12 plt.plot(theta,2*np.cos(4*theta),lw=2) 13 plt.rgrids(np.arange(0.5,2,0.5),angle=45) 14 plt.thetagrids([0,45,90]) 15 16 plt.show() ~
整个代码很好理解,在后面的13,14行没见过。第一个plt.rgrids(np.arange(0.5,2,0.5),angle=45)
表示绘制半径为0.5 1.0
1.5的三个同心圆,同时将这些半径的值标记在45度位置的那个直径上面。plt.thetagrids([0,45,90])
表示的是在theta为0,45,90度的位置上标记上度数。
http://img1.tuicool.com/qqaueu.jpg

加载中…