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

4
  • 1
    your question isn't very clear, can you provide the standard plot and indicate what you want to change? Commented Sep 27, 2011 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 stackoverflow.com/questions/6556361/… Otherwise please give more details. Commented Sep 27, 2011 at 16:25
  • i would like the axes to look like this , matplotlib.sourceforge.net/examples/pylab_examples/…, 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? Commented Sep 27, 2011 at 21:46
  • @user366660: you can either convert from polar coordinates to cartesian yourself (x=rcos(phi), y=rsin(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. Commented Sep 28, 2011 at 10:33

1 Answer 1

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()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.