创建使用Matplotlib / Python的一堆极坐标图的

编程入门 行业动态 更新时间:2024-10-14 08:23:53
本文介绍了创建使用Matplotlib / Python的一堆极坐标图的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我需要生成一个堆栈的2D极坐标图(三维圆柱图),这样我可以看到一个扭曲的圆柱体。我想使用matplotlib,因为我已经安装了它,并要分发我的code到其他人谁只有matplotlib。例如,假设我有一大堆的2-D阵列。有没有什么办法可以做到这一点,而无需下载外部包?这是我的code。

I need to generate a stack of 2D polar plots (a 3D cylindrical plot) so that I can view a distorted cylinder. I want to use matplotlib since I already have it installed and want to distribute my code to others who only have matplotlib. For example, say I have a bunch of 2-D arrays. Is there any way I can do this without having to download an external package? Here's my code.

#!usr/bin/env python import matplotlib.pyplot as plt import numpy as np x = np.arange(-180.0,190.0,10) theta = (np.pi/180.0 )*x # in radians A0 = 55.0 offset = 60.0 R = [116.225,115.105,114.697,115.008,115.908,117.184,118.61,119.998,121.224,122.216,\ 122.93,123.323,123.343,122.948,122.134,120.963,119.575,118.165,116.941,116.074,115.66\ ,115.706,116.154,116.913,117.894,119.029,120.261,121.518,122.684,123.594,124.059,\ 123.917,123.096,121.661,119.821,117.894,116.225] fig = plt.figure() ax = fig.add_axes([0.1,0.1,0.8,0.8],polar=True) # Polar plot ax.plot(theta,R,lw=2.5) ax.set_rmax(1.5*(A0)+offset) plt.show()

我有10多个类似的2D极坐标图,我想很好地堆叠起来。如果有什么更好的办法,以可视化的三维扭曲的缸,我要建议完全开放。任何帮助将是AP preciated。谢谢!

I have 10 more similar 2D polar plots and I want to stack them up nicely. If there's any better way to visualize a distorted cylinder in 3D, I'm totally open to suggestions. Any help would be appreciated. Thanks!

推荐答案

如果你想使用matplotlib叠极坐标图,一种方法是使用Axes3D模块。你会发现,我第一次用极坐标再转换回笛卡尔当我准备好绘制出来。

If you want to stack polar charts using matplotlib, one approach is to use the Axes3D module. You'll notice that I used polar coordinates first and then converted them back to Cartesian when I was ready to plot them.

from numpy import * from mpl_toolkits.mplot3d import Axes3D import matplotlib.pyplot as plt n = 1000 fig = plt.figure() ax = fig.gca(projection='3d') for k in linspace(0, 5, 5): THETA = linspace(0, 2*pi, n) R = ones(THETA.shape)*cos(THETA*k) # Convert to Cartesian coordinates X = R*cos(THETA) Y = R*sin(THETA) ax.plot(X, Y, k-2) plt.show()

如果您 ax.plot 的最后一个参数玩,它控制每个片的高度。例如,如果您要投影所有的数据到一个单一轴你会使用 ax.plot(X,Y​​,0)。对于一个更奇特的例子,您可以将数据的高度映射到一个函数,说鞍 ax.plot(X,Y​​,-X ** 2 + Y ** 2)。通过与色彩玩为好,理论上你可以重新present多个四维数据集(虽然我不知道如何清楚,这将是)。下面的例子:

If you play with the last argument of ax.plot, it controls the height of each slice. For example, if you want to project all of your data down to a single axis you would use ax.plot(X, Y, 0). For a more exotic example, you can map the height of the data onto a function, say a saddle ax.plot(X, Y, -X**2+Y**2 ). By playing with the colors as well, you could in theory represent multiple 4 dimensional datasets (though I'm not sure how clear this would be). Examples below:

更多推荐

创建使用Matplotlib / Python的一堆极坐标图的

本文发布于:2023-11-12 19:57:49,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1582393.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:极坐标   Matplotlib   Python

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!