Python:向极坐标图中添加环形扇区或楔形 [英] Python: Add a Ring Sector or a Wedge to a Polar Plot

查看:49
本文介绍了Python:向极坐标图中添加环形扇区或楔形的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个极坐标图,其中有一个特定的部分,我想用红色完全上色(这是在两条红线之间标记的部分.是否有一个函数可以对该部分进行着色?还是可以得到一个使用补丁集的实心环扇区?

I have a polar plot with a specific section that I would like to colour completely in red (it is the section marked between the two red lines. Is there a function that will color that section? Or is it possible to get a solid ring sector using the Patch Collection?

这是我的剧本:

from pylab import *
import matplotlib.pyplot as plt
import numpy as np
import pylab
from matplotlib.projections import PolarAxes



###############################################################################
###############################################################################


fig = figure()
ax = fig.add_subplot(111, projection = 'polar')


subplot(111,projection='polar')
theta = arange(1000)*2*pi/1000.

plot(theta,0.25*ones(1000),'m') #A to B Circle
plot(theta, 0.65*ones(1000), 'm') # B to C Circle
plot([0, 0],[0.25,0.65],'m') # A to B 0 degrees line  
plot([pi/4.,pi/4.],[0.25, 0.65], 'm') # A to B 45 degrees line
plot([pi/2, pi/2.],[0.25, 0.65], 'm') # A to B 90 degrees line
plot([3*pi/4.,3*pi/4],[0.25, 0.65], 'm') # A to B 135 degrees line

plot([pi,pi],[0.25,0.65],'m') # A to B 180 degrees line
plot([5*pi/4,5*pi/4],[0.25, 0.65], 'm') # A to B 225 degrees line
plot([3*pi/2,3*pi/2],[0.25, 0.65], 'm') # A to B 270 degrees line
plot([7*pi/4,7*pi/4],[0.25, 0.65], 'm') # A to B 315 degrees line

plot([2*pi,2*pi],[0.25,0.65],'m') # A to B 360 degrees line

plot([0, 0],[0.65,1],'m') # B to C 0 degrees line
plot([pi/6,pi/6],[0.65, 1], 'm') # B to C 30 degrees line
plot([pi/3,pi/3.],[0.65,1], 'm') # B to C 60 degrees line
plot([pi/2,pi/2],[0.65,1], 'm') # B to C 90 degrees line

plot([2*pi/3,2*pi/3],[0.65,1],'m') # B to C 120 degrees line
plot([5*pi/6,5*pi/6],[0.65,1], 'm') # B to C 150 degrees line
plot([pi,pi],[0.65,1], 'm') # B to C 180 degrees line
plot([7*pi/6,7*pi/6],[0.65,1], 'm') # B to C 210 degrees line

plot([4*pi/3,4*pi/3],[0.65,1],'r', linewidth = 5) # B to C 240 degrees line
plot([3*pi/2,3*pi/2],[0.65,1], 'r', linewidth = 5) # B to C 270 degrees line
plot([5*pi/3,5*pi/3],[0.65, 1], 'm') # B to C 300 degrees line
plot([11*pi/6,11*pi/6],[0.65,1], 'm') # B to C 330 degrees line

plot([2*pi,2*pi],[0.65,1],'m') # B to C 360 degrees line




#patches = [Wedge((0,0), 1, 4*pi/3, 3*pi/2)]
#p = PatchCollection(patches)
#ax.add_collection(p)

rgrids((1,1),('',''))


ax.set_theta_zero_location("N")
ax.set_theta_direction('clockwise')         

show()

推荐答案

楔形似乎是可行的方法,但默认情况下它也会被转换为极坐标.您可以为楔形提供轴变换,这在视觉上是可行的,但如果您希望根据数据绘制楔形,则很难.

A wedge seems to be the way to go, but by default it will also be transformed to polar coordinates. You could give the wedge the axes transformation, that would visually work, but make it hard if you want wedges plotted based on data.

它可以这样做:

ax.add_artist(Wedge((.5,.5), 0.53, 180, 215, width=0.2, transform=ax.transAxes, color='red'))

这篇关于Python:向极坐标图中添加环形扇区或楔形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