The chaco examples create the displayed plot object in atleast two different ways - they either override the __init__ method of the underlying traits class to create and store the plot object or they define a plot trait and a _plot_default method which creates the plot object.
I think the latter way is preferred over the former - we don't want to unnecessarily override the __init__ method.
|
def __init__(self): |
|
# Create the data and the PlotData object |
|
x = linspace(-14, 14, 100) |
|
y = sin(x) * x ** 3 |
|
plotdata = ArrayPlotData(x=x, y=y) |
|
|
|
# Create a scatter plot |
|
scatter_plot = Plot(plotdata) |
|
scatter_plot.plot(("x", "y"), type="scatter", color="blue") |
|
|
|
# Create a line plot |
|
line_plot = Plot(plotdata) |
|
line_plot.plot(("x", "y"), type="line", color="blue") |
|
|
|
# Create a horizontal container and put the two plots inside it |
|
container = HPlotContainer(line_plot, scatter_plot, spacing=100) |
|
self.plot = container |
|
def _plot_default(self): |
|
y = self.x ** self.power |
|
plot_data = ArrayPlotData(x=self.x, y=y) |
|
plot = Plot(plot_data) |
|
plot.plot(("x", "y"), "line", name="power function", color="auto") |
|
|
|
# configure the plot |
|
plot.padding_top = 25 |
|
plot.border_visible = False |
|
plot.index_grid.visible = False |
|
plot.value_grid.visible = False |
|
plot.title = "Power Function n={}".format(self.power) |
|
plot.title_position = "right" |
|
plot.title_angle = -90 |
|
plot.legend_alignment = "ul" |
|
plot.legend.border_visible = False |
|
plot.legend.bgcolor = (0.9, 0.9, 0.9, 0.5) |
|
plot.legend.visible = True |
|
|
|
plot.index_axis.title = "y" |
|
plot.value_axis.title = "x" |
|
|
|
return plot |
The chaco examples create the displayed plot object in atleast two different ways - they either override the
__init__method of the underlying traits class to create and store the plot object or they define aplottrait and a_plot_defaultmethod which creates the plot object.I think the latter way is preferred over the former - we don't want to unnecessarily override the
__init__method.chaco/examples/user_guide/h_plot_container.py
Lines 20 to 36 in e5a8594
chaco/examples/user_guide/power_function_example.py
Lines 26 to 48 in e5a8594