加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

python画极坐标图:matplotlib

(2014-03-17 21:42:20)
标签:

python

matplot

gnuradio

pylab_examples example code: polar_demo.py

(Source codepnghires.pngpdf)


"""
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


0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有