Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make the angles in a matplotlib polar plot go clockwise with 0° at the top?

I am using matplotlib and numpy to make a polar plot. Here is some sample code:

import numpy as N import matplotlib.pyplot as P  angle = N.arange(0, 360, 10, dtype=float) * N.pi / 180.0 arbitrary_data = N.abs(N.sin(angle)) + 0.1 * (N.random.random_sample(size=angle.shape) - 0.5)  P.clf() P.polar(angle, arbitrary_data) P.show() 

You will notice that 0° is at 3 o'clock on the plot, and the angles go counterclockwise. It would be more useful for my data visualization purposes to have 0° at 12 o'clock and have the angles go clockwise. Is there any way to do this besides rotating the data and manually changing the axis labels?

like image 383
ptomato Avatar asked Mar 10 '10 14:03

ptomato


People also ask

How do you rotate a polar plot in Matlab?

Assuming you want to rotate by a multiple of 90 degrees, you can set the rotation of a polar plot by setting the ThetaZeroLocation , which sets where on the plot the zero angle is located. By default this is set to 'left' -- you can change this to one of 'left' , 'right' , 'bottom' , or 'top' .

How do you plot an angle in Python?

Plot two Intersecting lines. Find the point of Intersection marked with a color. Plot a circle in such a way that the point of Intersection of two lines is the same as Center of Circle. Mark it as a point where the circle will intersect with straight lines and plot that two points where we find the angle between them.

How do you plot one direction in Python?

The quickest way to generate a simple, 1-D plot is using the pyplot. plot() function. the figure and axis objects and plots the data onto them. the figure and axes objects automatically, and is the simplest way to create a plot.


2 Answers

Updating this question, in Matplotlib 1.1, there are now two methods in PolarAxes for setting the theta direction (CW/CCW) and location for theta=0.

Check out http://matplotlib.sourceforge.net/devel/add_new_projection.html#matplotlib.projections.polar.PolarAxes

Specifically, see set_theta_direction() and set_theta_offset().

Lots of people attempting to do compass-like plots it seems.

like image 146
Klimaat Avatar answered Oct 02 '22 16:10

Klimaat


To expand klimaat's answer, with an example:

from math import radians import matplotlib.pyplot as plt  angle=[0.,5.,10.,15.,20.,25.,30.,35.,40.,45.,50.,55.,60.,65.,70.,75.,\        80.,85.,90.,95.,100.,105.,110.,115.,120.,125.]  angle = [radians(a) for a in angle]  lux=[12.67,12.97,12.49,14.58,12.46,12.59,11.26,10.71,17.74,25.95,\      15.07,7.43,6.30,6.39,7.70,9.19,11.30,13.30,14.07,15.92,14.70,\      10.70,6.27,2.69,1.29,0.81]  plt.clf() sp = plt.subplot(1, 1, 1, projection='polar') sp.set_theta_zero_location('N') sp.set_theta_direction(-1) plt.plot(angle, lux) plt.show() 

enter image description here

  • matplotlib: Developer's guide for creating scales and transformations
like image 43
user90855 Avatar answered Oct 02 '22 16:10

user90855