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

Commitf7eb377

Browse files
committed
Use subplots() instead of axes_grid in suitable examples.
1 parent64874e5 commitf7eb377

File tree

2 files changed

+35
-103
lines changed

2 files changed

+35
-103
lines changed

‎examples/userdemo/annotate_explain.py

Lines changed: 12 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,14 @@
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)
3016

31-
ax=grid[0]
17+
ax=axs.flat[0]
3218
ax.plot([x1,x2], [y1,y2],".")
3319
el=mpatches.Ellipse((x1,y1),0.3,0.4,angle=30,alpha=0.2)
3420
ax.add_artist(el)
@@ -42,10 +28,9 @@ def add_at(ax, t, loc=2):
4228
connectionstyle="arc3,rad=0.3",
4329
),
4430
)
31+
ax.text(.05,.95,"connect",transform=ax.transAxes,ha="left",va="top")
4532

46-
add_at(ax,"connect",loc=2)
47-
48-
ax=grid[1]
33+
ax=axs.flat[1]
4934
ax.plot([x1,x2], [y1,y2],".")
5035
el=mpatches.Ellipse((x1,y1),0.3,0.4,angle=30,alpha=0.2)
5136
ax.add_artist(el)
@@ -59,11 +44,9 @@ def add_at(ax, t, loc=2):
5944
connectionstyle="arc3,rad=0.3",
6045
),
6146
)
47+
ax.text(.05,.95,"clip",transform=ax.transAxes,ha="left",va="top")
6248

63-
add_at(ax,"clip",loc=2)
64-
65-
66-
ax=grid[2]
49+
ax=axs.flat[2]
6750
ax.plot([x1,x2], [y1,y2],".")
6851
el=mpatches.Ellipse((x1,y1),0.3,0.4,angle=30,alpha=0.2)
6952
ax.add_artist(el)
@@ -77,11 +60,9 @@ def add_at(ax, t, loc=2):
7760
connectionstyle="arc3,rad=0.3",
7861
),
7962
)
63+
ax.text(.05,.95,"shrink",transform=ax.transAxes,ha="left",va="top")
8064

81-
add_at(ax,"shrink",loc=2)
82-
83-
84-
ax=grid[3]
65+
ax=axs.flat[3]
8566
ax.plot([x1,x2], [y1,y2],".")
8667
el=mpatches.Ellipse((x1,y1),0.3,0.4,angle=30,alpha=0.2)
8768
ax.add_artist(el)
@@ -95,13 +76,9 @@ def add_at(ax, t, loc=2):
9576
connectionstyle="arc3,rad=0.3",
9677
),
9778
)
79+
ax.text(.05,.95,"mutate",transform=ax.transAxes,ha="left",va="top")
9880

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)
81+
foraxinaxs.flat:
82+
ax.set(xlim=(0,1),ylim=(0,1),xticks=[],yticks=[],aspect=1)
10683

10784
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()

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp