chaco.plot module¶
Defines the Plot class.
-
class
chaco.plot.
Plot
(data=None, **kwtraits)¶ Bases:
chaco.data_view.DataView
Represents a correlated set of data, renderers, and axes in a single screen region.
A Plot can reference an arbitrary amount of data and can have an unlimited number of renderers on it, but it has a single X-axis and a single Y-axis for all of its associated data. Therefore, there is a single range in X and Y, although there can be many different data series. A Plot also has a single set of grids and a single background layer for all of its renderers. It cannot be split horizontally or vertically; to do so, create a VPlotContainer or HPlotContainer and put the Plots inside those. Plots can be overlaid as well; be sure to set the bgcolor of the overlaying plots to “none” or “transparent”.
A Plot consists of composable sub-plots. Each of these is created or destroyed using the plot() or delplot() methods. Every time that new data is used to drive these sub-plots, it is added to the Plot’s list of data and data sources. Data sources are reused whenever possible; in order to have the same actual array drive two de-coupled data sources, create those data sources before handing them to the Plot.
-
add_xy_plot
(index_name, value_name, renderer_factory, name=None, origin=None, **kwds)¶ Add a BaseXYPlot renderer subclass to this Plot.
- Parameters
index_name (str) – The name of the index datasource.
value_name (str) – The name of the value datasource.
renderer_factory (callable) – The callable that creates the renderer.
name (string (optional)) – The name of the plot. If None, then a default one is created (usually “plotNNN”).
origin (string (optional)) –
- Which corner the origin of this plot should occupy:
”bottom left”, “top left”, “bottom right”, “top right”
**kwds – Additional keywords to pass to the factory.
-
auto_colors
= List( …¶ List of colors to cycle through when auto-coloring is requested. Picked and ordered to be red-green color-blind friendly, though should not be an issue for blue-yellow.
-
candle_plot
(data, name=None, value_scale='linear', origin=None, **styles)¶ Adds a new sub-plot using the given data and plot style.
- Parameters
data (list(string), tuple(string)) –
The names of the data to be plotted in the ArrayDataSource. The number of arguments determines how they are interpreted:
- (index, bar_min, bar_max)
filled or outline-only bar extending from bar_min to bar_max
- (index, bar_min, center, bar_max)
above, plus a center line of a different color at center
- (index, min, bar_min, bar_max, max)
bar extending from bar_min to bar_max, with thin bars at min and max connected to the bar by a long stem
- (index, min, bar_min, center, bar_max, max)
like above, plus a center line of a different color and configurable thickness at center
name (string) – The name of the plot. If None, then a default one is created.
value_scale (string) – The type of scale to use for the value axis. If not “linear”, then a log scale is used.
Styles –
------ –
are all optional keyword arguments. (These) –
bar_color (string, 3- or 4-tuple) – The fill color of the bar; defaults to “auto”.
bar_line_color (string, 3- or 4-tuple) – The color of the rectangular box forming the bar.
stem_color (string, 3- or 4-tuple (default = bar_line_color)) – The color of the stems reaching from the bar to the min and max values.
center_color (string, 3- or 4-tuple (default = bar_line_color)) – The color of the line drawn across the bar at the center values.
line_width (int (default = 1)) – The thickness, in pixels, of the outline around the bar.
stem_width (int (default = line_width)) – The thickness, in pixels, of the stem lines
center_width (int (default = line_width)) – The width, in pixels, of the line drawn across the bar at the center values.
end_cap (bool (default = True)) – Whether or not to draw bars at the min and max extents of the error bar.
- Returns
- Return type
[renderers] -> list of renderers created in response to this call.
-
color_mapper
= Instance(AbstractColormap)¶ Optional mapper for the color axis. Not instantiated until first use; destroyed if no color plots are on the plot.
-
contour_plot
(data, type='line', name=None, poly_cmap=None, xbounds=None, ybounds=None, origin=None, hide_grids=True, **styles)¶ Adds contour plots to this Plot object.
- Parameters
data (string) – The name of the data array in self.plot_data, which must be floating point data.
type (comma-delimited string of "line", "poly") – The type of contour plot to add. If the value is “poly” and no colormap is provided via the poly_cmap argument, then a default colormap of ‘Spectral’ is used.
name (string) – The name of the plot; if omitted, then a name is generated.
poly_cmap (string) – The name of the color-map function to call (in chaco.default_colormaps) or an AbstractColormap instance to use for contour poly plots (ignored for contour line plots)
xbounds (string, tuple, or ndarray) – Bounds where this image resides. Bound may be: a) names of data in the plot data; b) tuples of (low, high) in data space, c) 1D arrays of values representing the pixel boundaries (must be 1 element larger than underlying data), or d) 2D arrays as obtained from a meshgrid operation
ybounds (string, tuple, or ndarray) – Bounds where this image resides. Bound may be: a) names of data in the plot data; b) tuples of (low, high) in data space, c) 1D arrays of values representing the pixel boundaries (must be 1 element larger than underlying data), or d) 2D arrays as obtained from a meshgrid operation
origin (string) –
- Which corner the origin of this plot should occupy:
”bottom left”, “top left”, “bottom right”, “top right”
hide_grids (bool, default True) – Whether or not to automatically hide the grid lines on the plot
styles (series of keyword arguments) – Attributes and values that apply to one or more of the plot types requested, e.g.,’line_color’ or ‘line_width’.
-
data
= Instance(AbstractPlotData)¶ The PlotData instance that drives this plot.
-
datasources
= Dict(Str, Instance(AbstractDataSource))¶ Mapping of data names from self.data to their respective datasources.
-
default_index
= Instance(AbstractDataSource)¶ The default index to use when adding new subplots.
-
delplot
(*names)¶ Removes the named sub-plots.
-
hideplot
(*names)¶ Convenience function to sets the named plots to be invisible. Their renderers are not removed, and they are still in the list of plots.
-
img_plot
(data, name=None, colormap=None, xbounds=None, ybounds=None, origin=None, hide_grids=True, **styles)¶ Adds image plots to this Plot object.
If data has shape (N, M, 3) or (N, M, 4), then it is treated as RGB or RGBA (respectively) and colormap is ignored.
If data is an array of floating-point data, then a colormap can be provided via the colormap argument, or the default of ‘Spectral’ will be used.
Data should be in row-major order, so that xbounds corresponds to data’s second axis, and ybounds corresponds to the first axis.
- Parameters
data (string) – The name of the data array in self.plot_data
name (string) – The name of the plot; if omitted, then a name is generated.
xbounds (string, tuple, or ndarray) – Bounds where this image resides. Bound may be: a) names of data in the plot data; b) tuples of (low, high) in data space, c) 1D arrays of values representing the pixel boundaries (must be 1 element larger than underlying data), or d) 2D arrays as obtained from a meshgrid operation
ybounds (string, tuple, or ndarray) – Bounds where this image resides. Bound may be: a) names of data in the plot data; b) tuples of (low, high) in data space, c) 1D arrays of values representing the pixel boundaries (must be 1 element larger than underlying data), or d) 2D arrays as obtained from a meshgrid operation
origin (string) –
- Which corner the origin of this plot should occupy:
”bottom left”, “top left”, “bottom right”, “top right”
hide_grids (bool, default True) – Whether or not to automatically hide the grid lines on the plot
styles (series of keyword arguments) – Attributes and values that apply to one or more of the plot types requested, e.g.,’line_color’ or ‘line_width’.
-
legend
= Instance(Legend)¶ The legend on the plot.
-
legend_alignment
= Property¶ Convenience attribute for legend.align; can be “ur”, “ul”, “ll”, “lr”.
-
new_window
(configure=False)¶ Convenience function that creates a window containing the Plot
Don’t call this if the plot is already displayed in a window.
-
plot
(data, type='line', name=None, index_scale='linear', value_scale='linear', origin=None, **styles)¶ Adds a new sub-plot using the given data and plot style.
- Parameters
data (string, tuple(string), list(string)) –
The data to be plotted. The type of plot and the number of arguments determines how the arguments are interpreted:
- one item: (line, scatter, segment)
The data is treated as the value and self.default_index is used as the index. If default_index does not exist, one is created from arange(len(data))
- two or more items: (line, scatter, segment)
Interpreted as (index, value1, value2, …). Each index,value pair forms a new plot of the type specified.
- three items: (cmap_scatter, cmap_segment)
Interpreted as (index, value, color)
- three items: (text)
Interpreted as (index, value, text).
- four items: (cmap_segment)
Interpreted as (index, val1, color_val1, width)
For segment plots index and value arrays alternate between coordinates for the start and end points of segments.
type (comma-delimited string of plot type) – The types of plots to add. One of “line”, “scatter”, “cmap_scatter”, “polygon”, “bar”, “filled_line”, “segment”, “text”
name (string) – The name of the plot. If None, then a default one is created (usually “plotNNN”).
index_scale (string) – The type of scale to use for the index axis. If not “linear”, then a log scale is used.
value_scale (string) – The type of scale to use for the value axis. If not “linear”, then a log scale is used.
origin (string) –
- Which corner the origin of this plot should occupy:
”bottom left”, “top left”, “bottom right”, “top right”
styles (series of keyword arguments) – attributes and values that apply to one or more of the plot types requested, e.g.,’line_color’ or ‘line_width’.
Examples
plot("my_data", type="line", name="myplot", color=lightblue) plot(("x-data", "y-data"), type="scatter") plot(("x", "y1", "y2", "y3"))
- Returns
- Return type
[renderers] -> list of renderers created in response to this call to plot()
-
plot_1d
(data, type='scatter_1d', name=None, orientation=None, direction=None, scale='linear', **styles)¶ Adds a new sub-plot using the given data and plot style.
- Parameters
data (string, tuple(string), list(string)) – The data to be plotted. The each item generates a separate renderer using the named data source
type (string) – The type of plots to add. One of of “scatter_1d”, “line_scatter_1d”, “textplot_1d”, “jitterplot”
name (string) – The name of the plot. If None, then a default one is created (usually “plotNNN”).
scale (string) – The type of scale to use for the index axis. If not “linear”, then a log scale is used.
orientation (string) – Whether the single dimension is horizontal (‘h’) or vertical (‘v’).
direction (string) – Whether data is mapped in the usual direction (left to right or bottom to top) or reversed.
styles (series of keyword arguments) – attributes and values that apply to one or more of the plot types requested, e.g.,’line_color’ or ‘line_width’.
- Returns
- Return type
[renderers] -> list of renderers created in response to this call to plot()
-
plots
= Dict(Str, List)¶ Mapping of plot names to lists of plot renderers.
-
quiverplot
(data, name=None, origin=None, **styles)¶ Adds a new sub-plot using the given data and plot style.
- Parameters
data (list(string), tuple(string)) –
The names of the data to be plotted in the ArrayDataSource. There is only one combination accepted by this function:
- (index, value, vectors)
index and value together determine the start coordinates of each vector. The vectors are an Nx2
name (string) – The name of the plot. If None, then a default one is created.
origin (string) –
- Which corner the origin of this plot should occupy:
”bottom left”, “top left”, “bottom right”, “top right”
Styles –
------ –
are all optional keyword arguments. (These) –
line_color (string (default = "black")) – The color of the arrows
line_width (float (default = 1.0)) – The thickness, in pixels, of the arrows.
arrow_size (int (default = 5)) – The length, in pixels, of the arrowhead
- Returns
- Return type
[renderers] -> list of renderers created in response to this call.
-
renderer_map
= Dict( …¶ Mapping of renderer type string to renderer class This can be overriden to customize what renderer type the Plot will instantiate for its various plotting methods.
-
showplot
(*names)¶ Convenience function to sets the named plots to be visible.
-
title
= Property()¶ The title of the plot.
-
title_font
= Property()¶ The font to use for the title.
-
title_position
= Property()¶ Convenience attribute for title.overlay_position; can be “top”, “bottom”, “left”, or “right”.
-
title_text
= Delegate("_title", prefix="text", modify=True)¶ Use delegates to expose the other PlotLabel attributes of the plot title
-