Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Move radial tick labels on a polar plot in matplotlib

From matplotlib examples:

import numpy as np
import seaborn as sbs
import matplotlib.pyplot as plt

r = np.arange(0, 3.0, 0.01)
theta = 2 * np.pi * r

ax = plt.subplot(111, polar=True)
ax.plot(theta, r, color='r', linewidth=3)
ax.set_rmax(2.0)
ax.grid(True)

ax.set_title("A line plot on a polar axis", va='bottom')
plt.show()

polar plot

How to move the radial tick labels (0.5, 1.0, 1.5, 2.0) to a different angle, say 120 deg?

like image 775
alkamid Avatar asked Apr 01 '15 15:04

alkamid


People also ask

How do I change the format of a tick in Matplotlib?

Tick formatters can be set in one of two ways, either by passing a str or function to set_major_formatter or set_minor_formatter , or by creating an instance of one of the various Formatter classes and providing that to set_major_formatter or set_minor_formatter .

How do I change the number of ticks in Matplotlib?

Locator_params() function that lets us change the tightness and number of ticks in the plots. This is made for customizing the subplots in matplotlib, where we need the ticks packed a little tighter and limited. So, we can use this function to control the number of ticks on the plots.

How do I hide axis text ticks or tick labels in Matplotlib?

By default, in the Matplotlib library, plots are plotted on a white background. Therefore, setting the color of tick labels as white can make the axis tick labels hidden. For this only color, the attribute needs to pass with w (represents white) as a value to xticks() and yticks() function.


1 Answers

With version 1.4 or later, you can use "set_rlabel_position". e.g. to place the radial ticks a long a line at, say, 135 degrees:

ax.set_rlabel_position(135)

The relevant documentation is residing here, a bit hidden under "projections".

Adding the line above yields (I don't have seaborn so this has default matplotlib formatting):

polar axis example ticks at 135 degrees

Prior to 1.4, ax.set_rgrids can take an angle argument.

like image 172
Ajean Avatar answered Sep 21 '22 07:09

Ajean