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

Skip to content

Commit 570e830

Browse files
committed
Use savefig instead of print_figure.
1 parent e3a34c5 commit 570e830

File tree

10 files changed

+18
-15
lines changed

10 files changed

+18
-15
lines changed

examples/api/agg_oo_sgskip.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,21 @@
33
The object-oriented interface
44
=============================
55
6-
A pure OO (look Ma, no pylab!) example using the agg backend
7-
6+
A pure OO (look Ma, no pyplot!) example using the agg backend.
87
"""
8+
99
from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas
1010
from matplotlib.figure import Figure
1111

1212
fig = Figure()
13-
canvas = FigureCanvas(fig)
13+
# A canvas must be manually attached to the figure (pyplot would automatically
14+
# do it). This is done by instanciating the canvas with the figure as
15+
# argument.
16+
FigureCanvas(fig)
1417
ax = fig.add_subplot(111)
1518
ax.plot([1, 2, 3])
1619
ax.set_title('hi mom')
1720
ax.grid(True)
1821
ax.set_xlabel('time')
1922
ax.set_ylabel('volts')
20-
canvas.print_figure('test')
23+
fig.savefig('test')

examples/misc/hyperlinks_sgskip.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
f = plt.figure()
2121
s = plt.scatter([1, 2, 3], [4, 5, 6])
2222
s.set_urls(['http://www.bbc.co.uk/news', 'http://www.google.com', None])
23-
f.canvas.print_figure('scatter.svg')
23+
f.savefig('scatter.svg')
2424

2525
###############################################################################
2626

@@ -36,4 +36,4 @@
3636
origin='lower', extent=[-3, 3, -3, 3])
3737

3838
im.set_url('http://www.google.com')
39-
f.canvas.print_figure('image.svg')
39+
f.savefig('image.svg')

examples/user_interfaces/embedding_webagg_sgskip.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ def get(self, fmt):
153153
self.set_header('Content-Type', mimetypes.get(fmt, 'binary'))
154154

155155
buff = io.BytesIO()
156-
manager.canvas.print_figure(buff, format=fmt)
156+
manager.canvas.figure.savefig(buff, format=fmt)
157157
self.write(buff.getvalue())
158158

159159
class WebSocket(tornado.websocket.WebSocketHandler):

lib/matplotlib/backends/backend_gtk.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -726,7 +726,7 @@ def save_figure(self, *args):
726726
# save dir for next time
727727
rcParams['savefig.directory'] = os.path.dirname(six.text_type(fname))
728728
try:
729-
self.canvas.print_figure(fname, format=format)
729+
self.canvas.figure.savefig(fname, format=format)
730730
except Exception as e:
731731
error_msg_gtk(str(e), parent=self)
732732

lib/matplotlib/backends/backend_gtk3.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,7 @@ def save_figure(self, *args):
580580
# save dir for next time
581581
rcParams['savefig.directory'] = os.path.dirname(six.text_type(fname))
582582
try:
583-
self.canvas.print_figure(fname, format=format)
583+
self.canvas.figure.savefig(fname, format=format)
584584
except Exception as e:
585585
error_msg_gtk(str(e), parent=self)
586586

lib/matplotlib/backends/backend_macosx.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ def save_figure(self, *args):
192192
self.canvas.get_default_filename())
193193
if filename is None: # Cancel
194194
return
195-
self.canvas.print_figure(filename)
195+
self.canvas.figure.savefig(filename)
196196

197197
def prepare_configure_subplots(self):
198198
toolfig = Figure(figsize=(6,3))

lib/matplotlib/backends/backend_qt5.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -750,7 +750,7 @@ def save_figure(self, *args):
750750
savefig_dir = os.path.dirname(six.text_type(fname))
751751
matplotlib.rcParams['savefig.directory'] = savefig_dir
752752
try:
753-
self.canvas.print_figure(six.text_type(fname))
753+
self.canvas.figure.savefig(six.text_type(fname))
754754
except Exception as e:
755755
QtWidgets.QMessageBox.critical(
756756
self, "Error saving file", six.text_type(e),

lib/matplotlib/backends/backend_tkagg.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -791,7 +791,7 @@ def save_figure(self, *args):
791791
rcParams['savefig.directory'] = os.path.dirname(six.text_type(fname))
792792
try:
793793
# This method will handle the delegation to the correct type
794-
self.canvas.print_figure(fname)
794+
self.canvas.figure.savefig(fname)
795795
except Exception as e:
796796
tkinter_messagebox.showerror("Error saving file", str(e))
797797

@@ -1008,7 +1008,7 @@ def trigger(self, *args):
10081008
six.text_type(fname))
10091009
try:
10101010
# This method will handle the delegation to the correct type
1011-
self.figure.canvas.print_figure(fname)
1011+
self.figure.savefig(fname)
10121012
except Exception as e:
10131013
tkinter_messagebox.showerror("Error saving file", str(e))
10141014

lib/matplotlib/backends/backend_webagg.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ def get(self, fignum, fmt):
151151
self.set_header('Content-Type', mimetypes.get(fmt, 'binary'))
152152

153153
buff = six.BytesIO()
154-
manager.canvas.print_figure(buff, format=fmt)
154+
manager.canvas.figure.savefig(buff, format=fmt)
155155
self.write(buff.getvalue())
156156

157157
class WebSocket(tornado.websocket.WebSocketHandler):

lib/matplotlib/backends/backend_wx.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1587,7 +1587,7 @@ def save_figure(self, *args):
15871587
(ext, format, ext), stacklevel=0)
15881588
format = ext
15891589
try:
1590-
self.canvas.print_figure(
1590+
self.canvas.figure.savefig(
15911591
os.path.join(dirname, filename), format=format)
15921592
except Exception as e:
15931593
error_msg_wx(str(e))

0 commit comments

Comments
 (0)