开发者

matplotlib, rectangular plot in polar axes

开发者 https://www.devze.com 2023-04-08 13:14 出处:网络
Is it possible to have a standard rectangular (aka Cartesian)plot, but displayed on a polar set of 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 开发者_C百科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()
0

精彩评论

暂无评论...
验证码 换一张
取 消