简体   繁体   English

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

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

Currently I have the following script that generates a polar plot of azimuth/radius data. 目前我有以下脚本生成方位角/半径数据的极坐标图。 "R1" is simple a list of values of [azimuth, inclination] derived from a table in ArcGIS. “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()

At the moment this creates the following plot: 目前,这会产生以下情节:

在此输入图像描述

How can I "invert" the fill so that what is filled with gray will be white, and what is white will be gray? 如何“反转”填充,使填充灰色的内容为白色,白色内容为灰色?

I have tried ax.fill_betweenx(theta,90,r,color='0.75') and that didn't work. 我尝试过ax.fill_betweenx(theta,90,r,color ='0.75')并且没有用。 I have been battling with this for some time now to no avail. 我一直在与此争斗一段时间无济于事。

ANY help or suggestions are greatly appreciated! 非常感谢任何帮助或建议!

If there is any way I can make this clearer, please let me know in the comments. 如果有任何方法可以让我更清楚,请在评论中告诉我。

Depending on what you want to do with this later, the quickest way is to simply make the background gray and the fill white: 根据您以后要执行的操作,最快捷的方法是将背景设置为灰色并填充白色:

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