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

Commit884060a

Browse files
authored
Merge pull request#10127 from anntzer/subplots-examples
Use subplots() instead of axes_grid in suitable examples.
2 parents64874e5 +ac964b5 commit884060a

File tree

3 files changed

+56
-151
lines changed

3 files changed

+56
-151
lines changed

‎examples/userdemo/annotate_explain.py

Lines changed: 12 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,13 @@
77

88
importmatplotlib.pyplotasplt
99
importmatplotlib.patchesasmpatches
10-
frommpl_toolkits.axes_grid1.axes_gridimportAxesGrid
11-
frommatplotlib.offsetboximportAnchoredText
1210

11+
12+
fig,axs=plt.subplots(2,2)
1313
x1,y1=0.3,0.3
1414
x2,y2=0.7,0.7
1515

16-
fig=plt.figure(1,figsize=(8,3))
17-
fig.clf()
18-
19-
20-
defadd_at(ax,t,loc=2):
21-
fp=dict(size=10)
22-
_at=AnchoredText(t,loc=loc,prop=fp)
23-
ax.add_artist(_at)
24-
return_at
25-
26-
27-
grid=AxesGrid(fig,111, (1,4),label_mode="1",share_all=True)
28-
29-
grid[0].set_autoscale_on(False)
30-
31-
ax=grid[0]
16+
ax=axs.flat[0]
3217
ax.plot([x1,x2], [y1,y2],".")
3318
el=mpatches.Ellipse((x1,y1),0.3,0.4,angle=30,alpha=0.2)
3419
ax.add_artist(el)
@@ -42,10 +27,9 @@ def add_at(ax, t, loc=2):
4227
connectionstyle="arc3,rad=0.3",
4328
),
4429
)
30+
ax.text(.05,.95,"connect",transform=ax.transAxes,ha="left",va="top")
4531

46-
add_at(ax,"connect",loc=2)
47-
48-
ax=grid[1]
32+
ax=axs.flat[1]
4933
ax.plot([x1,x2], [y1,y2],".")
5034
el=mpatches.Ellipse((x1,y1),0.3,0.4,angle=30,alpha=0.2)
5135
ax.add_artist(el)
@@ -59,11 +43,9 @@ def add_at(ax, t, loc=2):
5943
connectionstyle="arc3,rad=0.3",
6044
),
6145
)
46+
ax.text(.05,.95,"clip",transform=ax.transAxes,ha="left",va="top")
6247

63-
add_at(ax,"clip",loc=2)
64-
65-
66-
ax=grid[2]
48+
ax=axs.flat[2]
6749
ax.plot([x1,x2], [y1,y2],".")
6850
el=mpatches.Ellipse((x1,y1),0.3,0.4,angle=30,alpha=0.2)
6951
ax.add_artist(el)
@@ -77,11 +59,9 @@ def add_at(ax, t, loc=2):
7759
connectionstyle="arc3,rad=0.3",
7860
),
7961
)
62+
ax.text(.05,.95,"shrink",transform=ax.transAxes,ha="left",va="top")
8063

81-
add_at(ax,"shrink",loc=2)
82-
83-
84-
ax=grid[3]
64+
ax=axs.flat[3]
8565
ax.plot([x1,x2], [y1,y2],".")
8666
el=mpatches.Ellipse((x1,y1),0.3,0.4,angle=30,alpha=0.2)
8767
ax.add_artist(el)
@@ -95,13 +75,9 @@ def add_at(ax, t, loc=2):
9575
connectionstyle="arc3,rad=0.3",
9676
),
9777
)
78+
ax.text(.05,.95,"mutate",transform=ax.transAxes,ha="left",va="top")
9879

