forked from matplotlib/matplotlib
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes matplotlib#28050.
- Loading branch information
Showing
1 changed file
with
21 additions
and
13 deletions.
There are no files selected for viewing
34 changes: 21 additions & 13 deletions
34
galleries/examples/subplots_axes_and_figures/invert_axes.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,33 @@ | ||
""" | ||
=========== | ||
Invert Axes | ||
=========== | ||
============= | ||
Inverted axis | ||
============= | ||
You can use decreasing axes by flipping the normal order of the axis | ||
limits | ||
To invert an axis, you can explicitly set inverted axis limits or you | ||
can invert the axis without specifying any limits using | ||
`.Axis.set_inverted`. | ||
""" | ||
|
||
import matplotlib.pyplot as plt | ||
import numpy as np | ||
|
||
t = np.arange(0.01, 5.0, 0.01) | ||
t = np.arange(0.01, 4.0, 0.01) | ||
s = np.exp(-t) | ||
|
||
fig, ax = plt.subplots() | ||
fig, (ax1, ax2) = plt.subplots(1, 2) | ||
fig.suptitle('Should be growing...') | ||
|
||
ax1.plot(t, s) | ||
ax1.set_xlim(4, 0) # decreasing time | ||
ax1.set_title('Inverted fixed limits') | ||
ax1.set_xlabel('decreasing time (s)') | ||
ax1.grid(True) | ||
|
||
ax2.plot(t, s) | ||
ax2.xaxis.set_inverted(True) # decreasing time | ||
ax2.set_title('Inverted axis with autoscaling') | ||
ax2.set_xlabel('decreasing time (s)') | ||
ax2.grid(True) | ||
|
||
ax.plot(t, s) | ||
ax.set_xlim(5, 0) # decreasing time | ||
ax.set_xlabel('decreasing time (s)') | ||
ax.set_ylabel('voltage (mV)') | ||
ax.set_title('Should be growing...') | ||
ax.grid(True) | ||
|
||
plt.show() |