{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### New to Plotly?\n",
"Plotly's Python library is free and open source! [Get started](https://plotly.com/python/getting-started/) by downloading the client and [reading the primer](https://plotly.com/python/getting-started/).\n",
"
You can set up Plotly to work in [online](https://plotly.com/python/getting-started/#initialization-for-online-plotting) or [offline](https://plotly.com/python/getting-started/#initialization-for-offline-plotting) mode, or in [jupyter notebooks](https://plotly.com/python/getting-started/#start-plotting-online).\n",
"
We also have a quick-reference [cheatsheet](https://images.plot.ly/plotly-documentation/images/python_cheat_sheet.pdf) (new!) to help you get started!"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Create a Simple FigureWidget\n",
"Create an empty FigureWidget and then view it."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import plotly.graph_objs as go\n",
"\n",
"f = go.FigureWidget()\n",
"f"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"
"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Add traces or update the layout and then watch the output above update in real time."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"f.add_scatter(y=[2, 1, 4, 3])"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"f.add_bar(y=[1, 4, 3, 2])"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"f.layout.title = 'Hello FigureWidget'"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"
"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Update the Data and the Layout"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
"# update scatter data\n",
"scatter = f.data[0]\n",
"scatter.y = [3, 1, 4, 3]"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
"# update bar data\n",
"bar = f.data[1]\n",
"bar.y = [5, 3, 2, 8]"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [],
"source": [
"f.layout.title = 'This is a new title'"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Construct a FigureWidget With Data and Layout Arguments"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"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."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Using *Data* and *Layout*:"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
""
],
"text/vnd.plotly.v1+html": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.plotly.v1+json": {
"data": [
{
"type": "heatmap",
"uid": "3989468a-a573-11e8-85a9-9c4e36a18f28",
"x": [
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday"
],
"y": [
"Morning",
"Afternoon",
"Evening"
],
"z": [
[
1,
20,
30,
50,
1
],
[
20,
1,
60,
80,
30
],
[
30,
60,
1,
-10,
20
]
],
"zauto": true,
"zmax": 80,
"zmin": -10
}
],
"layout": {
"autosize": true,
"title": "Activity Heatmap",
"xaxis": {
"autorange": true,
"range": [
-0.5,
4.5
],
"type": "category"
},
"yaxis": {
"autorange": true,
"range": [
-0.5,
2.5
],
"type": "category"
}
}
},
"text/html": [
"