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 注解,从名字上看是注释,解释.但功能却不仅仅是注释 ...
随机推荐
- 4.1《想成为黑客,不知道这些命令行可不行》(Learn Enough Command Line to Be Dangerous)—目录结构
Unix风格的目录结构通常使用一个目录名列表并用正斜杠分隔来表示,这样我们可以结合ls命令: $ ls /Users/mhartl/ruby 或者 $ ls /usr/local/bin 正如图20, ...
- BZOJ1816 CQOI2010 扑克牌 贪心
题目传送门:https://www.lydsy.com/JudgeOnline/problem.php?id=1816 题意:有$N$堆牌,第$i$堆牌有$c_i$张牌,还有$M$张$joker$,每 ...
- KMeans算法分析以及实现
KMeans KMeans是一种无监督学习聚类方法, 目的是发现数据中数据对象之间的关系,将数据进行分组,组内的相似性越大,组间的差别越大,则聚类效果越好. 无监督学习,也就是没有对应的标签,只有数据 ...
- CentOS安装noVNC,以Web方式交付VNC远程连接
什么是noVNC noVNC 是一个 HTML5 VNC 客户端,采用 HTML 5 WebSockets, Canvas 和 JavaScript 实现,noVNC 被普遍用在各大云计算.虚拟机控制 ...
- Spring+SpringMVC+MyBatis+easyUI整合进阶篇(十二)Spring集成Redis缓存
作者:13 GitHub:https://github.com/ZHENFENG13 版权声明:本文为原创文章,未经允许不得转载. 整合Redis 本来以为类似的Redis教程和整合代码应该会很多,因 ...
- WordPress更新时提示无法连接到FTP服务器的解决方案
这几天在搭建主站的时候,更新wordpress时无法连接到FTP原因服务器 解决方法如下: 在WordPress目录下找到wp-config.php文件并编辑,在最后一行加上: define('FS_ ...
- 手机APP自动化之uiautomator2 +python3 UI自动化
题记: 之前一直用APPium直到用安卓9.0 发现uiautomatorviewer不支持安卓 9.0,点击截屏按钮 一直报错,百度很久解决方法都不可以,偶然间看见有人推荐:uiautomator ...
- BGFX 渲染引擎中着色器代码的调试方法
在实时渲染的图形开发中,着色器代码(Shader)越来越复杂,于是单纯的靠经验和不断试错的开发和调试方法早已不能满足实际需求.使用调试工具进行调试,成为开发中重要的方法.Bgfx 是一款跨平台.抽象封 ...
- sqli-labs less 5-6
sqli-labs less 5-6 从源代码中可以看到,运行返回结果正确的时候只返回you are in....,不会返回数据库当中的信息了,以前的union联合查询就不能用了,开始尝试盲注. 简单 ...
- webpack详细配置解析
阅读本文之前,先看下面这个webpack的配置文件,如果每一项你都懂,那本文能带给你的收获也许就比较有限,你可以快速浏览或直接跳过:如果你和十天前的我一样,对很多选项存在着疑惑,那花一段时间慢慢阅读本 ...