python polar函数_python – Matplotlib:在PolarAxes上绘制一系列径向线

论坛 期权论坛 编程之家     
选择匿名的用户   2021-6-2 18:57   817   0

我正在尝试使用matplotlib复制某个图:它应该看起来像这样.

我已经看到可以使用PolarAxes来绘制径向点:对于istance,我使用以下片段制作了一个非常简单的极坐标图:

import matplotlib.pyplot as plt

fig = plt.figure()

# Set the axes as polar

ax = fig.add_subplot(111, polar=True)

# Draw some points

ax.plot([0],[1], 'o')

ax.plot([3],[1], 'o')

ax.plot([6],[1], 'o')

# Go clockwise

ax.set_theta_direction(-1)

# Start from the top

ax.set_theta_offset(1.570796327)

plt.savefig('test.png')

我得到这样的东西:

所以我的问题是:是否有一种方法可以像第一个图中那样绘制线条,并调整宽度以适应整个圆周?还有一些关于如何处理颜色的提示将非常感激.

更新:必须绘制的数据非常简单:每个轨道都是一个浮点数组,其范围介于0和9之间(颜色来自颜色图RdYlGn).数组长度是96的倍数.

更新2:那是我用过的剪辑

# mydata is a simple list of floats

a = np.array([[x for i in range(10)] for x in mydata])

# construct the grid

radius = np.linspace(0.2,0.4,10)

theta = np.linspace(0,2*np.pi,len(a))

R,T = np.meshgrid(radius,theta)

fig = plt.figure()

ax = fig.add_subplot(111, polar = True)

# plot the values using the appropriate colormap

ax.pcolor(T,R,a,cmap=cm.RdYlGn)

解决方法:

如果没有关于数据组织方式的更多信息,很难说再创建这个图的最佳方法是什么.在极坐标图上绘制不同宽度和颜色的线条很容易.虽然如果你需要和你的例子一样多,事情可能会变慢.我还提供了一个极地伪彩色图的例子.

import numpy as np

import matplotlib.pyplot as plt

#Create radius and theta arrays, and a 2d radius/theta array

radius = np.linspace(0.2,0.4,51)

theta = np.linspace(0,2*np.pi,51)

R,T = np.meshgrid(radius,theta)

#Calculate some values to plot

Zfun = lambda R,T: R**2*np.cos(T)

Z = Zfun(R,T)

#Create figure and polar axis

fig = plt.figure()

ax = fig.add_subplot(111, polar = True)

ax.pcolor(T,R,Z) #Plot calculated values

#Plot thick red section and label it

theta = np.linspace(0,np.pi/4,21)

ax.plot(theta,[1.23 for t in theta],color='#AA5555',linewidth=10) #Colors are set by hex codes

ax.text(np.pi/8,1.25,"Text")

ax.set_rmax(1.25) #Set maximum radius

#Turn off polar labels

ax.axes.get_xaxis().set_visible(False)

ax.axes.get_yaxis().set_visible(False)

标签:python,matplotlib

分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:3875789
帖子:775174
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP