chaco.base_xy_plot module

Defines the base class for XY plots.

class chaco.base_xy_plot.BaseXYPlot(**kwtraits)

Bases: chaco.abstract_plot_renderer.AbstractPlotRenderer

Base class for simple X-vs-Y plots that consist of a single index data array and a single value data array.

Subclasses handle the actual rendering, but this base class takes care of most of making sure events are wired up between mappers and data or screen space changes, etc.

alpha = Range(0.0, 1.0, 1.0, requires_redraw=True)

Overall alpha value of the image. Ranges from 0.0 for transparent to 1.0

bgcolor = "transparent"

Overrides the default background color trait in PlotComponent.

get_closest_line(screen_pt, threshold=7.0)

Tests for proximity in screen-space against lines connecting the points in this plot’s dataset.

Parameters
  • screen_pt ((x,y)) – A point to test.

  • threshold (integer) – Optional maximum screen space distance (pixels) between the line and the plot. If 0.0, then the method returns the closest line regardless of distance from the plot.

Returns

  • (x1, y1, x2, y2, dist) of the endpoints of the line segment

  • closest to *screen_pt. The dist element is the perpendicular*

  • distance from *screen_pt to the line. If there is only a single point*

  • in the renderer’s data, then the method returns the same point twice.

  • If no data points are within *threshold of screen_pt, returns None.*

get_closest_point(screen_pt, threshold=7.0)

Tests for proximity in screen-space.

This method checks only data points, not the line segments connecting them; to do the latter use get_closest_line() instead.

Parameters
  • screen_pt ((x,y)) – A point to test.

  • threshold (integer) – Optional maximum screen space distance (pixels) between screen_pt and the plot. If 0.0, then no threshold tests are performed, and the nearest point is returned.

Returns

  • (x, y, distance) of a datapoint nearest to *screen_pt.*

  • If no data points are within *threshold of screen_pt, returns None.*

get_screen_points()

Returns the currently visible screen-space points.

Intended for use with overlays.

hgrid = Property

Read-only property for horizontal grid.

hittest(screen_pt, threshold=7.0, return_distance=False)

Performs proximity testing between a given screen point and the plot.

Parameters
  • screen_pt ((x,y)) – A point to test.

  • threshold (integer) – Optional maximum screen space distance (pixels) between screen_pt and the plot.

  • return_distance (Boolean) – If True, also return the distance.

Returns

  • If self.hittest_type is ‘point’, then this method returns the screen

  • coordinates of the closest point on the plot as a tuple (x,y)

  • If self.hittest_type is ‘line’, then this method returns the screen

  • endpoints of the line segment closest to *screen_pt, as*

  • ((x1,y1), (x2,y2))

  • If *screen_pt does not fall within threshold of the plot, then this*

  • method returns None.

  • If return_distance is True, return the (x, y, d), where d is the

  • distance between the distance between the input point and

  • the closest point (x, y), in screen coordinates.

hittest_type = Enum("point", "line")

The type of hit-testing that is appropriate for this renderer.

  • ‘line’: Computes Euclidean distance to the line between the nearest adjacent points.

  • ‘point’: Checks for adjacency to a marker or point.

index = Instance(ArrayDataSource)

The data source to use for the index coordinate.

index_mapper = Instance(AbstractMapper)

Screen mapper for index data.

index_range = Property

Convenience property for accessing the index data range.

labels = Property

Read-only property for labels.

map_data(screen_pt, all_values=False)

Maps a screen space point into the “index” space of the plot.

Implements the AbstractPlotRenderer interface.

If all_values is True, returns an array of (index, value) tuples; otherwise, it returns only the index values.

map_index(screen_pt, threshold=2.0, outside_returns_none=True, index_only=False)

Maps a screen space point to an index into the plot’s index array(s).

Implements the AbstractPlotRenderer interface.

Parameters
  • screen_pt – Screen space point

  • threshold (float) – Maximum distance from screen space point to plot data point. A value of 0.0 means no threshold (any distance will do).

  • outside_returns_none (bool) – If True, a screen space point outside the data range returns None. Otherwise, it returns either 0 (outside the lower range) or the last index (outside the upper range)

  • index_only (bool) – If True, the threshold is measured on the distance between the index values, otherwise as Euclidean distance between the (x,y) coordinates.

map_screen(data_array)

Maps an array of data points into screen space and returns it as an array.

Implements the AbstractPlotRenderer interface.

orientation = Enum("h", "v")

The orientation of the index axis.

origin_axis_color = black_color_trait

Defines the origin axis color, for testing.

origin_axis_visible = Bool(False)

Defines the origin axis visibility, for testing.

origin_axis_width = Float(1.0)

Defines a the origin axis width, for testing.

use_downsampling = Bool(False)

Does the plot use downsampling? This is not used right now. It needs an implementation of robust, fast downsampling, which does not exist yet.

use_subdivision = Bool(False)

Does the plot use a spatial subdivision structure for fast hit-testing? This makes data updates slower, but makes hit-tests extremely fast.

value = Instance(AbstractDataSource)

The data source to use as value points.

value_mapper = Instance(AbstractMapper)

Screen mapper for value data

value_range = Property

Convenience property for accessing the value data range.

vgrid = Property

Read-only property for vertical grid.

x_axis = Property

Read-only property for x-axis.

x_mapper = Property

Corresponds to either index_mapper or value_mapper, depending on the orientation of the plot.

y_axis = Property

Read-only property for y-axis.

y_mapper = Property

Corresponds to either value_mapper or index_mapper, depending on the orientation of the plot.