Python自学笔记——matplotlib极坐标.md
一、极坐标
在平面内取一个定点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小讲堂
Python自学笔记——matplotlib极坐标.md的更多相关文章
- Python自学笔记——Matplotlib风羽自定义
[前言]对于气象专业的小学生来说,风场是预报重要的参考数据,我们所知的风羽有四种:短线代表风速2m/s,长线代表风速4m/s,空心三角代表风速20m/s,实心三角代表风速50m/s.而matplotl ...
- python自学笔记
python自学笔记 python自学笔记 1.输出 2.输入 3.零碎 4.数据结构 4.1 list 类比于java中的数组 4.2 tuple 元祖 5.条件判断和循环 5.1 条件判断 5.2 ...
- python自学笔记(一)
我没学过python,通过网上和一些图书资料,自学并且记下笔记. 很多细节留作以后自己做项目时再研究,这样能更高效一些. python基础自学笔记 一.基本输入和输出 pthon3.0用input提示 ...
- python自学笔记一
之前看过一段时间的小甲鱼零基础自学python,b站上有高清免费资源[av4050443],但是作为零基础实在学得艰难,下载了python核心编程pdf,在这里做一些笔记. 虽然使用的是第二版的教材, ...
- Python 自学笔记(一)环境搭建
一,关于Python的介绍 关于Python的介绍,我不想多说了,网上随便一搜,很多介绍,这里我主要写下我的自学Python的 过程,也是为了促进我能继续学习下去. 二,环境搭建 1,这里我只讲解Wi ...
- python 自学笔记(四) 列表
有几天没有更新博客了,毕竟是自学,最近事情确实比较多,有时候想学的时候反而没时间,到有时间的时候反而不想学.以后得想办法改掉这个缺点,只要有时间就要学习自己想学的东西,希望自学的同学能和我共同交流,其 ...
- 如何深入系统的学习一门编程语言——python自学笔记
前言 最早接触python的时候,他并没有现在这么火,我也没把他太当回事,那时候我对python的印象就是给运维人员使用的一门很古老的语言,显然随着tensorflow(以下简称tf)的兴起,pyth ...
- python自学笔记二
:#进入循环重输文0件名 pass else:#退出循环,等待创建 break fobj = open(fname,'a')#打开或创建文件 #接下来写入文件 all = [] print('ente ...
- Python 自学笔记(二)第一个程序 Hello World
一 打印 Hello world 1,输入 Python “Hello world” 即可 2,脚本文件输出Hello World 在命令行(cmd),输入 python 文件路径+文件名 3,为什么 ...
随机推荐
- CentOs下安装PHP环境的步骤
前言 在CentOs环境下安装php开发环境,需要首先安装一些源文件,然后使用yum命令直接安装即可,在Fedora 20 源中已经有了PHP的源,直接可以使用以下命令安装即可: # yum inst ...
- C#中static void Main(string[] args) 参数详解
学习C#编程最常见的示例程序是在控制台应用程序中输出Hello World! using System; namespace DemoMainArgs { class Program { static ...
- JavaScript实现评论点赞功能
通过分析评论功能的逻辑关系,学会如何使用JavaScript实现评论.回复.点赞等各种功能 1.学会JavaScript处理日期和时间. 2.掌握Dom操作中的添加/删除子节点方法. 3.使用setT ...
- Mutillidae在kali linux上的安装
XAMPP:下载地址(https://www.apachefriends.org/download.html) Mutillidae:下载地址(http://sourceforge.net/proje ...
- [笔记]LibSVM源码剖析(java版)
之前学习了SVM的原理(见http://www.cnblogs.com/bentuwuying/p/6444249.html),以及SMO算法的理论基础(见http://www.cnblogs.com ...
- (21)IO流之对象的序列化和反序列化流ObjectOutputStream和ObjectInputStream
当创建对象时,程序运行时它就会存在,但是程序停止时,对象也就消失了.但是如果希望对象在程序不运行的情况下仍能存在并保存其信息,将会非常有用,对象将被重建并且拥有与程序上次运行时拥有的信息相同.可以使用 ...
- 27. Remove Element - 移除元素-Easy
Description: Given an array and a value, remove all instances of that value in place and return the ...
- oracle习题1~13
1. 查询Student表中的所有记录的Sname.Ssex和Class列. 2. 查询教师所有的单位即不重复的Depart列. 3. 查询Student表的所有记录. 4. 查询Score表中成绩在 ...
- jQuery ajax 与服务器交互方法
1.HTML <table> <tr> <td>用户名:</td> <td><input type="text" ...
- 转载八个最佳Python IDE
八个最佳Python IDE 作者:chszs,转载需注明.博客主页:http://blog.csdn.net/chszs Python是一种功能强大.语言简洁的编程语言.本文向大家推荐8个适合Pyt ...