简体   繁体   中英

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.

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. 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!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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