@@ -64,21 +64,28 @@ def annotate_rect(ax):
64
64
# one you use depends on the shape of the image and the size of the figure.
65
65
# We can control the relative sizes using the *width_ratios* argument *if* the images
66
66
# 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.
67
73
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' )
69
76
70
77
axs [0 ].imshow (A ,vmin = - 1 ,vmax = 1 )
71
78
annotate_rect (axs [0 ])
72
79
73
80
axs [1 ].imshow (B ,vmin = - 1 ,vmax = 1 )
74
-
75
81
# %%
76
82
# Given that the data subsample is in the upper left of the larger image,
77
83
# it might make sense if the top of the smaller Axes aligned with the top of the larger.
78
84
# This can be done manually by using `~.Axes.set_anchor`, and using "NW" (for
79
85
# northwest).
80
86
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' )
82
89
83
90
axs [0 ].imshow (A ,vmin = - 1 ,vmax = 1 )
84
91
annotate_rect (axs [0 ])
@@ -88,21 +95,22 @@ def annotate_rect(ax):
88
95
axs [1 ].set_anchor ('NW' )
89
96
90
97
# %%
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.
97
105
#
98
106
# Manual placement
99
107
# ================
100
108
#
101
109
# 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]`` and is in units that are a fraction of the figure width and height.
112
+ #Here we decide how large to make the axes based on the size of the images,
113
+ #and add a small buffer of 0.35 inches. We do all this at 100 dpi.
106
114
107
115
dpi = 100 # 100 pixels is one inch
108
116
@@ -140,7 +148,7 @@ def annotate_rect(ax):
140
148
ax = fig .add_axes ([posB [0 ]/ fig_width ,posB [1 ]/ fig_height ,
141
149
posB [2 ]/ fig_width ,posB [3 ]/ fig_height ])
142
150
ax .imshow (B ,vmin = - 1 ,vmax = 1 )
143
-
151
+ plt . show ()
144
152
# %%
145
153
# Inspection of the image will show that it is exactly 3* 35 + 300 + 200 = 605
146
154
# pixels wide, and 2 * 35 + 100 = 170 pixels high (or twice that if the 2x