Skip to content

Commit dd9cfa4

Browse files
committed
Merge pull request #1125 from dmcdougall/oo
Reduce object-oriented boilerplate for users
2 parents a7aaa83 + 8738c1c commit dd9cfa4

27 files changed

+64
-5
lines changed

doc/users/whats_new.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,17 @@ Features that depend on the Python Imaging Library, such as JPEG
3838
handling, do not work, since the version of PIL for Python 3.x is not
3939
sufficiently mature.
4040

41+
Object-oriented interface
42+
-------------------------
43+
44+
Damon McDougall has reduced some of the boilerplate code needed to interact
45+
with the object-oriented interface. Now a figure canvas is set up by default::
46+
47+
>>> from matplotlib.figure import Figure
48+
>>> fig = Figure()
49+
>>> ax = fig.add_subplot(1, 1, 1)
50+
>>> fig.savefig('figure.pdf')
51+
4152
PGF/TikZ backend
4253
----------------
4354
Peter Würtz wrote a backend that allows matplotlib to export figures as

lib/matplotlib/backends/backend_agg.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,3 +515,5 @@ def print_to_buffer(self):
515515
(int(renderer.width), int(renderer.height)))
516516
renderer.dpi = original_dpi
517517
return result
518+
519+
FigureCanvas = FigureCanvasAgg

lib/matplotlib/backends/backend_cairo.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,3 +512,5 @@ def _save (self, fo, format, **kwargs):
512512

513513
ctx.show_page()
514514
surface.finish()
515+
516+
FigureCanvas = FigureCanvasCairo

lib/matplotlib/backends/backend_cocoaagg.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def stop_event_loop(self):
8989
FigureCanvasBase.stop_event_loop_default(self)
9090
stop_event_loop.__doc__=FigureCanvasBase.stop_event_loop_default.__doc__
9191

92-
92+
FigureCanvas = FigureCanvasCocoaAgg
9393

9494
NibClassBuilder.extractClasses('Matplotlib.nib', mplBundle)
9595

lib/matplotlib/backends/backend_emf.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -727,6 +727,8 @@ def print_emf(self, filename, dpi=300, **kwargs):
727727
def get_default_filetype(self):
728728
return 'emf'
729729

730+
FigureCanvas = FigureCanvasEMF
731+
730732
class FigureManagerEMF(FigureManagerBase):
731733
"""
732734
Wrap everything up into a window for the pylab interface

lib/matplotlib/backends/backend_fltkagg.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,8 @@ def stop_event_loop(self):
231231
FigureCanvasBase.stop_event_loop_default(self)
232232
stop_event_loop.__doc__=FigureCanvasBase.stop_event_loop_default.__doc__
233233

234+
FigureCanvas = FigureCanvasFltkAgg
235+
234236
def destroy_figure(ptr, figman):
235237
figman.window.hide()
236238
Fltk.Fl.wait(0) # This is needed to make the last figure vanish.

lib/matplotlib/backends/backend_gdk.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ def new_figure_manager_given_figure(num, figure):
434434
return manager
435435

436436

437-
class FigureCanvasGDK (FigureCanvasBase):
437+
class FigureCanvasGDK(FigureCanvasBase):
438438
def __init__(self, figure):
439439
FigureCanvasBase.__init__(self, figure)
440440

@@ -472,3 +472,5 @@ def _print_image(self, filename, format, *args, **kwargs):
472472
0, 0, 0, 0, width, height)
473473

474474
pixbuf.save(filename, format)
475+
476+
FigureCanvas = FigureCanvasGDK

lib/matplotlib/backends/backend_gtk.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ def _on_timer(self):
144144
return False
145145

146146

147-
class FigureCanvasGTK (gtk.DrawingArea, FigureCanvasBase):
147+
class FigureCanvasGTK(gtk.DrawingArea, FigureCanvasBase):
148148
keyvald = {65507 : 'control',
149149
65505 : 'shift',
150150
65513 : 'alt',
@@ -519,6 +519,8 @@ def stop_event_loop(self):
519519
FigureCanvasBase.stop_event_loop_default(self)
520520
stop_event_loop.__doc__=FigureCanvasBase.stop_event_loop_default.__doc__
521521

522+
FigureCanvas = FigureCanvasGTK
523+
522524
class FigureManagerGTK(FigureManagerBase):
523525
"""
524526
Public attributes

lib/matplotlib/backends/backend_gtk3.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def _on_timer(self):
9898
self._timer = None
9999
return False
100100

101-
class FigureCanvasGTK3 (Gtk.DrawingArea, FigureCanvasBase):
101+
class FigureCanvasGTK3(Gtk.DrawingArea, FigureCanvasBase):
102102
keyvald = {65507 : 'control',
103103
65505 : 'shift',
104104
65513 : 'alt',

lib/matplotlib/backends/backend_gtk3agg.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ def print_png(self, filename, *args, **kwargs):
6767
agg = self.switch_backends(backend_agg.FigureCanvasAgg)
6868
return agg.print_png(filename, *args, **kwargs)
6969

70+
FigureCanvas = FigureCanvasGTK3Agg
7071

7172
class FigureManagerGTK3Agg(backend_gtk3.FigureManagerGTK3):
7273
pass

0 commit comments

Comments
 (0)