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

Commitc55cfb0

Browse files
committed
DOC: fix aspect
1 parent5b0fcfa commitc55cfb0

File tree

1 file changed

+22
-14
lines changed

1 file changed

+22
-14
lines changed

‎galleries/examples/images_contours_and_fields/image_exact_placement.py

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -64,21 +64,28 @@ def annotate_rect(ax):
6464
# one you use depends on the shape of the image and the size of the figure.
6565
# We can control the relative sizes using the *width_ratios* argument *if* the images
6666
# are wider than they are tall and shown side by side, as is the case here.
67+
#
68+
# While we are making changes, let us also make the aspect ratio of the figure closer
69+
# to the aspect ratio of the axes using *figsize* so that the figure does not have so
70+
# much white space.
71+
72+
figsize= (6.4,2)# approximate figsize that trims some of the white space.
6773

68-
fig,axs=plt.subplots(1,2,width_ratios=[300/200,1],facecolor='aliceblue')
74+
fig,axs=plt.subplots(1,2,width_ratios=[300/200,1],
75+
figsize=figsize,facecolor='aliceblue')
6976

7077
axs[0].imshow(A,vmin=-1,vmax=1)
7178
annotate_rect(axs[0])
7279

7380
axs[1].imshow(B,vmin=-1,vmax=1)
74-
7581
# %%
7682
# Given that the data subsample is in the upper left of the larger image,
7783
# it might make sense if the top of the smaller Axes aligned with the top of the larger.
7884
# This can be done manually by using `~.Axes.set_anchor`, and using "NW" (for
7985
# northwest).
8086

81-
fig,axs=plt.subplots(1,2,width_ratios=[300/200,1],facecolor='aliceblue')
87+
fig,axs=plt.subplots(1,2,width_ratios=[300/200,1],
88+
figsize=figsize,facecolor='aliceblue')
8289

8390
axs[0].imshow(A,vmin=-1,vmax=1)
8491
annotate_rect(axs[0])
@@ -88,21 +95,22 @@ def annotate_rect(ax):
8895
axs[1].set_anchor('NW')
8996

9097
# %%
91-
# Note that this procedure still leaves large white spaces (that can be trimmed
92-
# in a final product by ``bbox_inches="tight"`` in `~.Figure.savefig`), and is
93-
# not very general. For instance, if the axes had been arranged vertically
94-
# instead of horizontally, setting the height aspect ratio would not have
95-
# helped because the axes are wider than they are tall. For more complicated
96-
# situations it is necessary to place the axes manually.
98+
# For more complicated situations it may be necessary to place the axes
99+
# manually. In the example above, even approximating figure aspect ratio, there
100+
# are still blank spaces (that can be trimmed in a final product by
101+
# ``bbox_inches="tight"`` in `~.Figure.savefig`). The procedure is also not
102+
# very general. For instance, if the axes had been arranged vertically instead
103+
# of horizontally, setting the height aspect ratio would not have helped
104+
# because the axes are wider than they are tall.
97105
#
98106
# Manual placement
99107
# ================
100108
#
101109
# We can manually place axes when they are created by passing a position to
102-
# `~.Figure.add_axes`. This position takes the form ``[left bottom width height]`` and
103-
# is in units that are a fraction of the figure width and height. Here we decide how
104-
# large to make the axes based on the size of the images, and add a small buffer of
105-
# 0.35 inches. We do all this at 100 dpi.
110+
# `~.Figure.add_axes`. This position takes the form ``[left bottom width
111+
#height]`` andis in units that are a fraction of the figure width and height.
112+
#Here we decide howlarge to make the axes based on the size of the images,
113+
#and add a small buffer of0.35 inches. We do all this at 100 dpi.
106114

107115
dpi=100# 100 pixels is one inch
108116

@@ -140,7 +148,7 @@ def annotate_rect(ax):
140148
ax=fig.add_axes([posB[0]/fig_width,posB[1]/fig_height,
141149
posB[2]/fig_width,posB[3]/fig_height])
142150
ax.imshow(B,vmin=-1,vmax=1)
143-
151+
plt.show()
144152
# %%
145153
# Inspection of the image will show that it is exactly 3* 35 + 300 + 200 = 605
146154
# pixels wide, and 2 * 35 + 100 = 170 pixels high (or twice that if the 2x

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp