Matplotlib to Chaco Cheatsheet¶
As mentioned in the Chaco Tutorial, matplotlib and Chaco have different approaches to plotting (script-oriented vs. application-oriented). However, new users of Chaco who have worked with matplotlib in the past may find it useful to think about mapping “equivalent” code between the two.
The following table lists various plotting related operations one might want to
perform along with code for doing that using either Chaco or matplotlib. For
the matplotlib code ax
represents the Plot Axes
i.e. fig, ax = plt.subplots()
after importing
import matplotlib.pyplot as plt
. For more details see the
matplotlib User’s Guide.
For Chaco code, p
is the Plot
instance. x
and y
are the
data to be plotted. In Chaco, this data needs to be wrapped in a
PlotData
object. For example,
import numpy as np
x = np.linspace(-2*np.pi, 2*np.pi, 100)
y = sin(x)
# Chaco only
pd = ArrayPlotData()
pd.set_data("x", x)
pd.set_data("y", y)
p = Plot(pd)
Note that in the matplotlib column, x
and y
represent the data, but
'x'
and 'y'
, such as in the “X grid” and “Y Grid” rows are simply
options for the axis
argument. In Chaco 'x'
and 'y'
are the names
the PlotData
object associates with numpy arrays x
and y
.
What |
Matplotlib |
Chaco |
---|---|---|
Plot lines |
|
|
x label |
|
|
y label |
|
|
Title |
|
|
X limits |
|
|
Y limits |
|
|
Label lines for legend |
|
|
Add legend |
|
|
Legend position |
|
|
Background color |
|
|
Show spines |
|
|
Line width |
|
|
X grid |
|
|
Y grid |
|
|
Second y ticks |
|
|