-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
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
Polar tick improvements #9068
Changes from 1 commit
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
73e4425
Use custom *Axis in polar plots.
QuLogic 30b4a6c
Add a custom ThetaTick for polar plots.
QuLogic 8c430e8
Add a custom RadialTick for polar plots.
QuLogic 386bb30
Apply padding to radial ticks in polar plots.
QuLogic ba242b1
Apply padding to theta ticks in polar plots.
QuLogic a2531ee
Add clip path when resetting radial ticks.
QuLogic 5f1ecbd
Add info about polar tick(label) changes.
QuLogic 9529875
Restore old polar tick label behaviour for full circles.
QuLogic 5b8d2df
Tweak padding on angular ticks to match previous.
QuLogic 33377ce
Enable ticks on some polar plot tests.
QuLogic 80a5f10
Cleanup polar tick changes based on review.
QuLogic 77e2532
Ensure polar ticks are always "right-side up".
QuLogic 228ee53
Add an 'auto' option to label rotation.
QuLogic 549c07f
Re-create polar tests images with new ticks.
QuLogic 15c57bd
Fix small grammatical errors.
QuLogic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Apply padding to theta ticks in polar plots.
- Loading branch information
commit ba242b16cd7a2290022ee62a12e377c0b9d6ebc8
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
|
||
import numpy as np | ||
|
||
import matplotlib.artist as martist | ||
from matplotlib.axes import Axes | ||
import matplotlib.axis as maxis | ||
from matplotlib import cbook | ||
|
@@ -248,18 +249,52 @@ class ThetaTick(maxis.XTick): | |
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. | ||
the arc spine. | ||
|
||
Labels are also rotated to be parallel to the spine. The label padding is | ||
also applied here since it's not possible to use a generic axes transform | ||
to produce tick-specific padding. | ||
""" | ||
def __init__(self, axes, *args, **kwargs): | ||
self._text1_translate = mtransforms.ScaledTranslation( | ||
0, 0, | ||
axes.figure.dpi_scale_trans) | ||
self._text2_translate = mtransforms.ScaledTranslation( | ||
0, 0, | ||
axes.figure.dpi_scale_trans) | ||
maxis.XTick.__init__(self, axes, *args, **kwargs) | ||
|
||
def _get_text1(self): | ||
t = maxis.XTick._get_text1(self) | ||
t.set_rotation_mode('anchor') | ||
t.set_transform(t.get_transform() + self._text1_translate) | ||
return t | ||
|
||
def _get_text2(self): | ||
t = maxis.XTick._get_text2(self) | ||
t.set_rotation_mode('anchor') | ||
t.set_transform(t.get_transform() + self._text2_translate) | ||
return t | ||
|
||
def _apply_params(self, **kw): | ||
maxis.XTick._apply_params(self, **kw) | ||
|
||
# Ensure transform is correct; sometimes this gets reset. | ||
trans = self.label1.get_transform() | ||
if not trans.contains_branch(self._text1_translate): | ||
self.label1.set_transform(trans + self._text1_translate) | ||
trans = self.label2.get_transform() | ||
if not trans.contains_branch(self._text2_translate): | ||
self.label2.set_transform(trans + self._text2_translate) | ||
|
||
def _update_padding(self, angle): | ||
padx = self._pad * np.cos(angle) / 72 | ||
pady = self._pad * np.sin(angle) / 72 | ||
self._text1_translate._t = (padx, pady) | ||
self._text1_translate.invalidate() | ||
self._text2_translate._t = (-padx, -pady) | ||
self._text2_translate.invalidate() | ||
|
||
def update_position(self, loc): | ||
maxis.XTick.update_position(self, loc) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. super? |
||
axes = self.axes | ||
|
@@ -292,6 +327,9 @@ def update_position(self, loc): | |
if self.label2On: | ||
self.label2.set_rotation(np.rad2deg(angle) + self._labelrotation) | ||
|
||
self._update_padding(self._loc * axes.get_theta_direction() + | ||
axes.get_theta_offset()) | ||
|
||
|
||
class ThetaAxis(maxis.XAxis): | ||
""" | ||
|
@@ -325,6 +363,18 @@ def _set_scale(self, value, **kwargs): | |
maxis.XAxis._set_scale(self, value, **kwargs) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. super? |
||
self._wrap_locator_formatter() | ||
|
||
def _copy_tick_props(self, src, dest): | ||
'Copy the props from src tick to dest tick' | ||
if src is None or dest is None: | ||
return | ||
maxis.XAxis._copy_tick_props(self, src, dest) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Super? |
||
|
||
# Ensure that tick transforms are independent so that padding works. | ||
trans = dest._get_text1_transform()[0] | ||
dest.label1.set_transform(trans + dest._text1_translate) | ||
trans = dest._get_text2_transform()[0] | ||
dest.label2.set_transform(trans + dest._text2_translate) | ||
|
||
|
||
class RadialLocator(mticker.Locator): | ||
""" | ||
|
@@ -752,14 +802,7 @@ def _set_lim_and_transforms(self): | |
.translate(0.0, -0.5) \ | ||
.scale(1.0, -1.0) \ | ||
.translate(0.0, 0.5) | ||
self._xaxis_text1_transform = ( | ||
flipr_transform + | ||
mtransforms.Affine2D().translate(0.0, 0.1) + | ||
self._xaxis_transform) | ||
self._xaxis_text2_transform = ( | ||
flipr_transform + | ||
mtransforms.Affine2D().translate(0.0, -0.1) + | ||
self._xaxis_transform) | ||
self._xaxis_text_transform = flipr_transform + self._xaxis_transform | ||
|
||
# This is the transform for r-axis ticks. It scales the theta | ||
# axis so the gridlines from 0.0 to 1.0, now go from thetamin to | ||
|
@@ -782,10 +825,10 @@ def get_xaxis_transform(self, which='grid'): | |
return self._xaxis_transform | ||
|
||
def get_xaxis_text1_transform(self, pad): | ||
return self._xaxis_text1_transform, 'bottom', 'center' | ||
return self._xaxis_text_transform, 'bottom', 'center' | ||
|
||
def get_xaxis_text2_transform(self, pad): | ||
return self._xaxis_text2_transform, 'top', 'center' | ||
return self._xaxis_text_transform, 'top', 'center' | ||
|
||
def get_yaxis_transform(self, which='grid'): | ||
if which in ('tick1', 'tick2'): | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not
super(ThetaTick, self)._apply_params(**kw)
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No reason; just couldn't remember which version was okay with old Python.