MCPcopy Index your code
hub / github.com/matplotlib/matplotlib / SecondaryAxis

Class SecondaryAxis

lib/matplotlib/axes/_secondary_axes.py:13–290  ·  view source on GitHub ↗

General class to hold a Secondary_X/Yaxis.

Source from the content-addressed store, hash-verified

11
12
13class SecondaryAxis(_AxesBase):
14 """
15 General class to hold a Secondary_X/Yaxis.
16 """
17
18 def __init__(self, parent, orientation, location, functions, transform=None,
19 **kwargs):
20 """
21 See `.secondary_xaxis` and `.secondary_yaxis` for the doc string.
22 While there is no need for this to be private, it should really be
23 called by those higher level functions.
24 """
25 _api.check_in_list(["x", "y"], orientation=orientation)
26 self._functions = functions
27 self._parent = parent
28 self._orientation = orientation
29 self._ticks_set = False
30
31 fig = self._parent.get_figure(root=False)
32 if self._orientation == 'x':
33 super().__init__(fig, [0, 1., 1, 0.0001], **kwargs)
34 self._axis = self.xaxis
35 self._locstrings = ['top', 'bottom']
36 self._otherstrings = ['left', 'right']
37 else: # 'y'
38 super().__init__(fig, [0, 1., 0.0001, 1], **kwargs)
39 self._axis = self.yaxis
40 self._locstrings = ['right', 'left']
41 self._otherstrings = ['top', 'bottom']
42 self._parentscale = None
43 # this gets positioned w/o constrained_layout so exclude:
44
45 self.set_location(location, transform)
46 self.set_functions(functions)
47
48 # styling:
49 otheraxis = self.yaxis if self._orientation == 'x' else self.xaxis
50 otheraxis.set_major_locator(mticker.NullLocator())
51 otheraxis.set_ticks_position('none')
52
53 self.spines[self._otherstrings].set_visible(False)
54 self.spines[self._locstrings].set_visible(True)
55
56 if self._pos < 0.5:
57 # flip the location strings...
58 self._locstrings = self._locstrings[::-1]
59 self.set_alignment(self._locstrings[0])
60
61 def set_alignment(self, align):
62 """
63 Set if axes spine and labels are drawn at top or bottom (or left/right)
64 of the Axes.
65
66 Parameters
67 ----------
68 align : {'top', 'bottom', 'left', 'right'}
69 Either 'top' or 'bottom' for orientation='x' or
70 'left' or 'right' for orientation='y' axis.

Callers 2

secondary_xaxisMethod · 0.90
secondary_yaxisMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…