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

Skip to content

Commit b545f64

Browse files
committed
DOC: Improve inverted axis example
Closes #28050.
1 parent d45dfbb commit b545f64

File tree

2 files changed

+41
-21
lines changed

2 files changed

+41
-21
lines changed

doc/api/index.rst

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,13 @@ description of both and their recommended use cases.
7373
Modules
7474
-------
7575

76-
Alphabetical list of modules:
76+
Public modules
77+
``````````````
7778

7879
.. toctree::
7980
:maxdepth: 1
8081

8182
matplotlib_configuration_api.rst
82-
afm_api.rst
8383
animation_api.rst
8484
artist_api.rst
8585
axes_api.rst
@@ -98,7 +98,6 @@ Alphabetical list of modules:
9898
container_api.rst
9999
contour_api.rst
100100
dates_api.rst
101-
docstring_api.rst
102101
dviread.rst
103102
figure_api.rst
104103
font_manager_api.rst
@@ -133,17 +132,27 @@ Alphabetical list of modules:
133132
text_api.rst
134133
texmanager_api.rst
135134
ticker_api.rst
136-
tight_bbox_api.rst
137-
tight_layout_api.rst
138135
transformations.rst
139136
tri_api.rst
140-
type1font.rst
141137
typing_api.rst
142138
units_api.rst
143139
widgets_api.rst
144-
_api_api.rst
145-
_enums_api.rst
146140
toolkits/mplot3d.rst
147141
toolkits/axes_grid1.rst
148142
toolkits/axisartist.rst
149143
pylab.rst
144+
145+
146+
Internal modules
147+
````````````````
148+
149+
.. toctree::
150+
:maxdepth: 1
151+
152+
afm_api.rst
153+
docstring_api.rst
154+
tight_bbox_api.rst
155+
tight_layout_api.rst
156+
type1font.rst
157+
_api_api.rst
158+
_enums_api.rst
Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,36 @@
11
"""
2-
===========
3-
Invert Axes
4-
===========
2+
=============
3+
Inverted axis
4+
=============
55
6-
You can use decreasing axes by flipping the normal order of the axis
7-
limits
6+
There are two ways to invert the direction of an axis:
7+
8+
- If you want to set *explicit axis limits* anyway, e.g. via `.set_xlim`, you can
9+
swap the limit values: ``set_xlim(4, 0)`` instead of ``set_xlim(0, 4)``.
10+
- Use `.Axis.set_inverted` if you only want to invert the axis *without modifying
11+
the limits*, i.e. keep existing limits or existing autoscaling behavior.
812
"""
913

1014
import matplotlib.pyplot as plt
1115
import numpy as np
1216

13-
t = np.arange(0.01, 5.0, 0.01)
17+
t = np.arange(0.01, 4.0, 0.01)
1418
s = np.exp(-t)
1519

16-
fig, ax = plt.subplots()
20+
fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(6.4, 4), layout="constrained")
21+
fig.suptitle('Inverted axis with ...')
22+
23+
ax1.plot(t, s)
24+
ax1.set_xlim(4, 0) # inverted fixed limits
25+
ax1.set_title('fixed limits: set_xlim(4, 0)')
26+
ax1.set_xlabel('decreasing time (s)')
27+
ax1.grid(True)
1728

18-
ax.plot(t, s)
19-
ax.set_xlim(5, 0) # decreasing time
20-
ax.set_xlabel('decreasing time (s)')
21-
ax.set_ylabel('voltage (mV)')
22-
ax.set_title('Should be growing...')
23-
ax.grid(True)
29+
# inverted axis with autoscaling
30+
ax2.plot(t, s)
31+
ax2.xaxis.set_inverted(True) # inverted axis with autoscaling
32+
ax2.set_title('autoscaling: set_inverted(True)')
33+
ax2.set_xlabel('decreasing time (s)')
34+
ax2.grid(True)
2435

2536
plt.show()

0 commit comments

Comments
 (0)