Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit babe9fb

Browse files
committed
more log scaling fixes
svn path=/trunk/matplotlib/; revision=936
1 parent c2b3535 commit babe9fb

7 files changed

Lines changed: 225 additions & 66 deletions

File tree

lib/matplotlib/axes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2812,7 +2812,7 @@ def set_xscale(self, value, basex = 10, subsx=None):
28122812
self.xaxis.set_minor_locator(LogLocator(basex,subsx))
28132813
self.transData.get_funcx().set_type(LOG10)
28142814
minx, maxx = self.get_xlim()
2815-
if min(minx, maxx)<0:
2815+
if min(minx, maxx)<=0:
28162816
self.autoscale_view()
28172817
elif value == 'linear':
28182818
self.xaxis.set_major_locator(AutoLocator())
@@ -2894,7 +2894,7 @@ def set_yscale(self, value, basey=10, subsy=None):
28942894
self.yaxis.set_minor_locator(LogLocator(basey,subsy))
28952895
self.transData.get_funcy().set_type(LOG10)
28962896
miny, maxy = self.get_ylim()
2897-
if min(miny, maxy)<0:
2897+
if min(miny, maxy)<=0:
28982898
self.autoscale_view()
28992899

29002900
elif value == 'linear':

lib/matplotlib/backend_bases.py

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -569,9 +569,16 @@ def __init__(self, name, canvas, x, y):
569569
for a in self.canvas.figure.get_axes():
570570
if self.x is not None and self.y is not None and a.in_axes(self.x, self.y):
571571
self.inaxes = a
572-
xdata, ydata = a.transData.inverse_xy_tup((self.x, self.y))
573-
self.xdata = xdata
574-
self.ydata = ydata
572+
#self.x, self.y, a.transData.get_funcx().get_type(), a.transData.get_funcy().get_type()
573+
574+
try: xdata, ydata = a.transData.inverse_xy_tup((self.x, self.y))
575+
except ValueError:
576+
self.xdata = None
577+
self.ydata = None
578+
else:
579+
self.xdata = xdata
580+
self.ydata = ydata
581+
575582
break
576583

577584
class MouseEvent(LocationEvent):
@@ -604,22 +611,9 @@ def __init__(self, name, canvas, x, y, button=None, key=None):
604611
button pressed None, 1, 2, 3
605612
"""
606613
LocationEvent.__init__(self, name, canvas, x, y)
607-
self.x = x
608-
self.y = y
609614
self.button = button
610615
self.key = key
611616

612-
self.inaxes = None
613-
for a in self.canvas.figure.get_axes():
614-
if a.in_axes(self.x, self.y):
615-
self.inaxes = a
616-
xdata, ydata = a.transData.inverse_xy_tup((self.x, self.y))
617-
self.xdata = xdata
618-
self.ydata = ydata
619-
break
620-
621-
622-
623617
class KeyEvent(LocationEvent):
624618
"""
625619
A key event (key press, key release).

lib/matplotlib/backends/backend_agg.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ def __init__(self, width, height, dpi):
107107
self.draw_polygon = self._renderer.draw_polygon
108108
self.draw_rectangle = self._renderer.draw_rectangle
109109
self.draw_lines = self._renderer.draw_lines
110+
self.draw_markers = self._renderer.draw_markers
110111
self.draw_image = self._renderer.draw_image
111112
self.draw_line_collection = self._renderer.draw_line_collection
112113
self.draw_poly_collection = self._renderer.draw_poly_collection

lib/matplotlib/backends/backend_ps.py

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -103,24 +103,24 @@ def __init__(self, width, height, pswriter):
103103
def set_color(self, r, g, b, store=1):
104104
if (r,g,b) != self.color:
105105
if r==g and r==b:
106-
self._pswriter.write("%s setgray\n"%_num_to_str(r))
106+
self._pswriter.write("%1.3f setgray\n"%r)
107107
else:
108-
self._pswriter.write("%s setrgbcolor\n"%_nums_to_str(r,g,b))
108+
self._pswriter.write("%1.3f %1.3f %1.3f setrgbcolor\n"%(r,g,b))
109109
self.color = (r,g,b)
110110

111111
def set_linewidth(self, linewidth):
112112
if linewidth != self.linewidth:
113-
self._pswriter.write("%s setlinewidth\n"%_num_to_str(linewidth))
113+
self._pswriter.write("%1.3f setlinewidth\n"%linewidth)
114114
self.linewidth = linewidth
115115

116116
def set_linejoin(self, linejoin):
117117
if linejoin != self.linejoin:
118-
self._pswriter.write("%s setlinejoin\n"%_num_to_str(linejoin))
118+
self._pswriter.write("%1.3f setlinejoin\n"%linejoin)
119119
self.linejoin = linejoin
120120

121121
def set_linecap(self, linecap):
122122
if linecap != self.linecap:
123-
self._pswriter.write("%s setlinecap\n"%_num_to_str(linecap))
123+
self._pswriter.write("%1.3f setlinecap\n"%linecap)
124124
self.linecap = linecap
125125

126126
def set_linedash(self, offset, seq):
@@ -137,9 +137,10 @@ def set_linedash(self, offset, seq):
137137

