简体   繁体   中英

matplotlib, rectangular plot in polar axes

Is it possible to have a standard rectangular (aka Cartesian) plot, but displayed on a polar set of axes?

I just want the masking appearance of the grey border provided by the polar() function, but I do not want to convert my coordinates to polar, and use polar() .

If you just want to be able to call two arrays in rectangular coordinates, while plotting on a polar grid, this will give you what you need. Here, x and y are your arrays that, in rectangular, would give you an x=y line. It returns the same trend line but on in polar coordinates. If you require more of a mask, that actually limits some of the data being presented, then insert a line in the for loop that says something like: for r < 5.0: or whatever your criteria is for the mask.

from math import cos, sin, atan2, sqrt
import matplotlib.pyplot as plt
plt.clf()
width, height = matplotlib.rcParams['figure.figsize']
size = min(width, height)
# make a square figure
fig = figure(figsize=(size, size))
ax = fig.add_axes([0.1, 0.1, 0.8, 0.8], polar=True, axisbg='#d5de9c')
x = range(10)
y = range(10)
r = []
phi = []
for ii in range(len(x)): 
  r.append(sqrt(x[ii]**2.+y[ii]**2.))
  phi.append(atan2(y[ii],x[ii]))
ax.scatter(phi,r)
show()

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