Skip to content

Commit

Permalink
Handle changed dpi in quiver; remove extra draw in print_figure.
Browse files Browse the repository at this point in the history
There is still a dpi-related problem with mathtext in the QuiverKey label.

svn path=/trunk/matplotlib/; revision=5079
  • Loading branch information
efiring committed Apr 27, 2008
1 parent 18e268b commit b66aa38
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 17 deletions.
7 changes: 3 additions & 4 deletions lib/matplotlib/backend_bases.py
Expand Up @@ -1088,8 +1088,7 @@ def print_figure(self, filename, dpi=None, facecolor='w', edgecolor='w',
self.figure.set_facecolor(origfacecolor)
self.figure.set_edgecolor(origedgecolor)
self.figure.set_canvas(self)
self.figure.canvas.draw()

#self.figure.canvas.draw() ## seems superfluous
return result

def get_default_filetype(self):
Expand Down Expand Up @@ -1509,7 +1508,7 @@ def release_zoom(self, event):
if not self._xypress: return

last_a = []

for cur_xypress in self._xypress:
x, y = event.x, event.y
lastx, lasty, a, ind, lim, trans = cur_xypress
Expand All @@ -1528,7 +1527,7 @@ def release_zoom(self, event):
x, y = inverse.transform_point( (x, y) )
Xmin,Xmax=a.get_xlim()
Ymin,Ymax=a.get_ylim()

# detect twinx,y axes and avoid double zooming
twinx, twiny = False, False
if last_a:
Expand Down
3 changes: 1 addition & 2 deletions lib/matplotlib/backends/backend_agg.py
Expand Up @@ -59,8 +59,7 @@ def __init__(self, width, height, dpi):
self.width = width
self.height = height
if __debug__: verbose.report('RendererAgg.__init__ width=%s, height=%s'%(width, height), 'debug-annoying')
self._renderer = _RendererAgg(int(width), int(height), dpi,
debug=False)
self._renderer = _RendererAgg(int(width), int(height), dpi, debug=False)
if __debug__: verbose.report('RendererAgg.__init__ _RendererAgg done',
'debug-annoying')
self.draw_path = self._renderer.draw_path
Expand Down
9 changes: 4 additions & 5 deletions lib/matplotlib/mathtext.py
Expand Up @@ -1438,8 +1438,8 @@ def hpack(self, w=0., m='additional'):
w: specifies a width
m: is either 'exactly' or 'additional'.
Thus, hpack(w, exactly) produces a box whose width is exactly w, while
hpack (w, additional ) yields a box whose width is the natural width
Thus, hpack(w, 'exactly') produces a box whose width is exactly w, while
hpack (w, 'additional') yields a box whose width is the natural width
plus w. The default values produce a box with the natural width.
node644, node649"""
# I don't know why these get reset in TeX. Shift_amount is pretty
Expand Down Expand Up @@ -1502,8 +1502,8 @@ def vpack(self, h=0., m='additional', l=float(inf)):
m: is either 'exactly' or 'additional'.
l: a maximum height
Thus, vpack(h, exactly) produces a box whose width is exactly w, while
vpack(w, additional) yields a box whose width is the natural width
Thus, vpack(h, 'exactly') produces a box whose width is exactly w, while
vpack(w, 'additional') yields a box whose width is the natural width
plus w. The default values produce a box with the natural width.
node644, node668"""
# I don't know why these get reset in TeX. Shift_amount is pretty
Expand Down Expand Up @@ -2678,7 +2678,6 @@ def __init__(self, output):
def parse(self, s, dpi = 72, prop = None):
if prop is None:
prop = FontProperties()

cacheKey = (s, dpi, hash(prop))
result = self._cache.get(cacheKey)
if result is not None:
Expand Down
25 changes: 20 additions & 5 deletions lib/matplotlib/quiver.py
Expand Up @@ -168,20 +168,24 @@ def __init__(self, Q, X, Y, U, label, **kw):
self.coord = kw.pop('coordinates', 'axes')
self.color = kw.pop('color', None)
self.label = label
self.labelsep = (kw.pop('labelsep', 0.1) * Q.ax.figure.dpi)
self._labelsep_inches = kw.pop('labelsep', 0.1)
self.labelsep = (self._labelsep_inches * Q.ax.figure.dpi)

def on_dpi_change(fig):
self.labelsep = (kw.pop('labelsep', 0.1) * fig.dpi)
self.labelsep = (self._labelsep_inches * fig.dpi)
self._initialized = False # simple brute force update
# works because _init is called
# at the start of draw.

Q.ax.figure.callbacks.connect('dpi_changed', on_dpi_change)


self.labelpos = kw.pop('labelpos', 'N')
self.labelcolor = kw.pop('labelcolor', None)
self.fontproperties = kw.pop('fontproperties', dict())
self.kw = kw
_fp = self.fontproperties
self.text = text.Text(text=label,
#boxprops = dict(facecolor='red')
self.text = text.Text(text=label, # bbox=boxprops,
horizontalalignment=self.halign[self.labelpos],
verticalalignment=self.valign[self.labelpos],
fontproperties=font_manager.FontProperties(**_fp))
Expand Down Expand Up @@ -297,6 +301,16 @@ def __init__(self, ax, *args, **kw):
self.keyvec = None
self.keytext = None

def on_dpi_change(fig):
self._new_UV = True # vertices depend on width, span
# which in turn depend on dpi
self._initialized = False # simple brute force update
# works because _init is called
# at the start of draw.

self.ax.figure.callbacks.connect('dpi_changed', on_dpi_change)


__init__.__doc__ = """
The constructor takes one required argument, an Axes
instance, followed by the args and kwargs described
Expand Down Expand Up @@ -331,7 +345,8 @@ def _init(self):
if not self._initialized:
trans = self._set_transform()
ax = self.ax
sx, sy = trans.inverted().transform_point((ax.bbox.width, ax.bbox.height))
sx, sy = trans.inverted().transform_point(
(ax.bbox.width, ax.bbox.height))
self.span = sx
sn = max(8, min(25, math.sqrt(self.N)))
if self.width is None:
Expand Down
1 change: 0 additions & 1 deletion lib/matplotlib/text.py
Expand Up @@ -1174,7 +1174,6 @@ def update_positions(self, renderer):
if self.arrowprops:
x0, y0 = x, y
l,b,w,h = self.get_window_extent(renderer).bounds
dpi = self.figure.dpi
r = l+w
t = b+h
xc = 0.5*(l+r)
Expand Down

0 comments on commit b66aa38

Please sign in to comment.