Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit3dee9d7

Browse files
authored
Merge pull request#28064 from meeseeksmachine/auto-backport-of-pr-28055-on-v3.8.x
2 parentsdaa1ca9 +9bb7bae commit3dee9d7

File tree

1 file changed

+24
-14
lines changed

1 file changed

+24
-14
lines changed
Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,35 @@
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+
This example demonstrates two ways to invert the direction of an axis:
7+
8+
- If you want to set *explicit axis limits* anyway, e.g. via `~.Axes.set_xlim`, you
9+
can 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
importmatplotlib.pyplotasplt
1115
importnumpyasnp
1216

13-
t=np.arange(0.01,5.0,0.01)
14-
s=np.exp(-t)
17+
x=np.arange(0.01,4.0,0.01)
18+
y=np.exp(-x)
19+
20+
fig, (ax1,ax2)=plt.subplots(1,2,figsize=(6.4,4),layout="constrained")
21+
fig.suptitle('Inverted axis with ...')
1522

16-
fig,ax=plt.subplots()
23+
ax1.plot(x,y)
24+
ax1.set_xlim(4,0)# inverted fixed limits
25+
ax1.set_title('fixed limits: set_xlim(4, 0)')
26+
ax1.set_xlabel('decreasing x ⟶')
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+
ax2.plot(x,y)
30+
ax2.xaxis.set_inverted(True)# inverted axis with autoscaling
31+
ax2.set_title('autoscaling: set_inverted(True)')
32+
ax2.set_xlabel('decreasing x ⟶')
33+
ax2.grid(True)
2434

2535
plt.show()

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp