Plotly FigureWidget Overview in Python/v3

Introduction to the new Plotly FigureWidget

Note: this page is part of the documentation for version 3 of, which is not the most recent version.
See our Version 4 Migration Guide for information about how to upgrade.
The version 4 version of this page is here.

New to Plotly?

Plotly's Python library is free and open source! Get started by downloading the client and reading the primer.
You can set up Plotly to work in online or offline mode, or in jupyter notebooks.
We also have a quick-reference cheatsheet (new!) to help you get started!

Create a Simple FigureWidget

Create an empty FigureWidget and then view it.

In [ ]:
import plotly.graph_objs as go

f = go.FigureWidget()

Add traces or update the layout and then watch the output above update in real time.

In [ ]:
f.add_scatter(y=[2, 1, 4, 3])
In [ ]:
f.add_bar(y=[1, 4, 3, 2])
In [6]:
f.layout.title = 'Hello FigureWidget'

Update the Data and the Layout

In [8]:
# update scatter data
scatter =[0]
scatter.y = [3, 1, 4, 3]
In [9]:
# update bar data
bar =[1]
bar.y = [5, 3, 2, 8]
In [10]:
f.layout.title = 'This is a new title'

Construct a FigureWidget With Data and Layout Arguments

We can construct a FigureWidget with the same arguments that py.iplot and py.plot use in order to convert an example of the latter using go.FigureWidget and we can also use a FigureWidget in the argument of iplot.

Using Data and Layout:

In [11]:
import plotly.offline as py

trace = go.Heatmap(z=[[1, 20, 30, 50, 1], [20, 1, 60, 80, 30], [30, 60, 1, -10, 20]],
                   x=['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday'],
                   y=['Morning', 'Afternoon', 'Evening'])
layout = go.Layout(title='Activity Heatmap')

f2 = go.FigureWidget(data,layout)

# two different ways to view f2