2

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().

j-i-l
  • 10,281
  • 3
  • 53
  • 70
alex
  • 2,968
  • 3
  • 23
  • 25
  • 1
    your question isn't very clear, can you provide the standard plot and indicate what you want to change? – steabert Sep 27 '11 at 13:52
  • with the level of detail you're providing, one can only guess what you are really after. If you want to just overlay the polar axes on a Cartesian plot, this answer might be handy http://stackoverflow.com/questions/6556361/add-polar-axes-to-cartesian-plot-in-matplotlib/6556678 Otherwise please give more details. – ev-br Sep 27 '11 at 16:25
  • i would like the axes to look like this , http://matplotlib.sourceforge.net/examples/pylab_examples/polar_demo.html, but i want to be able to plot in rectangular coordinates. i basically want a circular 'mask' over the contents of rectangular plot. is this more clear? – alex Sep 27 '11 at 21:46
  • @user366660: you can either convert from polar coordinates to cartesian yourself (x=r*cos(phi), y=r*sin(phi)), or make your plot in cartesian coords, then hide the spines and ticks and overlay a floating_axes, as shown in the example through the link above. Try either of these, and if you get stuck somewhere, then show the code. – ev-br Sep 28 '11 at 10:33

1 Answers1

0

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()
cosmosis
  • 6,047
  • 3
  • 32
  • 28