Revision: 5076
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=5076&view=rev
Author: jdh2358
Date: 2008-04-26 14:46:52 -0700 (Sat, 26 Apr 2008)
Log Message:
-----------
fixed dpi figure title positioning problem
Modified Paths:
--------------
trunk/matplotlib/CODING_GUIDE
trunk/matplotlib/Makefile
trunk/matplotlib/examples/barchart_demo.py
trunk/matplotlib/lib/matplotlib/axes.py
trunk/matplotlib/lib/matplotlib/figure.py
trunk/matplotlib/lib/matplotlib/pyplot.py
trunk/matplotlib/lib/matplotlib/text.py
Modified: trunk/matplotlib/CODING_GUIDE
===================================================================
--- trunk/matplotlib/CODING_GUIDE 2008-04-25 16:45:30 UTC (rev 5075)
+++ trunk/matplotlib/CODING_GUIDE 2008-04-26 21:46:52 UTC (rev 5076)
@@ -45,8 +45,8 @@
For numpy, use:
- import numpy as npy
- a = npy.array([1,2,3])
+ import numpy as np
+ a = np.array([1,2,3])
For masked arrays, use:
Modified: trunk/matplotlib/Makefile
===================================================================
--- trunk/matplotlib/Makefile 2008-04-25 16:45:30 UTC (rev 5075)
+++ trunk/matplotlib/Makefile 2008-04-26 21:46:52 UTC (rev 5076)
@@ -10,7 +10,7 @@
RELEASE = matplotlib-${VERSION}
-clean:
+clean:
${PYTHON} setup.py clean;\
rm -f *.png *.ps *.eps *.svg *.jpg *.pdf
find . -name "_tmp*.py" | xargs rm -f;\
@@ -25,11 +25,12 @@
${PYTHON} license.py ${VERSION} license/LICENSE;\
${PYTHON} setup.py sdist --formats=gztar,zip;
-pyback:
- tar cvfz pyback.tar.gz *.py lib src examples/*.py unit/*.py
+pyback:
+ tar cvfz pyback.tar.gz *.py lib src examples/*.py unit/*.py
+build_osx105:
+ CFLAGS="-Os -arch i386 -arch ppc" LDFLAGS="-Os -arch i386 -arch ppc"
python setup.py build
-
Modified: trunk/matplotlib/examples/barchart_demo.py
===================================================================
--- trunk/matplotlib/examples/barchart_demo.py 2008-04-25 16:45:30 UTC (rev
5075)
+++ trunk/matplotlib/examples/barchart_demo.py 2008-04-26 21:46:52 UTC (rev
5076)
@@ -1,24 +1,39 @@
+
#!/usr/bin/env python
# a bar plot with errorbars
-from pylab import *
+import numpy as np
+import matplotlib.pyplot as plt
N = 5
menMeans = (20, 35, 30, 35, 27)
menStd = (2, 3, 4, 1, 2)
-ind = arange(N) # the x locations for the groups
+ind = np.arange(N) # the x locations for the groups
width = 0.35 # the width of the bars
-p1 = bar(ind, menMeans, width, color='r', yerr=menStd)
+fig = plt.figure()
+ax = fig.add_subplot(111)
+rects1 = ax.bar(ind, menMeans, width, color='r', yerr=menStd)
+
womenMeans = (25, 32, 34, 20, 25)
womenStd = (3, 5, 2, 3, 3)
-p2 = bar(ind+width, womenMeans, width, color='y', yerr=womenStd)
+rects2 = ax.bar(ind+width, womenMeans, width, color='y', yerr=womenStd)
-ylabel('Scores')
-title('Scores by group and gender')
-xticks(ind+width, ('G1', 'G2', 'G3', 'G4', 'G5') )
+# add some
+ax.set_ylabel('Scores')
+ax.set_title('Scores by group and gender')
+ax.set_xticks(ind+width, ('G1', 'G2', 'G3', 'G4', 'G5') )
-legend( (p1[0], p2[0]), ('Men', 'Women') )
+ax.legend( (rects1[0], rects2[0]), ('Men', 'Women') )
-#savefig('barchart_demo')
-show()
+def autolabel(rects):
+ # attach some text labels
+ for rect in rects:
+ height = rect.get_height()
+ ax.text(rect.get_x()+rect.get_width()/2., 1.05*height,
'%d'%int(height),
+ ha='center', va='bottom')
+
+autolabel(rects1)
+autolabel(rects2)
+#fig.savefig('barchart_demo')
+plt.show()
Modified: trunk/matplotlib/lib/matplotlib/axes.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/axes.py 2008-04-25 16:45:30 UTC (rev
5075)
+++ trunk/matplotlib/lib/matplotlib/axes.py 2008-04-26 21:46:52 UTC (rev
5076)
@@ -780,7 +780,10 @@
self.grid(self._gridOn)
props = font_manager.FontProperties(size=rcParams['axes.titlesize'])
- self.titleOffsetTrans = mtransforms.Affine2D().translate(0.0, 10.0)
+
+
+ self.titleOffsetTrans = mtransforms.Affine2D().translate(
+ 0.0, 5.0*self.figure.dpi/72.)
self.title = mtext.Text(
x=0.5, y=1.0, text='',
fontproperties=props,
@@ -811,8 +814,17 @@
self.xaxis.set_clip_path(self.axesPatch)
self.yaxis.set_clip_path(self.axesPatch)
- self.titleOffsetTrans.clear().translate(0.0, 10.0)
+ self.titleOffsetTrans.clear().translate(
+ 0.0, 5.0*self.figure.dpi/72.)
+ def on_dpi_change(fig):
+ self.titleOffsetTrans.clear().translate(
+ 0.0, 5.0*fig.dpi/72.)
+
+ self.figure.callbacks.connect('dpi_changed', on_dpi_change)
+
+
+
def clear(self):
'clear the axes'
self.cla()
@@ -839,8 +851,10 @@
figure will be cleared on the next plot command
"""
- if b is None: self._hold = not self._hold
- else: self._hold = b
+ if b is None:
+ self._hold = not self._hold
+ else:
+ self._hold = b
def get_aspect(self):
return self._aspect
Modified: trunk/matplotlib/lib/matplotlib/figure.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/figure.py 2008-04-25 16:45:30 UTC (rev
5075)
+++ trunk/matplotlib/lib/matplotlib/figure.py 2008-04-26 21:46:52 UTC (rev
5076)
@@ -1,7 +1,7 @@
"""
Figure class -- add docstring here!
"""
-import numpy as npy
+import numpy as np
import time
import artist
@@ -20,6 +20,8 @@
from projections import projection_factory, get_projection_names, \
get_projection_class
+import matplotlib.cbook as cbook
+
class SubplotParams:
"""
A class to hold the parameters for a subplot
@@ -176,6 +178,13 @@
class Figure(Artist):
+ """
+ The Figure instance supports callbacks through a callbacks
+ attribute which is a cbook.CallbackRegistry instance. The events
+ you can connect to are 'dpi_changed', and the callback will be
+ called with func(fig) where fig is the Figure instance
+ """
+
def __str__(self):
return "Figure(%gx%g)" % tuple(self.bbox.size)
@@ -195,6 +204,8 @@
"""
Artist.__init__(self)
+ self.callbacks = cbook.CallbackRegistry(('dpi_changed', ))
+
if figsize is None : figsize = rcParams['figure.figsize']
if dpi is None : dpi = rcParams['figure.dpi']
if facecolor is None: facecolor = rcParams['figure.facecolor']
@@ -236,6 +247,7 @@
def _set_dpi(self, dpi):
self._dpi = dpi
self.dpi_scale_trans.clear().scale(dpi, dpi)
+ self.callbacks.process('dpi_changed', self)
dpi = property(_get_dpi, _set_dpi)
def enable_auto_layout(self, setting=True):
@@ -255,7 +267,7 @@
rotation: the rotation of the xtick labels
ha : the horizontal alignment of the xticklabels
"""
- allsubplots = npy.alltrue([hasattr(ax, 'is_last_row') for ax in
self.axes])
+ allsubplots = np.alltrue([hasattr(ax, 'is_last_row') for ax in
self.axes])
if len(self.axes)==1:
for label in ax.get_xticklabels():
label.set_ha(ha)
@@ -662,6 +674,9 @@
"""
Clear the figure
"""
+
+ self.callbacks = cbook.CallbackRegistry(('dpi_changed', ))
+
for ax in tuple(self.axes): # Iterate over the copy.
ax.cla()
self.delaxes(ax) # removes ax from self.axes
@@ -1022,8 +1037,8 @@
# min/max sizes to respect when autoscaling. If John likes the idea, they
# could become rc parameters, for now they're hardwired.
- figsize_min = npy.array((4.0,2.0)) # min length for width/height
- figsize_max = npy.array((16.0,16.0)) # max length for width/height
+ figsize_min = np.array((4.0,2.0)) # min length for width/height
+ figsize_max = np.array((16.0,16.0)) # max length for width/height
#figsize_min = rcParams['figure.figsize_min']
#figsize_max = rcParams['figure.figsize_max']
@@ -1038,7 +1053,7 @@
fig_height = rcParams['figure.figsize'][1]
# New size for the figure, keeping the aspect ratio of the caller
- newsize = npy.array((fig_height/arr_ratio,fig_height))
+ newsize = np.array((fig_height/arr_ratio,fig_height))
# Sanity checks, don't drop either dimension below figsize_min
newsize /= min(1.0,*(newsize/figsize_min))
@@ -1048,7 +1063,7 @@
# 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 = npy.clip(newsize,figsize_min,figsize_max)
+ newsize = np.clip(newsize,figsize_min,figsize_max)
return newsize
artist.kwdocd['Figure'] = artist.kwdoc(Figure)
Modified: trunk/matplotlib/lib/matplotlib/pyplot.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/pyplot.py 2008-04-25 16:45:30 UTC (rev
5075)
+++ trunk/matplotlib/lib/matplotlib/pyplot.py 2008-04-26 21:46:52 UTC (rev
5076)
@@ -274,9 +274,9 @@
def ginput(*args, **kwargs):
"""
- Blocking call to interact with the figure.
+ Blocking call to interact with the figure.
- This will wait for n clicks from the user and return a list of the
+ This will wait for n clicks from the user and return a list of the
coordinates of each click.
If timeout is negative, does not timeout.
@@ -345,8 +345,17 @@
will be cleared on the next plot command
"""
- gcf().hold(b)
- gca().hold(b)
+ fig = gcf()
+ ax = fig.gca()
+
+ fig.hold(b)
+ ax.hold(b)
+
+ # b=None toggles the hold state, so let's get get the current hold
+ # state; but should pyplot hold toggle the rc setting - me thinks
+ # not
+ b = ax.ishold()
+
rc('axes', hold=b)
def ishold():
Modified: trunk/matplotlib/lib/matplotlib/text.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/text.py 2008-04-25 16:45:30 UTC (rev
5075)
+++ trunk/matplotlib/lib/matplotlib/text.py 2008-04-26 21:46:52 UTC (rev
5076)
@@ -4,7 +4,7 @@
from __future__ import division
import math
-import numpy as npy
+import numpy as np
from matplotlib import cbook
from matplotlib import rcParams
@@ -180,8 +180,8 @@
width, height = 0.0, 0.0
lines = self._text.split('\n')
- whs = npy.zeros((len(lines), 2))
- horizLayout = npy.zeros((len(lines), 4))
+ whs = np.zeros((len(lines), 2))
+ horizLayout = np.zeros((len(lines), 4))
# Find full vertical extent of font,
# including ascenders and descenders:
@@ -208,7 +208,7 @@
# get the rotation matrix
M = Affine2D().rotate_deg(self.get_rotation())
- offsetLayout = npy.zeros((len(lines), 2))
+ offsetLayout = np.zeros((len(lines), 2))
offsetLayout[:] = horizLayout[:, 0:2]
# now offset the individual text lines within the box
if len(lines)>1: # do the multiline aligment
@@ -219,9 +219,9 @@
offsetLayout[:, 0] += width - horizLayout[:, 2]
# the corners of the unrotated bounding box
- cornersHoriz = npy.array(
+ cornersHoriz = np.array(
[(xmin, ymin), (xmin, ymax), (xmax, ymax), (xmax, ymin)],
- npy.float_)
+ np.float_)
# now rotate the bbox
cornersRotated = M.transform(cornersHoriz)
@@ -658,7 +658,7 @@
dashlength is the length of the dash in canvas units.
(default=0.0).
- dashdirection is one of 0 or 1, npy.where 0 draws the dash
+ dashdirection is one of 0 or 1, np.where 0 draws the dash
after the text and 1 before.
(default=0).
@@ -782,15 +782,15 @@
dashpush = self.get_dashpush()
angle = get_rotation(dashrotation)
- theta = npy.pi*(angle/180.0+dashdirection-1)
- cos_theta, sin_theta = npy.cos(theta), npy.sin(theta)
+ theta = np.pi*(angle/180.0+dashdirection-1)
+ cos_theta, sin_theta = np.cos(theta), np.sin(theta)
transform = self.get_transform()
# Compute the dash end points
# The 'c' prefix is for canvas coordinates
cxy = transform.transform_point((dashx, dashy))
- cd = npy.array([cos_theta, sin_theta])
+ cd = np.array([cos_theta, sin_theta])
c1 = cxy+dashpush*cd
c2 = cxy+(dashpush+dashlength)*cd
@@ -829,8 +829,8 @@
if dy > h or dy < -h:
dy = h
dx = h/tan_theta
- cwd = npy.array([dx, dy])/2
- cwd *= 1+dashpad/npy.sqrt(npy.dot(cwd,cwd))
+ cwd = np.array([dx, dy])/2
+ cwd *= 1+dashpad/np.sqrt(np.dot(cwd,cwd))
cw = c2+(dashdirection*2-1)*cwd
newx, newy = inverse.transform_point(tuple(cw))
@@ -840,7 +840,7 @@
# I'm not at all sure this is the right way to do this.
we = Text.get_window_extent(self, renderer=renderer)
self._twd_window_extent = we.frozen()
- self._twd_window_extent.update_from_data_xy(npy.array([c1]), False)
+ self._twd_window_extent.update_from_data_xy(np.array([c1]), False)
# Finally, make text align center
Text.set_horizontalalignment(self, 'center')
@@ -1094,8 +1094,8 @@
return x, y
elif s=='polar':
theta, r = x, y
- x = r*npy.cos(theta)
- y = r*npy.sin(theta)
+ x = r*np.cos(theta)
+ y = r*np.cosmsin(theta)
trans = self.axes.transData
return trans.transform_point((x,y))
elif s=='figure points':
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
Don't miss this year's exciting event. There's still time to save $100.
Use priority code J8TL2D2.
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
Matplotlib-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins