matplotlib极坐标方法详解
一、极坐标
在平面内取一个定点O,叫极点,引一条射线Ox,叫做极轴,再选定一个长度单位和角度的正方向(通常取逆时针方向)。对于平面内任何一点M,用ρ表示线段OM的长度(有时也用r表示),θ表示从Ox到OM的角度,ρ叫做点M的极径,θ叫做点M的极角,有序数对 (ρ,θ)就叫点M的极坐标,这样建立的坐标系叫做极坐标系。通常情况下,M的极径坐标单位为1(长度单位),极角坐标单位为rad(或°)

二、matplotlib绘制极坐标图
1.创建极坐标图
matplotlib的pyplot子库提供了绘制极坐标图的方法,在调用subplot()创建子图时通过设置projection='polar',便可创建一个极坐标子图,然后调用plot()在极坐标子图中绘图。
下面就创建一个极坐标子图和一个直角坐标子图进行对比。
import matplotlib.pyplot as plt
ax1 = plt.subplot(121, projection='polar')
ax2 = plt.subplot(122)
ax1.plot(theta,theta/6,'--',lw=2)
ax2.plot(theta,theta/6,'--',lw=2)
plt.show()

2.极坐标图设置
dir()命令可以得到一个对象的所有方法属性,通过比较ax1与ax2的方法属性便可知道极坐标有哪些设置方法。
>>> print(sorted(set(dir(ax1))-set(dir(ax2))))
['InvertedPolarTransform', 'PolarAffine', 'PolarTransform', 'RadialLocator', 'ThetaFormatter', '_default_rlabel_position', '_default_theta_direction', '_default_theta_offset', '_direction', '_r_label_position', '_theta_label1_position', '_theta_label2_position', '_theta_offset', '_xaxis_text1_transform', '_xaxis_text2_transform', '_yaxis_text_transform', 'get_rlabel_position', 'get_rmax', 'get_rmin', 'get_theta_direction', 'get_theta_offset', 'resolution', 'set_rgrids', 'set_rlabel_position', 'set_rlim', 'set_rmax', 'set_rmin', 'set_rscale', 'set_rticks', 'set_theta_direction', 'set_theta_offset', 'set_theta_zero_location', 'set_thetagrids', 'transProjection', 'transProjectionAffine', 'transPureProjection']
2.1 极坐标正方向
set_theta_direction方法用于设置极坐标的正方向
- 当
set_theta_direction的参数值为1,'counterclockwise'或者是'anticlockwise'的时候,正方向为逆时针; - 当
set_theta_direction的参数值为-1或者是'clockwise'的时候,正方向为顺时针; - 默认情况下正方向为逆时针
import matplotlib.pyplot as plt
import numpy as np
theta=np.arange(0,2*np.pi,0.02)
ax1= plt.subplot(121, projection='polar')
ax2= plt.subplot(122, projection='polar')
ax2.set_theta_direction(-1)
ax1.plot(theta,theta/6,'--',lw=2)
ax2.plot(theta,theta/6,'--',lw=2)
plt.show()

2.2 极坐标0°位置
set_theta_zero_location方法用于设置极坐标0°位置
- 0°可设置在八个位置,分别为N, NW, W, SW, S, SE, E, NE
- 当
set_theta_zero_location的参数值为'N','NW','W','SW','S','SE','E','NE'时,0°分别对应的位置为方位N, NW, W, SW, S, SE, E, NE; - 默认情况下0°位于E方位
import matplotlib.pyplot as plt
import numpy as np
theta=np.arange(0,2*np.pi,0.02)
ax1= plt.subplot(121, projection='polar')
ax2= plt.subplot(122, projection='polar')
ax2.set_theta_zero_location('N')
ax1.plot(theta,theta/6,'--',lw=2)
ax2.plot(theta,theta/6,'--',lw=2)
plt.show()

2.3极坐标角度网格线显示
set_thetagrids方法用于设置极坐标角度网格线显示
- 参数为所要显示网格线的角度值列表
- 默认显示0°、45°、90°、135°、180°、225°、270°、315°的网格线
import matplotlib.pyplot as plt
import numpy as np
theta=np.arange(0,2*np.pi,0.02)
ax1= plt.subplot(121, projection='polar')
ax2= plt.subplot(122, projection='polar')
ax2.set_thetagrids(np.arange(0.0, 360.0, 30.0))
ax1.plot(theta,theta/6,'--',lw=2)
ax2.plot(theta,theta/6,'--',lw=2)
plt.show()