138138
def set_font(self, fontname, fontsize):
139139
if (fontname,fontsize) != (self.fontname,self.fontsize):
140-
self._pswriter.write("/%s findfont\n"%fontname)
141-
self._pswriter.write("%s scalefont\n"%_num_to_str(fontsize))
142-
self._pswriter.write("setfont\n")
140+
writer = self._pswriter
141+
writer.write("/%s findfont\n"%fontname)
142+
writer.write("%1.3f scalefont\n"%fontsize)
143+
writer.write("setfont\n")
143144
self.fontname = fontname
144145
self.fontsize = fontsize
145146

@@ -387,8 +388,10 @@ def _draw_ps(self, ps, gc, rgbFace, command=None):
387388
Emit the PostScript sniplet 'ps' with all the attributes from 'gc'
388389
applied. 'ps' must consist of PostScript commands to construct a path.
389390
"""
391+
# local attr lookup faster and this is
392+
writer = self._pswriter
390393
if debugPS and command:
391-
self._pswriter.write("% "+command+"\n")
394+
writer.write("% "+command+"\n")
392395

393396
cliprect = gc.get_clip_rectangle()
394397
self.set_color(*gc.get_rgb())
@@ -400,21 +403,21 @@ def _draw_ps(self, ps, gc, rgbFace, command=None):
400403
cint = {'butt':0, 'round':1, 'projecting':2}[gc.get_capstyle()]
401404
self.set_linecap(cint)
402405
self.set_linedash(*gc.get_dashes())
403-
if cliprect:
404-
self._pswriter.write("gsave\n")
405406
if cliprect:
406407
x,y,w,h=cliprect
407-
self._pswriter.write('%s clipbox\n' % _nums_to_str(w,h,x,y))
408-
self._pswriter.write(ps.strip()+'\n')
408+
writer.write('gsave\n%1.3f %1.3f %1.3f %1.3f clipbox\n' % (w,h,x,y))
409+
# Jochen, is the strip necessary? - this could be a honking big string
410+
writer.write(ps.strip())
411+
writer.write("\n")
409412
if rgbFace:
410413
#print 'rgbface', rgbFace
411-
self._pswriter.write("gsave\n")
414+
writer.write("gsave\n")
412415
self.set_color(store=0, *rgbFace)
413-
self._pswriter.write("fill\n")
414-
self._pswriter.write("grestore\n")
415-
self._pswriter.write("stroke\n")
416+
writer.write("fill\ngrestore\n")
417+
418+
writer.write("stroke\n")
416419
if cliprect:
417-
self._pswriter.write("grestore\n")
420+
writer.write("grestore\n")
418421

419422

420423
class GraphicsContextPS(GraphicsContextBase):

lib/matplotlib/lines.py

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ def _get_numeric_clipped_data_in_range(self):
216216
# if the x or y clip is set, only plot the points in the
217217
# clipping region. If log scale is set, only pos data will be
218218
# returned
219+
219220
try: self._xc, self._yc
220221
except AttributeError: x, y = self._x, self._y
221222
else: x, y = self._xc, self._yc
@@ -226,11 +227,14 @@ def _get_numeric_clipped_data_in_range(self):
226227
try: logy = self._transform.get_funcy().get_type()==LOG10
227228
except RuntimeError: logy = False # non-separable
228229

229-
if not logx and not logy: return x, y
230+
if not logx and not logy:
231+
return x, y
230232

231233
if self._logcache is not None:
232-
return self._logcache
233-
234+
waslogx, waslogy, xcache, ycache = self._logcache
235+
if logx==waslogx and waslogy==logy:
236+
return xcache, ycache
237+
234238
Nx = len(x)
235239
Ny = len(y)
236240

@@ -244,7 +248,7 @@ def _get_numeric_clipped_data_in_range(self):
244248
x = take(x, ind)
245249
y = take(y, ind)
246250

247-
self._logcache = x, y
251+
self._logcache = logx, logy, x, y
248252
return x, y
249253

250254
def draw(self, renderer):
@@ -710,9 +714,19 @@ def _draw_tickdown(self, renderer, gc, xt, yt):
710714

711715
def _draw_plus(self, renderer, gc, xt, yt):
712716
offset = 0.5*renderer.points_to_pixels(self._markersize)
713-
for (x,y) in zip(xt, yt):
714-
renderer.draw_line(gc, x-offset, y, x+offset, y)
715-
renderer.draw_line(gc, x, y-offset, x, y+offset)
717+
if 0:
718+
path = (
719+
(1, -offset, 0),
720+
(2, offset, 0),
721+
(1, 0, -offset),
722+
(2, 0, offset),
723+
)
724+
renderer.draw_markers(gc, path, xt, yt)
725+
print 'called draw plus'
726+
else:
727+
for (x,y) in zip(xt, yt):
728+
renderer.draw_line(gc, x-offset, y, x+offset, y)
729+
renderer.draw_line(gc, x, y-offset, x, y+offset)
716730

717731
def _draw_tri_down(self, renderer, gc, xt, yt):
718732
offset = 0.5*renderer.points_to_pixels(self._markersize)

0 commit comments

Comments
 (0)