Skip to content

Commit 81188fb

Browse files
committed
fixed canvas switcher bug
svn path=/trunk/matplotlib/; revision=943
1 parent 4376f1c commit 81188fb

16 files changed

+227
-87
lines changed

API_CHANGES

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ API CHANGES in matplotlib-0.72
2525

2626
subs=none now does autosubbing in the tick locator.
2727

28-
removed BBoxTransformation
28+
New subplots that overlap old will delete the old axes. If you do
29+
not want this behavior, use fig.add_subplot or the axes command
2930

3031
API CHANGES in matplotlib-0.71
3132

MANIFEST.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
include API_CHANGES CHANGELOG KNOWN_BUGS INSTALL
1+
include API_CHANGES CHANGELOG KNOWN_BUGS INSTALL NUMARRAY_ISSUES
22
include INTERACTIVE TODO
33
include Makefile MANIFEST.in MANIFEST
44
include .matplotlibrc

TODO

Lines changed: 1 addition & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -642,48 +642,4 @@ ZeroDivisionError: SeparableTransformation::eval_scalars yin interval is zero; c
642642

643643
-- fix contour mappable to work under changes in clim, cmap
644644

645-
-- port colorbar, current mappable to API
646-
647-
-- add qt / gpl warning
648-
649-
-- Nil's xtick labeling bug
650-
651-
-- make a fig dict wrapper
652-
653-
-- plot items ala gnuplot
654-
FileItem, FuncItem, High level plot items
655-
656-
-- doc why figimage doesn't respond to nav
657-
658-
- imshow() bug: make a random 1024x1024 array, zoom in hard (to a 10x10
659-
square). All displayed area is white.
660-
661-
662-
-- Tk figure destruction bugs with mayavi. Already reported.
663-
664-
-- run in ipython with -backend
665-
666-
667-
- easy interactive logscaling x/y axes independently. (l->y, L->x) Button?
668-
669-
- grid on/off toggle (g key), button?
670-
671-
- measuring ruler? (see gnuplot's 'r' hotkey in X11).
672-
673-
- button to add text labels easily anywhere on the plot. A few drawing
674-
buttons as well for simple things? Circle/ellipse, box, arrows, etc.
675-
676-
- toggle log/linear shows strange accumulation of ticks on y axis
677-
678-
from pylab import *
679-
x = arange(-2.00, 10, 0.01)
680-
y = exp(-x)
681-
plot(x,y)
682-
#set(gca(), xscale='log')
683-
show()
684-
685-
-- DONE pyparsing a performance bottleneck for log ticks
686-
687-
-- DONE draw point and draw pixel currently broken for new style markers
688-
689-
-- alpha channel in colormaps
645+
-- make subplot delaxes on other subplots under it.

lib/matplotlib/backend_bases.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -802,11 +802,19 @@ def destroy(self):
802802
pass
803803

804804
def key_press(self, event):
805+
806+
# these bindings happen whether you are over an axes or not
807+
#if event.key == 'q':
808+
# self.destroy() # how cruel to have to destroy oneself!
809+
# return
810+
805811
if event.inaxes is None: return
812+
813+
# the mouse has to be over an axes to trigger these
806814
if event.key == 'g':
807815
event.inaxes.grid()
808816
self.canvas.draw()
809-
if event.key == 'l':
817+
elif event.key == 'l':
810818
event.inaxes.toggle_log_lineary()
811819
self.canvas.draw()
812820

lib/matplotlib/backends/backend_agg.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,3 +399,4 @@ def print_figure(self, filename, dpi=150,
399399
self.figure.dpi.set(origDPI)
400400
self.figure.set_facecolor(origfacecolor)
401401
self.figure.set_edgecolor(origedgecolor)
402+
self.figure.set_canvas(self)

lib/matplotlib/backends/backend_fltkagg.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,8 @@ def print_figure(self, filename, dpi=150,
220220

221221
agg = self.switch_backends(FigureCanvasAgg)
222222
agg.print_figure(filename, dpi, facecolor, edgecolor, orientation)
223-
223+
self.figure.set_canvas(self)
224+
224225
def widget(self):
225226
return self.canvas
226227

lib/matplotlib/backends/backend_gdk.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -572,3 +572,5 @@ def print_figure(self, filename, dpi=150, facecolor='w', edgecolor='w',
572572
error_msg('Format "%s" is not supported.\nSupported formats are %s.' %
573573
(ext, ', '.join(IMAGE_FORMAT)),
574574
parent=self)
575+
576+
self.figure.set_canvas(self)

lib/matplotlib/backends/backend_gtk.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ def print_figure(self, filename, dpi=150, facecolor='w', edgecolor='w',
349349
self.figure.set_facecolor(origfacecolor)
350350
self.figure.set_edgecolor(origedgecolor)
351351
self.figure.set_figsize_inches(origWIn, origHIn)
352-
352+
self.figure.set_canvas(self)
353353

354354
class FigureManagerGTK(FigureManagerBase):
355355
"""

lib/matplotlib/backends/backend_gtkagg.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ def print_figure(self, filename, dpi=150,
6565
agg = self.switch_backends(FigureCanvasAgg)
6666
agg.print_figure(filename, dpi, facecolor, edgecolor, orientation)
6767

68+
self.figure.set_canvas(self)
6869

6970

7071
def configure_event(self, widget, event=None):

lib/matplotlib/backends/backend_ps.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,9 @@ def draw_line(self, gc, x0, y0, x1, y1):
283283

284284
def _draw_markers(self, gc, path, x, y, transform):
285285
"""
286+
I'm underscore hiding this method from lines.py right now
287+
since it is incomplete
288+
286289
Draw the markers defined by path at each of the positions in x
287290
and y. path coordinates are points, x and y coords will be
288291
transformed by the transform

lib/matplotlib/backends/backend_qtagg.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ def print_figure(self, filename, dpi=150,
215215

216216
agg = self.switch_backends(FigureCanvasAgg)
217217
agg.print_figure(filename, dpi, facecolor, edgecolor, orientation)
218+
self.figure.set_canvas(self)
218219

219220
class NavigationToolbar2QtAgg(NavigationToolbar2, qt.QToolBar):
220221
"""

lib/matplotlib/backends/backend_tkagg.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ def print_figure(self, filename, dpi=150,
159159

160160
agg = self.switch_backends(FigureCanvasAgg)
161161
agg.print_figure(filename, dpi, facecolor, edgecolor, orientation)
162-
162+
self.figure.set_canvas(self)
163163

164164
def motion_notify_event(self, event):
165165
x = event.x

lib/matplotlib/backends/backend_wx.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -896,6 +896,7 @@ def print_figure(self, filename, dpi=150,
896896

897897
ps.print_figure(filename, 72, facecolor, edgecolor)
898898
self.figure.dpi.set(origDPI)
899+
self.figure.set_canvas(self)
899900
return
900901
elif ext.find('svg')>=0:
901902
# enable svg save from WX backend only import this if we
@@ -907,7 +908,8 @@ def print_figure(self, filename, dpi=150,
907908
svg = self.switch_backends(FigureCanvasSVG)
908909
svg.figure.dpi.set(72)
909910
svg.print_figure(filename, 72, facecolor, edgecolor)
910-
self.figure.dpi.set(origDPI)
911+
self.figure.dpi.set(origDPI)
912+
self.figure.set_canvas(self)
911913
return
912914

913915
if not self._isRealized:

lib/matplotlib/backends/backend_wxagg.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ def print_figure(self, filename, dpi=150, facecolor='w',
6767
"""
6868
agg = self.switch_backends(FigureCanvasAgg)
6969
agg.print_figure(filename, dpi, facecolor, edgecolor, orientation)
70+
self.figure.set_canvas(self)
7071

7172
def _get_imagesave_wildcards(self):
7273
'return the wildcard string for the filesave dialog'

lib/matplotlib/pylab.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -761,7 +761,8 @@ def figlegend(handles, labels, loc, **kwargs):
761761
return l
762762

763763
def savefig(*args, **kwargs):
764-
try: ret = gcf().savefig(*args, **kwargs)
764+
fig = gcf()
765+
try: ret = fig.savefig(*args, **kwargs)
765766
except RuntimeError, msg:
766767
msg = raise_msg_to_str(msg)
767768
error_msg(msg)
@@ -1266,10 +1267,28 @@ def subplot(*args, **kwargs):
12661267
12671268
See help(axes) for additional information on axes and subplot
12681269
keyword arguments.
1270+
1271+
New subplots that overlap old will delete the old axes. If you do
1272+
not want this behavior, use fig.add_subplot or the axes command. Eg
1273+
1274+
from pylab import *
1275+
plot([1,2,3]) # implicitly creates subplot(111)
1276+
subplot(211) # overlaps, subplot(111) is killed
1277+
plot(rand(12), rand(12))
1278+
12691279
"""
12701280

12711281
try:
1272-
a = gcf().add_subplot(*args, **kwargs)
1282+
fig = gcf()
1283+
a = fig.add_subplot(*args, **kwargs)
1284+
bbox = a.bbox
1285+
byebye = []
1286+
for other in fig.axes:
1287+
if other==a: continue
1288+
if bbox.overlaps(other.bbox):
1289+
byebye.append(other)
1290+
for ax in byebye: delaxes(ax)
1291+
12731292
except ValueError, msg:
12741293
msg = raise_msg_to_str(msg)
12751294
error_msg(msg)

0 commit comments

Comments
 (0)