99-
add_at(ax,"mutate",loc=2)
100-
101-
grid[0].set_xlim(0,1)
102-
grid[0].set_ylim(0,1)
103-
grid[0].axis["bottom"].toggle(ticklabels=False)
104-
grid[0].axis["left"].toggle(ticklabels=False)
105-
fig.subplots_adjust(left=0.05,right=0.95,bottom=0.05,top=0.95)
80+
foraxinaxs.flat:
81+
ax.set(xlim=(0,1),ylim=(0,1),xticks=[],yticks=[],aspect=1)
10682

10783
plt.show()

‎examples/userdemo/connectionstyle_demo.py

Lines changed: 23 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -7,33 +7,14 @@
77

88
importmatplotlib.pyplotasplt
99
importmatplotlib.patchesasmpatches
10-
frommpl_toolkits.axes_grid1.axes_gridimportAxesGrid
11-
frommatplotlib.offsetboximportAnchoredText
1210

1311

14-
fig=plt.figure(1,figsize=(8,5))
15-
fig.clf()
16-
17-
18-
defadd_at(ax,t,loc=2):
19-
fp=dict(size=8)
20-
_at=AnchoredText(t,loc=loc,prop=fp)
21-
ax.add_artist(_at)
22-
return_at
23-
24-
25-
grid=AxesGrid(fig,111, (3,5),label_mode="1",share_all=True)
26-
27-
grid[0].set_autoscale_on(False)
28-
12+
fig,axs=plt.subplots(3,5,figsize=(8,4.8))
2913
x1,y1=0.3,0.3
3014
x2,y2=0.7,0.7
3115

3216

3317
defdemo_con_style(ax,connectionstyle,label=None):
34-
iflabelisNone:
35-
label=connectionstyle
36-
3718
x1,y1=0.3,0.2
3819
x2,y2=0.8,0.6
3920

@@ -50,53 +31,27 @@ def demo_con_style(ax, connectionstyle, label=None):
5031
),
5132
)
5233

