toyplot.coordinates module

Classes and functions for working with coordinate systems.

class toyplot.coordinates.Axis(label=None, domain_min=None, domain_max=None, scale='linear', show=True, tick_angle=0, tick_locator=None)[source]

Bases: object

One dimensional axis that can be used to create coordinate systems.

class DomainHelper(domain_min, domain_max)[source]

Bases: object

Controls domain related behavior for this axis.

max

Specify an explicit domain maximum for this axis. By default the implicit domain maximum is computed from visible data.

min

Specify an explicit domain minimum for this axis. By default the implicit domain minimum is computed from visible data.

show

Control whether the domain should be made visible using the axis spine.

class Axis.InteractiveCoordinatesHelper[source]

Bases: object

Controls the appearance and behavior of interactive coordinates.

label

toyplot.coordinates.Axis.InteractiveCoordinatesLabelHelper instance.

location

Controls the position of interactive coordinates relative to the axis.

Allowed values are “above” (force coordinates to appear above the axis), “below” (the opposite), or None (the default - display interactive coordinates opposite tick labels).

show

Set False to disable showing interactive coordinates for this axis.

tick

toyplot.coordinates.Axis.InteractiveCoordinatesTickHelper instance.

class Axis.InteractiveCoordinatesLabelHelper[source]

Bases: object

show
style

Dictionary of CSS property-value pairs.

Use the style property to control the text appearance. The following CSS properties are allowed:

  • alignment-baseline
  • baseline-shift
  • fill
  • fill-opacity
  • font-size
  • font-weight
  • opacity
  • stroke
  • stroke-opacity
  • stroke-width
  • text-anchor
  • -toyplot-anchor-shift

Note that when assigning to the style property, the properties you supply are merged with the existing properties.

class Axis.InteractiveCoordinatesTickHelper[source]

Bases: object

show
style

Dictionary of CSS property-value pairs.

Use the style property to control the appearance of the line. The following CSS properties are allowed:

  • opacity
  • stroke
  • stroke-dasharray
  • stroke-opacity
  • stroke-width

Note that when assigning to the style property, the properties you supply are merged with the existing properties.

class Axis.InteractiveHelper[source]

Bases: object

Controls interactive behavior for this axis.

coordinates

toyplot.coordinates.Axis.InteractiveCoordinatesHelper instance.

class Axis.LabelHelper(text, style)[source]

Bases: object

location
offset

Specifies the position relative to the axis. Increasing values of offset move the position further away from the axis, whether the location is “above” or “below”.

Getter:Returns the offset in CSS pixels.
Setter:Sets the offset using a number, string, or (number, string) tuple. Assumes CSS pixels if units aren’t provided. See Units for details.
style

Dictionary of CSS property-value pairs.

Use the style property to control the text appearance. The following CSS properties are allowed:

  • alignment-baseline
  • baseline-shift
  • fill
  • fill-opacity
  • font-size
  • font-weight
  • opacity
  • stroke
  • stroke-opacity
  • stroke-width
  • text-anchor
  • -toyplot-anchor-shift

Note that when assigning to the style property, the properties you supply are merged with the existing properties.

text

The text to be displayed, or None.

class Axis.PerTickHelper(allowed)[source]

Bases: object

class TickProxy(tick, allowed)[source]

Bases: object

style
Axis.PerTickHelper.styles(values)[source]
class Axis.SpineHelper[source]

Bases: object

position
show
style

Dictionary of CSS property-value pairs.

Use the style property to control the appearance of the line. The following CSS properties are allowed:

  • opacity
  • stroke
  • stroke-dasharray
  • stroke-opacity
  • stroke-width

Note that when assigning to the style property, the properties you supply are merged with the existing properties.

class Axis.TickLabelsHelper(angle)[source]

Bases: object

angle
label
offset

Specifies the position relative to the axis. Increasing values of offset move the position further away from the axis, whether the location is “above” or “below”.

Getter:Returns the offset in CSS pixels.
Setter:Sets the offset using a number, string, or (number, string) tuple. Assumes CSS pixels if units aren’t provided. See Units for details.
show
style

Dictionary of CSS property-value pairs.

Use the style property to control the text appearance. The following CSS properties are allowed:

  • alignment-baseline
  • baseline-shift
  • fill
  • fill-opacity
  • font-size
  • font-weight
  • opacity
  • stroke
  • stroke-opacity
  • stroke-width
  • text-anchor
  • -toyplot-anchor-shift

Note that when assigning to the style property, the properties you supply are merged with the existing properties.

class Axis.TicksHelper(locator, angle)[source]

Bases: object

far

Specifies the distance from the axis, in the opposite direction as location.

labels
location

Controls the position of ticks (and labels) relative to the axis.

Allowed values are “above” (force labels to appear above the axis), “below” (the opposite), or None (use default, context-sensitive behavior).

locator
near

Specifies the distance from the axis, in the same direction as location.

show
style

Dictionary of CSS property-value pairs.

Use the style property to control the appearance of the line. The following CSS properties are allowed:

  • opacity
  • stroke
  • stroke-dasharray
  • stroke-opacity
  • stroke-width

Note that when assigning to the style property, the properties you supply are merged with the existing properties.

tick
Axis.domain

toyplot.coordinates.Axis.DomainHelper instance.

Axis.interactive

toyplot.coordinates.Axis.InteractiveHelper instance.

Axis.label

toyplot.coordinates.Axis.LabelHelper instance.

Axis.scale
Axis.show
Axis.spine

toyplot.coordinates.Axis.SpineHelper instance.

Axis.ticks

toyplot.coordinates.Axis.TicksHelper instance.

class toyplot.coordinates.Cartesian(xmin_range, xmax_range, ymin_range, ymax_range, aspect, xmin, xmax, ymin, ymax, show, xshow, yshow, label, xlabel, ylabel, xticklocator, yticklocator, xscale, yscale, padding, parent, xaxis=None, yaxis=None)[source]

Bases: object

Standard two-dimensional Cartesian coordinate system.

Do not create Cartesian instances directly. Use factory methods such as toyplot.canvas.Canvas.axes() instead.

class LabelHelper(text, style)[source]

Bases: object

style

Dictionary of CSS property-value pairs.

Use the style property to control the text appearance. The following CSS properties are allowed:

  • alignment-baseline
  • baseline-shift
  • fill
  • fill-opacity
  • font-size
  • font-weight
  • opacity
  • stroke
  • stroke-opacity
  • stroke-width
  • text-anchor
  • -toyplot-anchor-shift

Note that when assigning to the style property, the properties you supply are merged with the existing properties.

text

The text to be displayed, or None.

Cartesian.aspect

Control the mapping from domains to ranges.

By default, each axis maps its domain to its range separately, which is what is usually expected from a plot. Sometimes, both axes have the same domain. In this case, it is desirable that both axes are mapped to a consistent range to avoid “squashing” or “stretching” the data. To do so, set aspect to “fit-range”.

Cartesian.bars(a, b=None, c=None, along='x', baseline='stacked', color=None, opacity=1.0, title=None, style=None, filename=None)[source]

Add stacked bars to the axes.

This command generates one-or-more series of stacked bars. For convenience, you can call it with many different types of input. To generate a single series of \(M\) bars, pass an optional vector of \(M\) bar positions plus a vector of \(M\) bar magnitudes:

>>> axes.bars(magnitudes)
>>> axes.bars(centers, magnitudes)
>>> axes.bars(minpos, maxpos, magnitudes)

To generate \(N\) stacked series of \(M\) bars, pass an optional vector of \(M\) bar positions plus an \(M \times N\) matrix of bar magnitudes:

>>> axes.bars(magnitudes)
>>> axes.bars(centers, magnitudes)
>>> axes.bars(minpos, maxpos, magnitudes)

As a convenience for working with numpy.histogram(), you may pass a 2-tuple containing \(M\) counts and \(M+1\) bin edges:

>>> axes.bars((counts, edges))

Alternatively, you can generate \(N-1\) stacked series of \(M\) bars by passing an optional vector of \(M\) bar positions plus an \(M \times N\) matrix of bar boundaries:

>>> axes.bars(boundaries, baseline=None)
>>> axes.bars(centers, boundaries, baseline=None)
>>> axes.bars(minpos, maxpos, boundaries, baseline=None)
Parameters:
  • a, b, c (array-like series data.)
  • along (string, “x” or “y”, optional) – Specify “x” (the default) for vertical bars, or “y” for horizontal bars.
  • baseline (array-like, “stacked”, “symmetrical”, “wiggle”, or None)
  • color (array-like set of colors, optional) – Specify a single color for all bars, one color per series, or one color per bar. Color values can be explicit toyplot colors, or scalar values to be mapped to colors using the colormap or palette parameter.
  • opacity (array-like set of opacities, optional) – Specify a single opacity for all bars, one opacity per series, or one opacity per bar.
  • title (array-like set of strings, optional) – Specify a single title, one title per series, or one title per bar.
  • style (dict, optional) – Collection of CSS styles to be applied globally.
Returns:

bars

Return type:

toyplot.mark.BarBoundaries or toyplot.mark.BarMagnitudes

Cartesian.color_scale(colormap, label=None, tick_locator=None, width=10, padding=10)[source]

Add a color scale to the axes.

The color scale displays a mapping from scalar values to colors, for the given colormap. Note that the supplied colormap must have an explicitly defined domain (specified when the colormap was created), otherwise the mapping would be undefined.

Parameters:
  • colormap (toyplot.color.Map, required) – Colormap to be displayed.
  • label (string, optional) – Human-readable label placed below the axis.
  • ticklocator (toyplot.locator.TickLocator, optional) – Controls the placement and formatting of axis ticks and tick labels.
Returns:

axes

Return type:

toyplot.coordinates.Numberline

Cartesian.fill(a, b=None, c=None, along='x', baseline=None, color=None, opacity=1.0, title=None, style=None, annotation=False, filename=None)[source]

Fill multiple regions separated by curves.

Parameters:
  • a, b, c (array-like sets of coordinates) – If a, b, and c are provided, they specify the X coordinates, bottom coordinates, and top coordinates of the region respectively. If only a and b are provided, they specify the X coordinates and top coordinates, with the bottom coordinates lying on the X axis. If only a is provided, it specifies the top coordinates, with the bottom coordinates lying on the X axis and the X coordinates ranging from [0, N).
  • title (string, optional) – Human-readable title for the mark. The SVG / HTML backends render the title as a tooltip.
  • style (dict, optional) – Collection of CSS styles to apply to the mark. See toyplot.mark.FillBoundaries for a list of useful styles.
  • annotation (boolean, optional) – Set to True if this mark should be considered an annotation.
Returns:

mark

Return type:

toyplot.mark.FillBoundaries or toyplot.mark.FillMagnitudes

Cartesian.graph(a, b=None, c=None, olayout=None, layout=None, along='x', vlabel=None, vcoordinates=None, vcolor=None, vmarker='o', varea=None, vsize=None, vopacity=1.0, vtitle=None, vstyle=None, vlstyle=None, vlshow=True, ecolor=None, ewidth=1.0, eopacity=1.0, estyle=None)[source]

Add a graph plot to the axes.

Returns:plot
Return type:toyplot.mark.Graph
Cartesian.hlines(y, color=None, opacity=1.0, title=None, style=None, annotation=True)[source]

Add horizontal line(s) to the axes.

Horizontal lines are convenient because they’re guaranteed to fill the axes from left to right regardless of the axes size.

Parameters:
  • y (array-like set of Y coordinates) – One horizontal line will be drawn through each Y coordinate provided.
  • title (string, optional) – Human-readable title for the mark. The SVG / HTML backends render the title as a tooltip.
  • style (dict, optional) – Collection of CSS styles to apply to the mark. See toyplot.mark.AxisLines for a list of useful styles.
  • annotation (boolean, optional) – Set to True if this mark should be considered an annotation.
Returns:

hlines

Return type:

toyplot.mark.AxisLines

Cartesian.legend(entries, bounds=None, rect=None, corner=None, grid=None, gutter=50, style=None, label_style=None)[source]

Add a legend to the axes.

Parameters:
  • entries (sequence of entries to add to the legend Each entry to be) – displayed in the legend must be either a (label, mark) tuple or a (label, marker) tuple. Labels are human-readable text, markers are specified using the syntax described in Markers, and marks can be any instance of toyplot.mark.Mark.
  • bounds ((xmin, xmax, ymin, ymax) tuple, optional) – Use the bounds property to position / size the legend by specifying the position of each of its boundaries. The boundaries may be specified in absolute drawing units, or as a percentage of the axes width / height using strings that end with “%”.
  • rect ((x, y, width, height) tuple, optional) – Use the rect property to position / size the legend by specifying its upper-left-hand corner, width, and height. Each parameter may be specified in absolute drawing units, or as a percentage of the axes width / height using strings that end with “%”.
  • corner ((corner, width, height, inset) tuple, optional) – Use the corner property to position / size the legend by specifying its width and height, plus an inset from a corner of the axes. Allowed corner values are “top-left”, “top”, “top-right”, “right”, “bottom-right”, “bottom”, “bottom-left”, and “left”. The width and height may be specified in absolute drawing units, or as a percentage of the axes width / height using strings that end with “%”. The inset is specified in absolute drawing units.
  • grid ((rows, columns, index) tuple, or (rows, columns, i, j) tuple, or (rows, columns, i, rowspan, j, columnspan) tuple, optional) – Use the grid property to position / size the legend using a collection of grid cells filling the axes. Specify the number of rows and columns in the grid, then specify either a zero-based cell index (which runs in left-ot-right, top-to-bottom order), a pair of i, j cell coordinates, or a set of i, column-span, j, row-span coordinates so the legend can cover more than one cell.
  • gutter (size of the gutter around grid cells, optional) – Specifies the amount of empty space to leave between grid cells When using the grid parameter to position the legend.
  • style (dict, optional)
Returns:

legend

Return type:

toyplot.mark.Legend

Cartesian.padding

Control the default distance between axis spines and data.

By default, axis spines are offset slightly from the data, to avoid visual clutter and overlap. Use padding to change this offset. The default units are CSS pixels, but you may specify the padding using any Units you like.

Cartesian.plot(a, b=None, along='x', color=None, stroke_width=2.0, opacity=1.0, title=None, marker=None, area=None, size=None, mfill=None, mopacity=1.0, mtitle=None, style=None, mstyle=None, mlstyle=None, filename=None)[source]

Add bivariate line plots to the axes.

Parameters:
  • a, b (array-like sets of coordinates) – If a and b are provided, they specify the first and second coordinates respectively of each point in the plot. If only a is provided, it provides second coordinates, and the first coordinates will range from [0, N).
  • along (string, optional) – Controls the mapping from coordinates to axes. When set to “x” (the default), first and second coordinates map to the X and Y axes. When set to “y”, the coordinates are reversed.
  • color (array-like, optional) – Overrides the default per-series colors provided by the axis palette. Specify one color, or one-color-per-series. Colors may be CSS colors, toyplot colors, or scalar values that will be mapped to colors using colormap or palette.
  • stroke_width (array-like, optional) – Overrides the default stroke width of the plots. Specify one width in drawing units, or one-width-per-series.
  • stroke_opacity (array-like, optional) – Overrides the default opacity of the plots. Specify one opacity, or one-opacity-per-series.
  • marker (array-like, optional) – Allows markers to be rendered for each plot datum. Specify one marker, one-marker-per-series, or one-marker-per-datum. Markers can use the string marker type as a shortcut, or a full marker specification.
  • size (array-like, optional) – Controls marker sizes. Specify one size, one-size-per-series, or one-size-per-datum.
  • fill (array-like, optional) – Override the fill color for markers, which defaults to the per-series color specified by color. Specify one color, one-color-per-series, or one-color-per-datum. Colors may be CSS colors, toyplot colors, or scalar values that will be mapped to colors using fill_colormap or fill_palette.
  • opacity (array-like, optional) – Overrides the default opacity of the markers. Specify one opacity, one-opacity-per-series, or one-opacity-per-datum.
  • title (array-like, optional) – Human-readable title for the data series. The SVG / HTML backends render the title using tooltips. Specify one title or one-title-per-series.
  • style (dict, optional) – Collection of CSS styles applied to all plots.
  • mstyle (dict, optional) – Collection of CSS styles applied to all markers.
  • mlstyle (dict, optional) – Collection of CSS styles applied to all marker labels.
Returns:

mark

Return type:

toyplot.mark.Plot

Cartesian.rects(a, b, c, d, along='x', color=None, opacity=1.0, title=None, style=None, filename=None)[source]
Cartesian.scatterplot(a, b=None, along='x', color=None, marker='o', area=None, size=None, opacity=1.0, title=None, style=None, mstyle=None, mlstyle=None, filename=None)[source]

Add a bivariate plot to the axes.

Parameters:
  • a, b (array-like sets of coordinates) – If a and b are provided, they specify the X coordinates and Y coordinates of each point in the plot. If only a is provided, it specifies the Y coordinates, and the X coordinates will range from [0, N).
  • title (string, optional) – Human-readable title for the mark. The SVG / HTML backends render the title as a tooltip.
  • style (dict, optional) – Collection of CSS styles to apply across all datums.
Returns:

plot

Return type:

toyplot.mark.Plot

Cartesian.share(axis='x', xmin=None, xmax=None, ymin=None, ymax=None, xlabel=None, ylabel=None, xticklocator=None, yticklocator=None, xscale='linear', yscale='linear')[source]

Create a Cartesian coordinate system with a shared axis.

Parameters:
  • axis (string, optional) – The axis that will be shared. Allowed values are “x” and “y”.
  • xmin, xmax, ymin, ymax (float, optional) – Used to explicitly override the axis domain (normally, the domain is implicitly defined by any marks added to the axes).
  • xlabel, ylabel (string, optional) – Human-readable axis labels.
  • xticklocator, yticklocator (toyplot.locator.TickLocator, optional) – Controls the placement and formatting of axis ticks and tick labels.
  • xscale, yscale (“linear”, “log”, “log10”, “log2”, or a (“log”, <base>) tuple, optional) – Specifies the mapping from data to canvas coordinates along an axis.
Returns:

axes

Return type:

toyplot.coordinates.Cartesian

Cartesian.show

Control axis visibility.

Use the show property to hide all visible parts of the axes: labels, spines, ticks, tick labels, etc. Note that this does not affect visibility of the axes contents, just the axes themselves.

Cartesian.text(a, b, text, angle=0, color=None, opacity=1.0, title=None, style=None, filename=None, annotation=True)[source]

Add text to the axes.

Parameters:
  • a, b (float) – Coordinates of the text anchor.
  • text (string) – The text to be displayed.
  • title (string, optional) – Human-readable title for the mark. The SVG / HTML backends render the title as a tooltip.
  • style (dict, optional) – Collection of CSS styles to apply to the mark. See toyplot.mark.Text for a list of useful styles.
  • annotation (boolean, optional) – Set to True if this mark should be considered an annotation.
Returns:

text

Return type:

toyplot.mark.Text

Cartesian.vlines(x, color=None, opacity=1.0, title=None, style=None, annotation=True)[source]

Add vertical line(s) to the axes.

Vertical lines are convenient because they’re guaranteed to fill the axes from top to bottom regardless of the axes size.

Parameters:
  • x (array-like set of X coordinates) – One vertical line will be drawn through each X coordinate provided.
  • title (string, optional) – Human-readable title for the mark. The SVG / HTML backends render the title as a tooltip.
  • style (dict, optional) – Collection of CSS styles to apply to the mark. See toyplot.mark.AxisLines for a list of useful styles.
  • annotation (boolean, optional) – Set to True if this mark should be considered an annotation.
Returns:

mark

Return type:

toyplot.mark.AxisLines

Cartesian.xmax_range
Cartesian.xmin_range
Cartesian.ymax_range
Cartesian.ymin_range
class toyplot.coordinates.Numberline(x1, y1, x2, y2, padding, spacing, min, max, show, label, ticklocator, scale, parent)[source]

Bases: object

Standard one-dimensional coordinate system / numberline.

Do not create Numberline instances directly. Use factory methods such as toyplot.canvas.Canvas.numberline() instead.

axis

toyplot.coordinates.Axis instance that provides the numberline coordinate system.

colormap(colormap, offset=None, width=10, style=None)[source]
padding

Control the default distance between the axis spine and data.

By default, the axis spine is offset slightly from the data, to avoid visual clutter and overlap. Use padding to change this offset. The default units are CSS pixels, but you may specify the padding using any Units you like.

scatterplot(coordinates, offset=None, color=None, marker='o', area=None, size=None, opacity=1.0, title=None, style=None, mstyle=None, mlstyle=None, filename=None)[source]

Add a univariate plot to the axes.

