How to use the pylab API vs. the matplotlib API
This article has a good description of the 2 API's in matplotlib: the pylab API and the matplotlib API. I've been using the pylab interface because it is easier, especially coming from a matlab background. But I wanted to get direct access to the matplotlib classes so I needed to use the matplotlib API. Here is a simple example that creates a .png figure using the 2 different API's.
Here is the example using the pylab API:
Here is the example using the matplotlib API:
Here is the example using the pylab API:
""" api_pylab.py
"""
from pylab import *
figure(figsize=[4,4])
axes([.1,.1,.8,.8])
scatter([1,2],[3,4])
savefig('api_pylab.png')
Here is the example using the matplotlib API:
""" api_matplotlib.py
"""
from matplotlib.figure import Figure
from matplotlib.backends.backend_agg import FigureCanvasAgg
fig = Figure(figsize=[4,4])
ax = fig.add_axes([.1,.1,.8,.8])
ax.scatter([1,2], [3,4])
canvas = FigureCanvasAgg(fig)
canvas.print_figure("api_matplotlib.png")
Related posts
- Creating a histogram plot with python — posted 2011-12-08
- How to draw a simple line using python and the matplotlib API - — posted 2007-01-05
- How to create some derived arrow classes with matplotlib and python — posted 2007-01-03
- How to draw an arrow with matplotlib and python — posted 2007-01-02
- Example pie charts using python and matplotlib — posted 2006-12-19