当前位置: 首页 > news >正文

python28种极坐标绘图函数总结

文章目录

    • 基础图
    • 误差线
    • 等高线polar
    • 场图polar
    • 统计图
    • 非结构坐标图

📊python35种绘图函数总结,3D、统计、流场,实用性拉满

matplotlib中的画图函数,大部分情况下只要声明坐标映射是polar,就都可以画出对应的极坐标图。但极坐标和直角坐标的坐标区间不同,所以有些数据和函数关系适合在直角坐标系中展示,而有些则适合在及坐标中展示。

基础图

函数坐标参数图形类别
plotx,y曲线图
stackplotx,y散点图
stemx,y茎叶图
scatterx,y散点图
polarx,y极坐标图
stepx,y步阶图
barx,y条形图
barhx,y横向条形图

在这里插入图片描述
bar和barh的对偶关系稍微有些抽象,可以理解为前者是以角度方向为x轴;而barh则是以半径方向为x轴。

代码如下

import matplotlib.pyplot as plt
import numpy as npx = np.arange(20)/2
y = xfDct = {"plot" : plt.plot,  "stackplot": plt.stackplot,"stem" : plt.stem,  "scatter"  : plt.scatter,         "polar": plt.polar, "step"     : plt.step, "bar"  : plt.bar,   "barh"     : plt.barh, }fig = plt.figure(figsize=(14,6))
for i,key in enumerate(fDct, 1):ax = fig.add_subplot(2,4,i, projection="polar")fDct[key](x, y)plt.title(key)plt.tight_layout()
plt.show()

误差线

函数坐标图形类别
errorbarx,y,xerr,yerr误差线
fill_betweenx,y1,y2纵向区间图
fill_betweenxy, x1, x2横向区间图

在这里插入图片描述

代码如下

x = np.arange(20)/2
y = x
y1, y2 = 0.9*y, 1.1*y
x1, x2 = 0.9*x, 1.1*x
xerr = np.abs([x1, x2])/10
yerr = np.abs([y1, y2])/10fig = plt.figure(figsize=(12,4))ax = fig.add_subplot(141, projection='polar')
ax.errorbar(x, y, yerr=yerr)
plt.title("errorbar with yerr")ax = fig.add_subplot(142, projection='polar')
ax.errorbar(x, y, xerr=xerr)
plt.title("errorbar with xerr")ax = fig.add_subplot(143, projection='polar')
ax.fill_between(x, y1, y2)
plt.title("fill_between")ax = fig.add_subplot(144, projection='polar')
ax.fill_betweenx(y, x1, x2)
plt.title("fill_betweenx")plt.tight_layout()
plt.show()

等高线polar

绘图函数坐标说明
contour[x,y,]z等高线
contourf[x,y,]z填充等高线
pcolormesh[x,y,]z伪彩图

由于imshow默认其绘图坐标是标准的1x1网格,而在极坐标种,这种网格的尺寸会随着r的增大而增大,从而变得极其不实用,所以下面对极坐标图的演示,就不包含imshow了。

在这里插入图片描述

代码如下

X, Y = np.indices([100,100])
X = X/100*np.pi*2
Y = Y/25 - 2
Z = (1 - np.sin(X) + np.cos(X)**5 + Y**3) * np.exp(-Y**2)fDct = {"contour": plt.contour, "contourf":plt.contourf, "pcolormesh" : plt.pcolormesh}fig = plt.figure(figsize=(9,3))
for i,key in enumerate(fDct, 1):ax = fig.add_subplot(1,3,i, projection='polar')fDct[key](X,Y,Z)plt.title(key)plt.tight_layout()
plt.show()

场图polar

绘图函数坐标说明
quiverx,y,u,v向量场图
streamplotx,y,u,v流场图
barbsx,y,u,v风场图

在这里插入图片描述

代码如下

Y, X = np.indices([10,10])
X = X/10*np.pi*2.5
Y = Y#Y, X = np.indices([6,6])/0.75 - 4
U = 6*np.sin(X) + Y
V = Y - 6*np.sin(X)dct = {"quiver":plt.quiver, "streamplot":plt.streamplot, "barbs" :plt.barbs}fig = plt.figure(figsize=(12,4))for i,key in enumerate(dct, 1):ax = fig.add_subplot(1,3,i,projection='polar')dct[key](X,Y,U,V)plt.title(key)plt.tight_layout()
plt.show()

统计图

绘图函数坐标说明
histx数据直方图
boxplotx箱线图
violinplotx小提琴图
enventplotx平行线疏密图
hist2dx,y二维直方图
hexbinx,y钻石图
piex饼图

极坐标在绘制直方图的时候,需要注意其横坐标是以 2 π 2\pi 2π为周期的,也就是说随机变量的最大值和最小值不得相差 2 π 2\pi 2π,否则会导致重叠。

在这里插入图片描述
由于极坐标绘图本质上是一种坐标映射,所以并不会把0和360°真正地等同起来,所以在hist2d中,整个图像并没有闭合。而最有意思的是饼图,直接给压扁了,让人很难一下子看出不同组分的比例关系。

代码如下

x = np.random.standard_normal(size=1000)dct = {"hist"  : plt.hist, "violinplot" : plt.violinplot,"boxplot": plt.boxplot}fig = plt.figure(figsize=(10,6))
for i,key in enumerate(dct, 1):ax = fig.add_subplot(2,3,i, projection='polar')dct[key](x)plt.title(key)ax = fig.add_subplot(234, projection='polar')
ax.eventplot(x)
plt.title("eventplot")x = np.random.randn(5000)
y = 1.2 * x + np.random.randn(5000) / 3
ax = fig.add_subplot(235, projection='polar')
ax.hist2d(x, y, bins=[np.arange(-3,3,0.1)] * 2)
plt.title("hist2d")ax = fig.add_subplot(236, projection='polar')
ax.pie([1,2,3,4,5])
plt.title("pie")plt.tight_layout()
plt.show()

非结构坐标图

绘图函数坐标说明
tricontourx,y,z非结构等高线
tricontourfx,y,z非结构化填充等高线
tricolorx,y,z非结构化伪彩图
triplotx,y三角连线图

在这里插入图片描述

代码如下

x = np.random.uniform(0, np.pi*2, 256)
y = np.random.uniform(-2, 2, 256)
z = (1 - np.sin(x) + np.cos(x)**5 + y**3) * np.exp(-y**2)levels = np.linspace(z.min(), z.max(), 7)fig = plt.figure(figsize=(12,4))ax = fig.add_subplot(141, projection='polar')
ax.plot(x, y, 'o', markersize=1, color='lightgrey', alpha=0.5)
ax.tricontour(x, y, z, levels=levels)
plt.title("tricontour")ax = fig.add_subplot(142, projection='polar')
ax.plot(x, y, 'o', markersize=1, color='lightgrey', alpha=0.5)
ax.tricontourf(x, y, z, levels=levels)
plt.title("tricontourf")ax = fig.add_subplot(143, projection='polar')
ax.plot(x, y, 'o', markersize=1, color='lightgrey', alpha=0.5)
ax.tripcolor(x, y, z)
plt.title("tripcolor")ax = fig.add_subplot(144, projection='polar')
ax.triplot(x,y)
plt.title("triplot")plt.tight_layout()
plt.show()
http://www.lryc.cn/news/161884.html

相关文章:

  • C#编程基础(万字详解,这一篇就够了)
  • SpringBoot中自定义注解
  • 《TCP/IP网络编程》阅读笔记--地址族和数据序列
  • 【C++】可变参数模板
  • WPF Flyout风格动画消息弹出消息提示框
  • Spring Boot 集成 Redis
  • Java线程之间通信方式
  • 【LeetCode-中等题】367. 有效的完全平方数
  • 英语单词(二)
  • Django 用相对路径方式引用自定义模块 或 文件
  • 企业架构LNMP学习笔记22
  • uniapp和小程序设置tabBar和显示与隐藏tabBar
  • 物联网、无线通讯
  • Pod和容器设计模式
  • docker系列(3) - 常用软件安装
  • Apache Hive之数据查询
  • OpenCV---视频操作
  • 《TCP/IP网络编程》阅读笔记--进程间通信
  • mysql中show status参数介绍
  • Tomcat服务的部署及配置优化
  • 入门力扣自学笔记279 C++ (题目编号:1123)
  • 【AIGC专题】Stable Diffusion 从入门到企业级实战0402
  • 【Spring事务】Spring事务的传播机制(通俗易懂)
  • 使用 Python 的高效相机流
  • pycharm使用
  • C++项目实战——基于多设计模式下的同步异步日志系统-②-相关技术补充(不定参函数)
  • iOS开发Swift-10-位置授权, cocoapods,API,天气获取,城市获取-和风天气App首页代码
  • CNN(七):ResNeXt-50算法的思考
  • 【人月神话】深入了解软件工程和项目管理
  • 52、基于函数式方式开发 Spring WebFlux 应用