2.4极坐标角度偏离
set_theta_offset方法用于设置角度偏离
- 参数值为弧度值数值
import matplotlib.pyplot as plt
import numpy as np
theta=np.arange(0,2*np.pi,0.02)
ax1= plt.subplot(121, projection='polar')
ax2= plt.subplot(122, projection='polar')
ax2.set_theta_offset(np.pi)
ax1.plot(theta,theta/6,'--',lw=2)
ax2.plot(theta,theta/6,'--',lw=2)
plt.show()

2.5极坐标极径网格线显示
set_rgrids方法用于设置极径网格线显示
- 参数值为所要显示网格线的极径值列表,最小值不能小于等于0
import matplotlib.pyplot as plt
import numpy as np
theta=np.arange(0,2*np.pi,0.02)
ax1= plt.subplot(121, projection='polar')
ax2= plt.subplot(122, projection='polar')
ax2.set_rgrids(np.arange(0.2,1.0,0.4))
ax1.plot(theta,theta/6,'--',lw=2)
ax2.plot(theta,theta/6,'--',lw=2)
plt.show()

2.6极坐标极径标签位置
set_rlabel_position方法用于设置极径标签显示位置
- 参数为标签所要显示在的角度
import matplotlib.pyplot as plt
import numpy as np
theta=np.arange(0,2*np.pi,0.02)
ax1= plt.subplot(121, projection='polar')
ax2= plt.subplot(122, projection='polar')
ax2.set_rlabel_position('90')
ax1.plot(theta,theta/6,'--',lw=2)
ax2.plot(theta,theta/6,'--',lw=2)
plt.show()

2.7极坐标极径范围
set_rlim方法用于设置显示的极径范围
- 参数为极径最小值,最大值
import matplotlib.pyplot as plt
import numpy as np
theta=np.arange(0,2*np.pi,0.02)
ax1= plt.subplot(121, projection='polar')
ax2= plt.subplot(122, projection='polar')
ax2.set_rlim(0.6,1.2)
ax1.plot(theta,theta/6,'--',lw=2)
ax2.plot(theta,theta/6,'--',lw=2)
plt.show()

2.8极坐标极径最大值
set_rmax方法用于设置显示的极径最大值
- 该方法要在绘制完图像后使用才有效
import matplotlib.pyplot as plt
import numpy as np
theta=np.arange(0,2*np.pi,0.02)
ax1= plt.subplot(121, projection='polar')
ax2= plt.subplot(122, projection='polar')
ax1.plot(theta,theta/6,'--',lw=2)
ax2.plot(theta,theta/6,'--',lw=2)
ax2.set_rmax(0.6)
plt.show()

2.9极坐标极径最小值
set_rmin方法用于设置显示的极径最小值
- 该方法要在绘制完图像后使用才有效
import matplotlib.pyplot as plt
import numpy as np
theta=np.arange(0,2*np.pi,0.02)
ax1= plt.subplot(121, projection='polar')
ax2= plt.subplot(122, projection='polar')
ax1.plot(theta,theta/6,'--',lw=2)
ax2.plot(theta,theta/6,'--',lw=2)
ax2.set_rmin(0.6)
plt.show()

2.10 极径对数坐标
set_rscale方法用于设置极径对数坐标
- 参数值为'linear','log','symlog'
- 默认值为'linear'
- 该方法要在绘制完图像后使用才有效
import matplotlib.pyplot as plt
import numpy as np
theta=np.arange(0,2*np.pi,0.02)
ax1= plt.subplot(121, projection='polar')
ax2= plt.subplot(122, projection='polar')
ax1.plot(theta,theta/6,'--',lw=2)
ax2.plot(theta,theta/6,'--',lw=2)
ax2.set_rlim(math.pow(10,-1),math.pow(10,0))
ax1.set_rscale('linear')
ax2.set_rscale('symlog')
plt.show()

2.11 极坐标极径网格线显示范围
set_rticks方法用于设置极径网格线的显示范围
import matplotlib.pyplot as plt
import numpy as np
theta=np.arange(0,2*np.pi,0.02)
ax1= plt.subplot(121, projection='polar')
ax2= plt.subplot(122, projection='polar')
ax2.set_rticks(np.arange(0.1, 0.9, 0.2))
ax1.plot(theta,theta/6,'--',lw=2)
ax2.plot(theta,theta/6,'--',lw=2)
plt.show()

想观看Matplotlib教学视频,了解更多Matplotlib实用技巧可关注
微信公众账号: MatplotlibClass

今日头条号:Matplotlib小讲堂

