The Plotly pane displays Plotly plots within a Panel application. It enhances the speed of plot updates by using binary serialization for array data contained in the Plotly object.
Please remember that to use the Plotly pane in a Jupyter notebook, you must activate the Panel extension and include "plotly"
as an argument. This step ensures that plotly.js is properly set up.
Parameters:
For details on other options for customizing the component see the general layout and styling how-to guides as well as the specific Style Plotly Plots how-to guide.
Core
object
(object): The PlotlyFigure
or dictionary object being displayed.config
(dict): Additional configuration of the plot. See Plotly configuration options.
Update in Place
link_figure
(bool, default: True): Update the displayed Plotly figure when the PlotlyFigure
is modified in place.
Events
click_data
(dict): Click event data fromplotly_click
event.clickannotation_data
(dict): Clickannotation event data fromplotly_clickannotation
event.hover_data
(dict): Hover event data fromplotly_hover
andplotly_unhover
events.relayout_data
(dict): Relayout event data fromplotly_relayout
eventrestyle_data
(dict): Restyle event data fromplotly_restyle
eventselected_data
(dict): Selected event data fromplotly_selected
andplotly_deselect
events.viewport
(dict): Current viewport state, i.e. the x- and y-axis limits of the displayed plot. Updated onplotly_relayout
,plotly_relayouting
andplotly_restyle
events.viewport_update_policy
(str, default = 'mouseup'): Policy by which the viewport parameter is updated during user interactionsmouseup
: updates are synchronized when mouse button is released after panningcontinuous
: updates are synchronized continually while panningthrottle
: updates are synchronized while panning, at intervals determined by the viewport_update_throttle parameter
viewport_update_throttle
(int, default = 200, bounds = (0, None)): Time interval in milliseconds at which viewport updates are synchronized when viewport_update_policy is "throttle".
As with most other types Panel
will automatically convert a Plotly Figure
to a Plotly
pane if it is passed to the pn.panel
function or a Panel layout, but a Plotly
pane can also be constructed directly using the pn.pane.Plotly
constructor:
Basic Example
Lets create a basic example
Once created Plotly
pane can be updated by assigning a new figure object
Lets reset the Plotly pane
Layout Example
The Plotly
pane supports layouts and subplots of arbitrary complexity, allowing even deeply nested Plotly figures to be displayed:
Responsive Plots
Plotly plots can be made responsive using the autosize
option on a Plotly layout and a responsive sizing_mode
argument to the Plotly
pane:
Plot Configuration
You can set the Plotly configuration options via the config
parameter. Lets try to configure scrollZoom
:
Try scrolling with the mouse over the plot!
Patching
Instead of updating the entire Figure you can efficiently patch traces or the layout if you use a dictionary instead of a Plotly Figure.
Note patching will only be efficient if the Figure
is defined as a dictionary, since Plotly will make copies of the traces, which means that modifying them in place has no effect. Modifying an array will send just the array using a binary protocol, leading to fast and efficient updates.
Similarly, modifying the plot layout
will only modify the layout, leaving the traces unaffected.
Lets reset the Plotly pane
Streaming
You can stream updates by replacing the entire Figure object. To stream efficiently though you should use patching technique described above.
You can stream periodically using pn.state.add_periodic_callback
.
You can also stream via a generator or async generator function:
Update in Place
An alternative to updating the figure dictionary is updating the Plotly Figure
in place, i.e. via its attributes and methods.
This enables you to use the Plotly Figure
in the same way as you would have been using the Plotly FigureWidget
.
If you for some reason want to disable in place updates, you can set link_figure=False
when you create the Plotly
pane. You cannot change this when the pane has been created.
Events
The Plotly pane enables you to bind to most of the click, hover, selection and other events described in Plotly Event Handlers.
Simple Event Example
Event Inspection
The be able to work with the events its a good idea to inspect them. You can do that by printing them or including them in your visualization.
Lets display them.
In the plot above, try hovering, clicking, selecting and changing the viewport by panning. Watch how the parameter values just above changes.
Parent-Child Views
A common technique for exploring higher-dimensional datasets is the use of Parent-Child views. This approach allows you to employ a top-down method to initially exing thehree most important dimensions in the parent plot. You can then select a subset of the data points and examine them in greater detail and across additional dimensions.
Let's create a plot where Box or Lasso selections in the parent plot update a child plot. We will also customize the action bars using the config
parameter.
Controls
The Plotly
pane exposes a number of options which can be changed from both Python and Javascript try out the effect of these parameters interactively: