简体   繁体   中英

fill between two lines in polar coordinates

I'm trying to fill in the space between two lines that aren't closed at both ends. I can't get plt.fill_between with plt.polar, any ideas? Here's the code I'm using to draw the lines:

import matplotlib.pyplot as plt
import numpy as np 

inner_offset = 0.05
r = np.arange(inner_offset,1. + inner_offset,1./720.)
theta = np.arange(0.,2.,1./360.)*np.pi 

plt.polar(theta/2.,r) #first part of spiral
plt.polar((theta/2.)+(np.pi/3.),r)

plt.show()

Since your radius ( "y" ) is the same, you can use plt.fill_betweenx() :

import matplotlib.pyplot as plt
import numpy as np

plt.figure()
inner_offset = 0.05
r = np.arange(inner_offset,1. + inner_offset,1./720.)
theta = np.arange(0.,2.,1./360.)*np.pi

c1 = plt.polar(theta/2.,r, color='b')[0]
x1 = c1.get_xdata()
y1 = c1.get_ydata()
c2 = plt.polar((theta/2.)+(np.pi/3.),r, color='y')[0]
x2 = c2.get_xdata()
y2 = c2.get_ydata()

plt.fill_betweenx(y1, x1, x2, color='g')
plt.show()

giving:

在此输入图像描述

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