SourceForge logo
SourceForge logo
Menu

matplotlib-devel

From: <seb...@fr...> - 2005年07月28日 15:15:48
 Hi,
First of all thank you for this great package.
1/
The matshow function computes the aspect ratio of the figure with:
 in matplotlib/pylab.py
 def matshow(*args,**kw):
 ...
 # Extract actual aspect ratio of array and make appropriately sized f=
igure
 w,h =3D figaspect(arr)
 ...
before displaying it.
figaspect takes the array as an argument and compute its aspect ratio wit=
h:
 in matplotlib/figure.py
 def figaspect(arr):
 ...
 # Extract the aspect ratio of the array
 nr,nc =3D arr.shape[:2]
 arr_ratio =3D float(nr)/nc
 ...
Could it be changed such that figaspect takes a float as its argument and=
 the 2
lines to compute arr_ratio are moved from figaspect to matshow before cal=
ling
figaspect ? (+ change the figaspect doc string)
It will make figaspect more general and allow us to create a figure with =
a given
aspect ratio without copying/pasting of nearly all the figaspect machiner=
y.
2/
Does anybody intend to add a Patch object to draw polygons with holes (I =
do not
know how to do it) ?
Thank you,
 Seb
From: John H. <jdh...@ac...> - 2005年08月01日 15:59:09
>>>>> "sebastian" == sebastian rooks <seb...@fr...> writes:
 sebastian> Could it be changed such that figaspect takes a float
 sebastian> as its argument and the 2 lines to compute arr_ratio
 sebastian> are moved from figaspect to matshow before calling
 sebastian> figaspect ? (+ change the figaspect doc string) It will
 sebastian> make figaspect more general and allow us to create a
 sebastian> figure with a given aspect ratio without
 sebastian> copying/pasting of nearly all the figaspect machinery.
Good idea -- I overloaded figaspect to do both (it works with either
an array or a number argument). Code is below and in CVS
 Checking in lib/matplotlib/figure.py;
 /cvsroot/matplotlib/matplotlib/lib/matplotlib/figure.py,v <-- figure.py
 new revision: 1.34; previous revision: 1.33
 sebastian> 2/ Does anybody intend to add a Patch object to draw
 sebastian> polygons with holes (I do not know how to do it) ?
Not presently, but this would be nice.
JDH
def figaspect(arg):
 """
 Create a figure with specified aspect ratio. If arg is a number,
 use that aspect ratio. If arg is an array, figaspect will
 determine the width and height for a figure that would fit array
 preserving aspcect ratio. The figure width, height in inches are
 returned. Be sure to create an axes with equal with and height,
 eg
 Example usage:
 # make a figure twice as tall as it is wide
 w, h = figaspect(2.)
 fig = Figure(figsize=(w,h))
 ax = fig.add_axes([0.1, 0.1, 0.8, 0.8])
 ax.imshow(A, **kwargs)
 # make a figure with the proper aspect for an array
 A = rand(5,3)
 w, h = figaspect(A)
 fig = Figure(figsize=(w,h))
 ax = fig.add_axes([0.1, 0.1, 0.8, 0.8])
 ax.imshow(A, **kwargs)
 Thanks to Fernando Perez for this function
 """
 isarray = hasattr(arg, 'shape')
 
 # min/max sizes to respect when autoscaling. If John likes the idea, they
 # could become rc parameters, for now they're hardwired.
 figsize_min = array((4.0,2.0)) # min length for width/height
 figsize_max = array((16.0,16.0)) # max length for width/height
 #figsize_min = rcParams['figure.figsize_min']
 #figsize_max = rcParams['figure.figsize_max']
 # Extract the aspect ratio of the array
 if isarray:
 nr,nc = arg.shape[:2]
 arr_ratio = float(nr)/nc
 else:
 arr_ratio = float(arg)
 # Height of user figure defaults
 fig_height = rcParams['figure.figsize'][1]
 # New size for the figure, keeping the aspect ratio of the caller
 newsize = array((fig_height/arr_ratio,fig_height))
 # Sanity checks, don't drop either dimension below figsize_min
 newsize /= min(1.0,*(newsize/figsize_min))
 # Avoid humongous windows as well
 newsize /= max(1.0,*(newsize/figsize_max))
 # Finally, if we have a really funky aspect ratio, break it but respect
 # the min/max dimensions (we don't want figures 10 feet tall!)
 newsize = clip(newsize,figsize_min,figsize_max)
 return newsize
From: <seb...@fr...> - 2005年08月01日 20:25:36
Thank you,
 Seb
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.
Thanks for helping keep SourceForge clean.
X





Briefly describe the problem (required):
Upload screenshot of ad (required):
Select a file, or drag & drop file here.
Screenshot instructions:

Click URL instructions:
Right-click on the ad, choose "Copy Link", then paste here →
(This may not be possible with some types of ads)

More information about our ad policies

Ad destination/click URL:

AltStyle によって変換されたページ (->オリジナル) /