Plotly FigureWidget Overview in Python/v3

Introduction to the new Plotly FigureWidget

See our Version 4 Migration Guide for information about how to upgrade.

New to Plotly?¶

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()
f


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 = f.data[0]
scatter.y = [3, 1, 4, 3]

In [9]:
# update bar data
bar = f.data[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
py.init_notebook_mode()

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'])
data=[trace]
layout = go.Layout(title='Activity Heatmap')

f2 = go.FigureWidget(data,layout)

# two different ways to view f2
py.iplot(f2)
f2