Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Deprecate Tick.{gridOn,tick1On,label1On,...} in favor of set_visible.#10088

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
jklymak merged 2 commits intomatplotlib:masterfromanntzer:tick-visibility
Oct 4, 2018
Merged
Show file tree
Hide file tree
Changes fromall commits
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
13 changes: 13 additions & 0 deletionsdoc/api/api_changes/171014-AL-tickprops.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
Deprecation of redundant `Tick` attributes
``````````````````````````````````````````

The ``gridOn``, ``tick1On``, ``tick2On``, ``label1On``, and ``label2On``
`~.Tick` attributes have been deprecated. Directly get and set the visibility
on the underlying artists, available as the ``gridline``, ``tick1line``,
``tick2line``, ``label1``, and ``label2`` attributes.

The ``label`` attribute, which was an alias for ``label1``, has been
deprecated.

Subclasses that relied on setting the above visibility attributes needs to be
updated; see e.g. :file:`examples/api/skewt.py`.
86 changes: 25 additions & 61 deletionsexamples/specialty_plots/skewt.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -10,10 +10,12 @@
axes that are not orthogonal. This is handled by including a skew component to
the basic Axes transforms. Additional complexity comes in handling the fact
that the upper and lower X-axes have different data ranges, which necessitates
a bunch of custom classes for ticks,spines, and the axis to handle this.
a bunch of custom classes for ticks,spines, and axis to handle this.

"""

from contextlib import ExitStack

from matplotlib.axes import Axes
import matplotlib.transforms as transforms
import matplotlib.axis as maxis
Expand All@@ -24,66 +26,28 @@
# The sole purpose of this class is to look at the upper, lower, or total
# interval as appropriate and see what parts of the tick to draw, if any.
class SkewXTick(maxis.XTick):
def update_position(self, loc):
# This ensures that the new value of the location is set before
# any other updates take place
self._loc = loc
super().update_position(loc)

def _has_default_loc(self):
return self.get_loc() is None

def _need_lower(self):
return (self._has_default_loc() or
transforms.interval_contains(self.axes.lower_xlim,
self.get_loc()))

def _need_upper(self):
return (self._has_default_loc() or
transforms.interval_contains(self.axes.upper_xlim,
self.get_loc()))

@property
def gridOn(self):
return (self._gridOn and (self._has_default_loc() or
transforms.interval_contains(self.get_view_interval(),
self.get_loc())))

@gridOn.setter
def gridOn(self, value):
self._gridOn = value

@property
def tick1On(self):
return self._tick1On and self._need_lower()

@tick1On.setter
def tick1On(self, value):
self._tick1On = value

@property
def label1On(self):
return self._label1On and self._need_lower()

@label1On.setter
def label1On(self, value):
self._label1On = value

@property
def tick2On(self):
return self._tick2On and self._need_upper()

@tick2On.setter
def tick2On(self, value):
self._tick2On = value

@property
def label2On(self):
return self._label2On and self._need_upper()

@label2On.setter
def label2On(self, value):
self._label2On = value
def draw(self, renderer):
# When adding the callbacks with `stack.callback`, we fetch the current
# visibility state of the artist with `get_visible`; the ExitStack will
# restore these states (`set_visible`) at the end of the block (after
# the draw).
with ExitStack() as stack:
Copy link
Member

Choose a reason for hiding this comment

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

This is kind of mysterious for an example w/o a comment why you need it.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

added an explanation, I hope it helps

for artist in [self.gridline, self.tick1line, self.tick2line,
self.label1, self.label2]:
stack.callback(artist.set_visible, artist.get_visible())
needs_lower = transforms.interval_contains(
self.axes.lower_xlim, self.get_loc())
needs_upper = transforms.interval_contains(
self.axes.upper_xlim, self.get_loc())
self.tick1line.set_visible(
self.tick1line.get_visible() and needs_lower)
self.label1.set_visible(
self.label1.get_visible() and needs_lower)
self.tick2line.set_visible(
self.tick2line.get_visible() and needs_upper)
self.label2.set_visible(
self.label2.get_visible() and needs_upper)
super(SkewXTick, self).draw(renderer)

def get_view_interval(self):
return self.axes.xaxis.get_view_interval()
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp