Menu

[r2807]: / trunk / course / examples / mpl_agg_oo.py  Maximize  Restore  History

Download this file

27 lines (21 with data), 739 Bytes

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
"""
A pure object oriented example using the agg backend
"""
# import the matplotlib backend you want to use and the Figure class
from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas
from matplotlib.figure import Figure
# the figure is the center of the action, and the canvas is a backend
# dependent container to hold the figure and make backend specific calls
fig = Figure()
canvas = FigureCanvas(fig)
# you can add multiple subplots and axes
ax = fig.add_subplot(111)
# the simplest plot!
ax.plot([1,2,3])
# you can decorate your plot with text and grids
ax.set_title('hi mom')
ax.grid(True)
ax.set_xlabel('time')
ax.set_ylabel('volts')
# and save it to hardcopy
fig.savefig('../fig/mpl_one_two_three.png')
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.