Skip to content

Commit

Permalink
DOC: Improve inverted axis example
Browse files Browse the repository at this point in the history
  • Loading branch information
timhoffm committed Apr 10, 2024
1 parent d45dfbb commit 0c7f227
Showing 1 changed file with 21 additions and 13 deletions.
34 changes: 21 additions & 13 deletions galleries/examples/subplots_axes_and_figures/invert_axes.py
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()

0 comments on commit 0c7f227

Please sign in to comment.