Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Polar tick improvements #9068

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Sep 26, 2017
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add a custom ThetaTick for polar plots.
This is able to add a position-dependent rotation to the tick marker,
ensuring it is correctly perpendicular to the spine. It also rotates the
tick label so that it is parallel to the spine.
  • Loading branch information
QuLogic committed Sep 25, 2017
commit 30b4a6c8c807a17e647cb92531a7aaea3213ecc0
59 changes: 56 additions & 3 deletions 59 lib/matplotlib/projections/polar.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import matplotlib.axis as maxis
from matplotlib import cbook
from matplotlib import docstring
import matplotlib.markers as mmarkers
import matplotlib.patches as mpatches
import matplotlib.path as mpath
from matplotlib import rcParams
Expand Down Expand Up @@ -240,6 +241,58 @@ def zoom(self, direction):
return self.base.zoom(direction)


class ThetaTick(maxis.XTick):
"""
A theta-axis tick.

This subclass of `XTick` provides angular ticks with some small
modification to their re-positioning such that ticks are rotated based on
tick location. This results in ticks that are correctly perpendicular to
the arc spine. Labels are also rotated to be parallel to the spine.
"""
def _get_text1(self):
t = maxis.XTick._get_text1(self)
t.set_rotation_mode('anchor')
return t

def _get_text2(self):
t = maxis.XTick._get_text2(self)
t.set_rotation_mode('anchor')
return t

def update_position(self, loc):
maxis.XTick.update_position(self, loc)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

super?

axes = self.axes
angle = (loc * axes.get_theta_direction() +
axes.get_theta_offset() - np.pi / 2)

if self.tick1On:
marker = self.tick1line.get_marker()
if marker in (mmarkers.TICKUP, '|'):
trans = mtransforms.Affine2D().scale(1.0, 1.0).rotate(angle)
elif marker == mmarkers.TICKDOWN:
trans = mtransforms.Affine2D().scale(1.0, -1.0).rotate(angle)
else:
# Don't modify custom tick line markers.
trans = self.tick1line._marker._transform
self.tick1line._marker._transform = trans
if self.tick2On:
marker = self.tick2line.get_marker()
if marker in (mmarkers.TICKUP, '|'):
trans = mtransforms.Affine2D().scale(1.0, 1.0).rotate(angle)
elif marker == mmarkers.TICKDOWN:
trans = mtransforms.Affine2D().scale(1.0, -1.0).rotate(angle)
else:
# Don't modify custom tick line markers.
trans = self.tick2line._marker._transform
self.tick2line._marker._transform = trans

if self.label1On:
self.label1.set_rotation(np.rad2deg(angle) + self._labelrotation)
if self.label2On:
self.label2.set_rotation(np.rad2deg(angle) + self._labelrotation)


class ThetaAxis(maxis.XAxis):
"""
A theta Axis.
Expand All @@ -255,7 +308,7 @@ def _get_tick(self, major):
tick_kw = self._major_tick_kw
else:
tick_kw = self._minor_tick_kw
return maxis.XTick(self.axes, 0, '', major=major, **tick_kw)
return ThetaTick(self.axes, 0, '', major=major, **tick_kw)

def _wrap_locator_formatter(self):
self.set_major_locator(ThetaLocator(self.get_major_locator()))
Expand Down Expand Up @@ -587,10 +640,10 @@ def get_xaxis_transform(self, which='grid'):
return self._xaxis_transform

def get_xaxis_text1_transform(self, pad):
return self._xaxis_text1_transform, 'center', 'center'
return self._xaxis_text1_transform, 'bottom', 'center'

def get_xaxis_text2_transform(self, pad):
return self._xaxis_text2_transform, 'center', 'center'
return self._xaxis_text2_transform, 'top', 'center'

def get_yaxis_transform(self, which='grid'):
if which in ('tick1', 'tick2'):
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.