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

Skip to content

Commit b58217b

Browse files
committed
ENH: add secondary x axis
1 parent 0919861 commit b58217b

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
safe_first_element)
3939
from matplotlib.container import BarContainer, ErrorbarContainer, StemContainer
4040
from matplotlib.axes._base import _AxesBase, _process_plot_format
41+
from matplotlib.axes._secondary_axes import Secondary_Xaxis
4142

4243
_log = logging.getLogger(__name__)
4344

@@ -639,7 +640,7 @@ def indicate_inset_zoom(self, inset_ax, **kwargs):
639640

640641
return rectpatch, connects
641642

642-
def secondary_xaxis(self, loc, conversion, *, **kwargs):
643+
def secondary_xaxis(self, loc, conversion, **kwargs):
643644
"""
644645
Add a second x-axis to this axes.
645646
@@ -675,6 +676,7 @@ def secondary_xaxis(self, loc, conversion, *, **kwargs):
675676
"""
676677
secondary_ax = Secondary_Xaxis(self, loc, conversion, **kwargs)
677678
self.add_child_axes(secondary_ax)
679+
return secondary_ax
678680

679681

680682
def text(self, x, y, s, fontdict=None, withdash=False, **kwargs):

lib/matplotlib/axes/_base.py

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2510,7 +2510,16 @@ def _update_title_position(self, renderer):
25102510
y = 1.0
25112511
# need to check all our twins too...
25122512
axs = self._twinned_axes.get_siblings(self)
2513-
2513+
# and all the children
2514+
for ax in self.child_axes:
2515+
if ax is not None:
2516+
locator = ax.get_axes_locator()
2517+
if locator:
2518+
pos = locator(self, renderer)
2519+
ax.apply_aspect(pos)
2520+
else:
2521+
ax.apply_aspect()
2522+
axs = axs + [ax]
25142523
for ax in axs:
25152524
try:
25162525
if (ax.xaxis.get_label_position() == 'top'
@@ -2542,12 +2551,15 @@ def draw(self, renderer=None, inframe=False):
25422551

25432552
# prevent triggering call backs during the draw process
25442553
self._stale = True
2545-
locator = self.get_axes_locator()
2546-
if locator:
2547-
pos = locator(self, renderer)
2548-
self.apply_aspect(pos)
2549-
else:
2550-
self.apply_aspect()
2554+
2555+
# loop over self and child axes...
2556+
for ax in [self]:
2557+
locator = ax.get_axes_locator()
2558+
if locator:
2559+
pos = locator(self, renderer)
2560+
ax.apply_aspect(pos)
2561+
else:
2562+
ax.apply_aspect()
25512563

25522564
artists = self.get_children()
25532565
artists.remove(self.patch)

0 commit comments

Comments
 (0)