53-
add_at(ax,label,loc=2)
54-
55-
56-
column=grid.axes_column[0]
57-
58-
demo_con_style(column[0],"angle3,angleA=90,angleB=0",
59-
label="angle3,\nangleA=90,\nangleB=0")
60-
demo_con_style(column[1],"angle3,angleA=0,angleB=90",
61-
label="angle3,\nangleA=0,\nangleB=90")
62-
63-
column=grid.axes_column[1]
64-
65-
demo_con_style(column[0],"arc3,rad=0.")
66-
demo_con_style(column[1],"arc3,rad=0.3")
67-
demo_con_style(column[2],"arc3,rad=-0.3")
68-
69-
column=grid.axes_column[2]
70-
71-
demo_con_style(column[0],"angle,angleA=-90,angleB=180,rad=0",
72-
label="angle,\nangleA=-90,\nangleB=180,\nrad=0")
73-
demo_con_style(column[1],"angle,angleA=-90,angleB=180,rad=5",
74-
label="angle,\nangleA=-90,\nangleB=180,\nrad=5")
75-
demo_con_style(column[2],"angle,angleA=-90,angleB=10,rad=5",
76-
label="angle,\nangleA=-90,\nangleB=10,\nrad=0")
77-
78-
column=grid.axes_column[3]
79-
80-
demo_con_style(column[0],"arc,angleA=-90,angleB=0,armA=30,armB=30,rad=0",
81-
label="arc,\nangleA=-90,\nangleB=0,\narmA=30,\narmB=30,\nrad=0")
82-
demo_con_style(column[1],"arc,angleA=-90,angleB=0,armA=30,armB=30,rad=5",
83-
label="arc,\nangleA=-90,\nangleB=0,\narmA=30,\narmB=30,\nrad=5")
84-
demo_con_style(column[2],"arc,angleA=-90,angleB=0,armA=0,armB=40,rad=0",
85-
label="arc,\nangleA=-90,\nangleB=0,\narmA=0,\narmB=40,\nrad=0")
86-
87-
column=grid.axes_column[4]
88-
89-
demo_con_style(column[0],"bar,fraction=0.3",
90-
label="bar,\nfraction=0.3")
91-
demo_con_style(column[1],"bar,fraction=-0.3",
92-
label="bar,\nfraction=-0.3")
93-
demo_con_style(column[2],"bar,angle=180,fraction=-0.2",
94-
label="bar,\nangle=180,\nfraction=-0.2")
95-
96-
grid[0].set_xlim(0,1)
97-
grid[0].set_ylim(0,1)
98-
grid.axes_llc.axis["bottom"].toggle(ticklabels=False)
99-
grid.axes_llc.axis["left"].toggle(ticklabels=False)
100-
fig.subplots_adjust(left=0.05,right=0.95,bottom=0.05,top=0.95)
34+
ax.text(.05,.95,connectionstyle.replace(",",",\n"),
35+
transform=ax.transAxes,ha="left",va="top")
36+
37+
38+
demo_con_style(axs[0,0],"angle3,angleA=90,angleB=0")
39+
demo_con_style(axs[1,0],"angle3,angleA=0,angleB=90")
40+
demo_con_style(axs[0,1],"arc3,rad=0.")
41+
demo_con_style(axs[1,1],"arc3,rad=0.3")
42+
demo_con_style(axs[2,1],"arc3,rad=-0.3")
43+
demo_con_style(axs[0,2],"angle,angleA=-90,angleB=180,rad=0")
44+
demo_con_style(axs[1,2],"angle,angleA=-90,angleB=180,rad=5")
45+
demo_con_style(axs[2,2],"angle,angleA=-90,angleB=10,rad=5")
46+
demo_con_style(axs[0,3],"arc,angleA=-90,angleB=0,armA=30,armB=30,rad=0")
47+
demo_con_style(axs[1,3],"arc,angleA=-90,angleB=0,armA=30,armB=30,rad=5")
48+
demo_con_style(axs[2,3],"arc,angleA=-90,angleB=0,armA=0,armB=40,rad=0")
49+
demo_con_style(axs[0,4],"bar,fraction=0.3")
50+
demo_con_style(axs[1,4],"bar,fraction=-0.3")
51+
demo_con_style(axs[2,4],"bar,angle=180,fraction=-0.2")
52+
53+
foraxinaxs.flat:
54+
ax.set(xlim=(0,1),ylim=(0,1),xticks=[],yticks=[],aspect=1)
55+
fig.tight_layout(pad=0)
10156

10257
plt.show()

‎examples/userdemo/simple_annotate01.py

Lines changed: 21 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -8,61 +8,38 @@
88
importmatplotlib.pyplotasplt
99
importmatplotlib.patchesasmpatches
1010

11+
12+
fig,axs=plt.subplots(2,4)
1113
x1,y1=0.3,0.3
1214
x2,y2=0.7,0.7
1315

14-
fig=plt.figure(1)
15-
fig.clf()
16-
frommpl_toolkits.axes_grid1.axes_gridimportGrid
17-
frommatplotlib.offsetboximportAnchoredText
18-
19-
frommatplotlib.font_managerimportFontProperties
20-
21-
22-
defadd_at(ax,t,loc=2):
23-
fp=dict(size=10)
24-
_at=AnchoredText(t,loc=loc,prop=fp)
25-
ax.add_artist(_at)
26-
return_at
27-
28-
29-
grid=Grid(fig,111, (4,4),label_mode="1",share_all=True)
30-
31-
grid[0].set_autoscale_on(False)
32-
33-
ax=grid[0]
16+
ax=axs.flat[0]
3417
ax.plot([x1,x2], [y1,y2],"o")
3518
ax.annotate("",
3619
xy=(x1,y1),xycoords='data',
3720
xytext=(x2,y2),textcoords='data',
3821
arrowprops=dict(arrowstyle="->"))
22+
ax.text(.05,.95,"A $->$ B",transform=ax.transAxes,ha="left",va="top")
3923

