繁体   English   中英

Python / Matplotlib极坐标绘制多边形的反向填充

[英]Python/Matplotlib Inverse Fill of Polar Plot Polygon

目前我有以下脚本生成方位角/半径数据的极坐标图。 “R1”很简单,是从ArcGIS中的表格派生的[方位角,倾角]值列表。

import matplotlib.pyplot as plt
import numpy as np 

for(a,r) in R1:
    angles.append(a)
    radius.append(90-r)
theta = np.radians(angles)
r = radius

ax = plt.subplot(111,polar=True)
ax.plot(theta, r, color='black', ls='-', linewidth=1)
ax.fill(theta,r,'0.75') ## should I use ax.fill_betweenx() ?
ax.set_theta_zero_location('N')
ax.set_theta_direction(-1)
ax.set_rmax(90)
ax.set_rmin(0)
ax.set_yticks(range(0,90,10))
yLabel=['90','','','60','','','30','','','']
ax.set_yticklabels(yLabel)
ax.grid(True)
plt.show()

目前,这会产生以下情节:

在此输入图像描述

如何“反转”填充,使填充灰色的内容为白色,白色内容为灰色?

我尝试过ax.fill_betweenx(theta,90,r,color ='0.75')并且没有用。 我一直在与此争斗一段时间无济于事。

非常感谢任何帮助或建议!

如果有任何方法可以让我更清楚,请在评论中告诉我。

根据您以后要执行的操作,最快捷的方法是将背景设置为灰色并填充白色:

import matplotlib.pyplot as plt
import numpy as np
ax = plt.subplot(111, polar=True)

theta = np.linspace(0, 2*np.pi, 100)
r = 2 + np.sin(theta * 2)
ax.patch.set_facecolor('0.5')
ax.plot(theta, r, color='black', ls='-', linewidth=1)
ax.fill(theta,r,'w')
plt.show()
plt.draw() # just to be safe!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM