.. _interaction:
A key goal for the Toyplot team is to explore interactive features for plots, making them truly useful and embeddable, so that they become a ubiquitous part of every data graphic user's experience. The following examples of interaction are just scratching the surface of what we have planned for Toyplot:
Most of the visualization types in Toyplot accept a title
parameter, allowing you to specify per-series or per-datum titles for a figure. With Toyplot's preferred embeddable HTML output, those titles are displayed via a popup when hovering over the data. For example, the following figure has a global title "Employee Schedule", which you should see as a popup when you hover the mouse over any of the bars:
In [1]:
import numpy
numpy.random.seed(1234)
start = numpy.random.normal(loc=8, scale=1, size=20)
end = numpy.random.normal(loc=16, scale=1, size=20)
boundaries = numpy.column_stack((start, end))
title = "Employee Schedule"
In [2]:
import toyplot
toyplot.bars(boundaries, baseline=None, title=title, width=500, height=300);
If your plot includes multiple series, you can assign a per-series title instead. Hover the mouse over both series in the following plot to see "Morning Schedule" and "Afternoon Schedule":
In [3]:
lunch = numpy.random.normal(loc=12, scale=0.5, size=20)
boundaries = numpy.column_stack((start, lunch, end))
title = ["Morning Schedule", "Afternoon Schedule"]
toyplot.bars(boundaries, baseline=None, title=title, width=500, height=300);
Finally, you can assign a title for every datum:
In [4]:
title = numpy.column_stack((
["Employee %s Morning" % i for i in range(20)],
["Employee %s Afternoon" % i for i in range(20)]
))
toyplot.bars(boundaries, baseline=None, title=title, width=500, height=300);
Of course, the title attribute works with all types of visualizations.
As you mouse over the above figures, you should also see the interactive mouse coordinates in the upper-right-hand corner of the axes. These coordinates show the domain values where the crosshair mouse cursor is located.
If you wish to disable the mouse coordinates altogether, you can do so using the axes:
In [5]:
canvas, axes, mark = toyplot.bars(boundaries, baseline=None, title=title, width=500, height=300)
axes.coordinates.show = False
Now when you mouse over the axes, the coordinates are no longer there.
If you right-click the mouse over any of the above plots, a small popup menu will appear, giving you the option to "Save as .csv". If you choose that option, the raw data from the plot will be extracted in CSV format and you can save it.
Note that different browsers, browser versions, and platforms will behave differently when extracting the file:
File > Save As
.Note that, on the browsers that support it, the default filename for the saved data is toyplot.csv
. You can override this default on a per-data-table basis by specifying the filename when you create your figure. For example, when exporting data from the following figure (again, for browsers that support setting a default filename), the filename will default to employee-schedules.csv
:
In [6]:
canvas, axes, mark = toyplot.bars(boundaries, baseline=None, filename="employee-schedules", title=title, width=500, height=300)
Note that the filename you specify should not include a file extension, as the file extension is added for you (and other file formats may become available in the future).