40-
add_at(ax,"A $->$ B",loc=2)
41-
42-
43-
ax=grid[1]
24+
ax=axs.flat[2]
4425
ax.plot([x1,x2], [y1,y2],"o")
4526
ax.annotate("",
4627
xy=(x1,y1),xycoords='data',
4728
xytext=(x2,y2),textcoords='data',
48-
arrowprops=dict(arrowstyle="->",connectionstyle="arc3,rad=0.3"))
49-
50-
add_at(ax,"connectionstyle=arc3",loc=2)
51-
29+
arrowprops=dict(arrowstyle="->",connectionstyle="arc3,rad=0.3",
30+
shrinkB=5)
31+
)
32+
ax.text(.05,.95,"shrinkB=5",transform=ax.transAxes,ha="left",va="top")
5233

53-
ax=grid[2]
34+
ax=axs.flat[3]
5435
ax.plot([x1,x2], [y1,y2],"o")
5536
ax.annotate("",
5637
xy=(x1,y1),xycoords='data',
5738
xytext=(x2,y2),textcoords='data',
58-
arrowprops=dict(arrowstyle="->",connectionstyle="arc3,rad=0.3",
59-
shrinkB=5)
60-
)
61-
62-
add_at(ax,"shrinkB=5",loc=2)
63-
39+
arrowprops=dict(arrowstyle="->",connectionstyle="arc3,rad=0.3"))
40+
ax.text(.05,.95,"connectionstyle=arc3",transform=ax.transAxes,ha="left",va="top")
6441

65-
ax=grid[3]
42+
ax=axs.flat[4]
6643
ax.plot([x1,x2], [y1,y2],"o")
6744
el=mpatches.Ellipse((x1,y1),0.3,0.4,angle=30,alpha=0.5)
6845
ax.add_artist(el)
@@ -72,8 +49,7 @@ def add_at(ax, t, loc=2):
7249
arrowprops=dict(arrowstyle="->",connectionstyle="arc3,rad=0.2")
7350
)
7451

75-
76-
ax=grid[4]
52+
ax=axs.flat[5]
7753
ax.plot([x1,x2], [y1,y2],"o")
7854
el=mpatches.Ellipse((x1,y1),0.3,0.4,angle=30,alpha=0.5)
7955
ax.add_artist(el)
@@ -83,11 +59,9 @@ def add_at(ax, t, loc=2):
8359
arrowprops=dict(arrowstyle="->",connectionstyle="arc3,rad=0.2",
8460
patchB=el)
8561
)
62+
ax.text(.05,.95,"patchB",transform=ax.transAxes,ha="left",va="top")
8663

87-
add_at(ax,"patchB",loc=2)
88-
89-
90-
ax=grid[5]
64+
ax=axs.flat[6]
9165
ax.plot([x1], [y1],"o")
9266
ax.annotate("Test",
9367
xy=(x1,y1),xycoords='data',
@@ -96,11 +70,9 @@ def add_at(ax, t, loc=2):
9670
bbox=dict(boxstyle="round",fc="w"),
9771
arrowprops=dict(arrowstyle="->")
9872
)
73+
ax.text(.05,.95,"annotate",transform=ax.transAxes,ha="left",va="top")
9974

100-
add_at(ax,"annotate",loc=2)
101-
102-
103-
ax=grid[6]
75+
ax=axs.flat[7]
10476
ax.plot([x1], [y1],"o")
10577
ax.annotate("Test",
10678
xy=(x1,y1),xycoords='data',
@@ -109,7 +81,9 @@ def add_at(ax, t, loc=2):
10981
bbox=dict(boxstyle="round",fc="w", ),
11082
arrowprops=dict(arrowstyle="->",relpos=(0.,0.))
11183
)
84+
ax.text(.05,.95,"relpos=(0,0)",transform=ax.transAxes,ha="left",va="top")
11285

113-
add_at(ax,"relpos=(0,0)",loc=2)
86+
foraxinaxs.flat:
87+
ax.set(xlim=(0,1),ylim=(0,1),xticks=[],yticks=[],aspect=1)
11488

11589
plt.show()

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp