Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Factor out common functionality in HostAxes.twin{,x,y}. #18913

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 1 commit into from
Nov 10, 2020
Merged
Changes from all 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
64 changes: 24 additions & 40 deletions lib/mpl_toolkits/axes_grid1/parasite_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,21 +248,11 @@ def twinx(self, axes_class=None):
The y-axis of self will have ticks on the left and the returned axes
will have ticks on the right.
"""
if axes_class is None:
axes_class = self._get_base_axes()

parasite_axes_class = parasite_axes_class_factory(axes_class)

ax2 = parasite_axes_class(self, sharex=self)
self.parasites.append(ax2)
ax2._remove_method = self._remove_any_twin

ax = self._add_twin_axes(axes_class, sharex=self)
self.axis["right"].set_visible(False)

ax2.axis["right"].set_visible(True)
ax2.axis["left", "top", "bottom"].set_visible(False)

return ax2
ax.axis["right"].set_visible(True)
ax.axis["left", "top", "bottom"].set_visible(False)
return ax

def twiny(self, axes_class=None):
"""
Expand All @@ -271,21 +261,11 @@ def twiny(self, axes_class=None):
The x-axis of self will have ticks on the bottom and the returned axes
will have ticks on the top.
"""
if axes_class is None:
axes_class = self._get_base_axes()

parasite_axes_class = parasite_axes_class_factory(axes_class)

ax2 = parasite_axes_class(self, sharey=self)
self.parasites.append(ax2)
ax2._remove_method = self._remove_any_twin

ax = self._add_twin_axes(axes_class, sharey=self)
self.axis["top"].set_visible(False)

ax2.axis["top"].set_visible(True)
ax2.axis["left", "right", "bottom"].set_visible(False)

return ax2
ax.axis["top"].set_visible(True)
ax.axis["left", "right", "bottom"].set_visible(False)
return ax

def twin(self, aux_trans=None, axes_class=None):
"""
Expand All @@ -294,23 +274,27 @@ def twin(self, aux_trans=None, axes_class=None):
While self will have ticks on the left and bottom axis, the returned
axes will have ticks on the top and right axis.
"""
if axes_class is None:
axes_class = self._get_base_axes()

parasite_axes_class = parasite_axes_class_factory(axes_class)

if aux_trans is None:
aux_trans = mtransforms.IdentityTransform()
ax2 = parasite_axes_class(self, aux_trans, viewlim_mode="transform")
self.parasites.append(ax2)
ax2._remove_method = self._remove_any_twin

ax = self._add_twin_axes(
axes_class, aux_transform=aux_trans, viewlim_mode="transform")
self.axis["top", "right"].set_visible(False)
ax.axis["top", "right"].set_visible(True)
ax.axis["left", "bottom"].set_visible(False)
return ax

ax2.axis["top", "right"].set_visible(True)
ax2.axis["left", "bottom"].set_visible(False)
def _add_twin_axes(self, axes_class, **kwargs):
"""
Helper for `.twinx`/`.twiny`/`.twin`.

return ax2
*kwargs* are forwarded to the parasite axes constructor.
"""
if axes_class is None:
axes_class = self._get_base_axes()
ax = parasite_axes_class_factory(axes_class)(self, **kwargs)
self.parasites.append(ax)
ax._remove_method = self._remove_any_twin
return ax

def _remove_any_twin(self, ax):
self.parasites.remove(ax)
Expand Down