matplotlib极坐标方法详解的更多相关文章
- session的使用方法详解
session的使用方法详解 Session是什么呢?简单来说就是服务器给客户端的一个编号.当一台WWW服务器运行时,可能有若干个用户浏览正在运正在这台服务器上的网站.当每个用户首次与这台WWW服务器 ...
- Kooboo CMS - Html.FrontHtml[Helper.cs] 各个方法详解
下面罗列了方法详解,每一个方法一篇文章. Kooboo CMS - @Html.FrontHtml().HtmlTitle() 详解 Kooboo CMS - Html.FrontHtml.Posit ...
- HTTP请求方法详解
HTTP请求方法详解 请求方法:指定了客户端想对指定的资源/服务器作何种操作 下面我们介绍HTTP/1.1中可用的请求方法: [GET:获取资源] GET方法用来请求已被URI识别的资源.指定 ...
- ecshop后台增加|添加商店设置选项和使用方法详解
有时候我们想在Ecshop后台做个设置.radio.checkbox 等等来控制页面的显示,看看Ecshop的设计,用到了shop_config这个商店设置功能 Ecshop后台增加|添加商店设置选项 ...
- (转)Spring JdbcTemplate 方法详解
Spring JdbcTemplate方法详解 文章来源:http://blog.csdn.net/dyllove98/article/details/7772463 JdbcTemplate主要提供 ...
- C++调用JAVA方法详解
C++调用JAVA方法详解 博客分类: 本文主要参考http://tech.ccidnet.com/art/1081/20050413/237901_1.html 上的文章. C++ ...
- windows.open()、close()方法详解
windows.open()方法详解: window.open(URL,name,features,replace)用于载入指定的URL到新的或已存在的窗口中,并返回代表新窗口的Win ...
- CURL使用方法详解
php采集神器CURL使用方法详解 作者:佚名 更新时间:2016-10-21 对于做过数据采集的人来说,cURL一定不会陌生.虽然在PHP中有file_get_contents函数可以获取远程 ...
- JAVA 注解的几大作用及使用方法详解
JAVA 注解的几大作用及使用方法详解 (2013-01-22 15:13:04) 转载▼ 标签: java 注解 杂谈 分类: Java java 注解,从名字上看是注释,解释.但功能却不仅仅是注释 ...
随机推荐
- [Oacle][Partition]Partition操作与 Index, Global Index 的关系
[Oacle][Partition]Partition操作与 Index, Global Index 的关系: ■ Regarding the local index and the global i ...
- Centos7 64位 -- glibc-2.29 编译升级方法(已成功)
某软件出现漏洞,需要升级解决(忘了哪个)结果提示glibc版本过低. 懵懂无知的我以为glibc想其他软件一样编译升级一下就好.. 结果? 重装系统! 说真的,如非必要(或学习),请勿升级 glibc ...
- JS_各种排序方法
排序有内部排序和外部排序,内部排序是数据记录在内存中进行排序,而外部排序是因排序的数据很大,一次不能容纳全部的排序记录,在排序过程中需要访问外存. 我们这里说说八大排序就是内部排序. 当n较大,则应采 ...
- C/C++中int128的那点事
最近群友对int128这个东西讨论的热火朝天的.讲道理的话,编译器的gcc是不支持__int128这种数据类型的,比如在codeblocks 16.01/Dev C++是无法编译的,但是提交到大部分O ...
- nginx通过https方式反向代理多实例tomcat
案例说明:前面一层nginx+Keepalived部署的LB,后端两台web服务器部署了多实例的tomcat,通过https方式部署nginx反向代理tomcat请求.配置一如下: 1)LB层的ngi ...
- 对MSF八个原则的思考
第一个原则,也是MSF中最基础的一个原则,推动信息共享与沟通.这个原则的一个特点是,对于团队成员的所有工作,都会被记录下来,包括走了弯路的.出现bug但已调试解决的部分.对于新加入团队的成员或者以前没 ...
- Jquery画折线图、柱状图、饼图
1.今天做了一个折线图,首先需要导js文件.这里有一个demo:http://files.cnblogs.com/files/feifeishi/jquery_zhexiantubingtuzhuzh ...
- s标签s:if和s:set实现一个表格显示为多个表格
1.首先本来这个表格是这样的 2.这时候代码是这样的 <table cellpadding="4"> <tr> <th>指标点</th&g ...
- QT 窗口置顶功能
Qt中,保持窗口置顶的设置为: Qt::WindowFlags m_flags = windowFlags(); setWindowFlags(m_flags | Qt::WindowStaysOnT ...
- 5-Python3从入门到实战—基础之数据类型(列表-List)
Python从入门到实战系列--目录 列表定义 list:列表(list)是Python内置的一种数据类型,list是一种有序的集合,索引从0开始,可以进行截取.组合等: //创建列表 list1 = ...