Parameters:
  • coordinate (array-like one-dimensional coordinates)
  • title (string, optional) – Human-readable title for the mark. The SVG / HTML backends render the title as a tooltip.
  • style (dict, optional) – Collection of CSS styles to apply across all datums.
Returns:

plot

Return type:

toyplot.mark.Plot

show

Control axis visibility.

Use the show property to hide all visible parts of the axis: label, spine, ticks, tick labels, etc. Note that this does not affect visibility of the numberline contents, just the axis.

spacing

Control the default distance between data added to the numberline.

The default units are CSS pixels, but you may specify the spacing using any Units you like.

class toyplot.coordinates.Table(xmin_range, xmax_range, ymin_range, ymax_range, rows, columns, trows, brows, lcolumns, rcolumns, label, parent, filename)[source]

Bases: object

Row and column-based table coordinate system.

Do not create Table instances directly. Use factory methods such as toyplot.canvas.Canvas.table() instead.

class CellBarMark(table, axes, baseline, color, filename, opacity, padding, series, style, title, width)[source]

Bases: toyplot.coordinates.CellMark

class Table.CellMark(table, axes, series)[source]

Bases: object

class Table.CellPlotMark(table, axes, area, color, filename, marker, mfill, mlstyle, mopacity, mstyle, mtitle, opacity, series, size, stroke_width, style, title)[source]

Bases: toyplot.coordinates.CellMark

class Table.CellReference(table, selection)[source]

Bases: object

align
angle
axes(xmin=None, xmax=None, ymin=None, ymax=None, aspect=None, show=True, xshow=False, yshow=False, label=None, xlabel=None, ylabel=None, xticklocator=None, yticklocator=None, xscale='linear', yscale='linear', padding=3, cell_padding=3)[source]
cartesian(xmin=None, xmax=None, ymin=None, ymax=None, aspect=None, show=True, xshow=False, yshow=False, label=None, xlabel=None, ylabel=None, xticklocator=None, yticklocator=None, xscale='linear', yscale='linear', padding=3, cell_padding=3)[source]
data
format
height
lstyle
merge()[source]
show
style
title
width
class Table.ColumnCellReference(table, selection)[source]

Bases: toyplot.coordinates.CellReference

delete()[source]
class Table.DistanceArrayReference(array)[source]

Bases: object

class Table.EmbeddedCartesian(table, *args, **kwargs)[source]

Bases: toyplot.coordinates.Cartesian

cell_bars(baseline='stacked', color=None, filename=None, opacity=1.0, padding=0, series='columns', style=None, title=None, width=0.5)[source]
cell_plot(area=None, color=None, filename=None, marker=None, mfill=None, mlstyle=None, mopacity=1.0, mstyle=None, mtitle=None, opacity=1.0, series='columns', size=None, stroke_width=2.0, style=None, title=None)[source]
class Table.GapReference(row_gaps, column_gaps)[source]

Bases: object

columns
rows
class Table.GridReference(table, hlines, vlines)[source]

Bases: object

hlines
separation
style
vlines
class Table.Label(text, style)[source]

Bases: object

style

Dictionary of CSS property-value pairs.

Use the style property to control the text appearance. The following CSS properties are allowed:

  • alignment-baseline
  • baseline-shift
  • fill
  • fill-opacity
  • font-size
  • font-weight
  • opacity
  • stroke
  • stroke-opacity
  • stroke-width
  • text-anchor
  • -toyplot-anchor-shift

Note that when assigning to the style property, the properties you supply are merged with the existing properties.

text

The text to be displayed, or None.

class Table.Region(table, row_begin, row_end, column_begin, column_end)[source]

Bases: object

class CellAccessor(region)[source]

Bases: object

class Table.Region.ColumnAccessor(region)[source]

Bases: object

insert(before=None, after=None)[source]
class Table.Region.RowAccessor(region)[source]

Bases: object

insert(before=None, after=None)[source]
Table.Region.cell
Table.Region.cells
Table.Region.column
Table.Region.gaps
Table.Region.grid
Table.Region.row
Table.Region.shape
class Table.RowCellReference(table, selection)[source]

Bases: toyplot.coordinates.CellReference

delete()[source]
Table.body
Table.bottom
Table.cells
Table.label
Table.left
Table.right
Table.shape
Table.top