@@ -862,19 +862,63 @@ def figimage(self, X, xo=0, yo=0, alpha=None, norm=None, cmap=None,
862
862
self .stale = True
863
863
return im
864
864
865
+ def set_size (self ,w ,h = None ,forward = True ):
866
+ """
867
+ Set the figure size
868
+
869
+ Parameters
870
+ ----------
871
+
872
+ w: float, string, or two-tuple of either.
873
+
874
+ If a two-tuple, (width, height) of the figure.
875
+
876
+ If a float, width of figure in inches.
877
+
878
+ If a string, its a float followed by a 2-character suffix
879
+ of either 'in', 'cm', 'mm', 'pt' (inches, centimeters,
880
+ millimeters, or points). i.e. ``w='4.6cm'``.
881
+
882
+ h: float or string
883
+ As above, if a float it is the hieght of the figure in inches,
884
+ or a string decoded as above.
885
+
886
+ forward : bool, default True
887
+ Forward to the window so the canvas size is updated;
888
+ e.g., you can resize the figure window from the shell
889
+
890
+ See Also
891
+ --------
892
+ matplotlib.Figure.set_size_inches
893
+
894
+ """
895
+ if h is None :
896
+ w ,h = w
897
+ if isinstance (w ,str ):
898
+ w = cbook ._print_unit (w )
899
+ if isinstance (w ,str ):
900
+ raise ValueError ('Could not convert str {} to '
901
+ 'inches' .format (w ))
902
+ if isinstance (h ,str ):
903
+ h = cbook ._print_unit (h )
904
+ if isinstance (h ,str ):
905
+ raise ValueError ('Could not convert str {} to '
906
+ 'inches' .format (h ))
907
+ self .set_size_inches (w ,h ,forward = forward )
908
+
865
909
def set_size_inches (self ,w ,h = None ,forward = True ):
866
- """Set the figure size in inches .
910
+ """Set the figure size.
867
911
868
912
Call signatures::
869
913
870
914
fig.set_size_inches(w, h) # OR
871
915
fig.set_size_inches((w, h))
872
916
873
- optional kwarg *forward=True* will cause the canvas size to be
917
+ Optional kwarg *forward=True* will cause the canvas size to be
874
918
automatically updated; e.g., you can resize the figure window
875
919
from the shell
876
920
877
- ACCEPTS: a (w, h) tuple with w, h in inches
921
+ ACCEPTS: a (w, h) tuple with w, h in inches.
878
922
879
923
See Also
880
924
--------
@@ -883,8 +927,10 @@ def set_size_inches(self, w, h=None, forward=True):
883
927
884
928
# the width and height have been passed in as a tuple to the first
885
929
# argument, so unpack them
930
+
886
931
if h is None :
887
932
w ,h = w
933
+
888
934
if not all (np .isfinite (_ )for _ in (w ,h )):
889
935
raise ValueError ('figure size must be finite not '
890
936
'({}, {})' .format (w ,h ))