Overview
scripton.lyra
is a plotting toolkit based on the Plotly JavaScript library. Here's a quick example:
Try running that snippet in Scripton (the Scratchpad might be handy here), and you should see an interactive plot pop up in the visualizations tab.
lyra.plot
As shown in the example above, the plot
function is used for creating plots. Its signature is:
The
traces
positional arguments represent data to be plotted on a single figure. Each trace is a single dictionary.# This creates a single figure containing two line plots plot( { 'x': x, 'y': np.sin(x), 'name' : 'sin' }, { 'x': x, 'y': np.cos(x), 'name' : 'cos' } )The
plot
function is not limited to just line plots (which is just the default). For instance, you can use it to create a histogram:plot( { 'x': np.random.randn(1000), 'type': 'histogram' } )The optional
key
keyword argument can be used to update an existing figure instead of creating a new one.# Display an animated version of the plot by updating # the same figure in a loop. for t in range(1000): plot( { 'x': x, 'y': np.cos(x + t / 10) }, # Using a fixed key here causes the same figure to be updated. key='oscillator' ) time.sleep(0.01)Optional keyword arguments can be used to control various attributes of the plot like its layout:
plot( {'x': x, 'y': np.sin(x), 'name': 'sin'}, {'x': x, 'y': np.cos(x), 'name': 'cos', 'xaxis': 'x2', 'yaxis': 'y2'}, grid={'rows': 2, 'columns': 1, 'pattern': 'independent'} )
Pandas Support
While the examples above use NumPy arrays, you can also pass in Pandas Series
instances as well.