You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Plot planets' distance from sun, density, and gravity with bubble size based on planet size
89
89
90
90
```python
@@ -125,6 +125,7 @@ fig.show()
125
125
```
126
126
127
127
#### Edit the Colorbar
128
+
128
129
Plot planets' distance from sun, density, and gravity with bubble size based on planet size
129
130
130
131
```python
@@ -165,5 +166,5 @@ fig.show()
165
166
```
166
167
167
168
#### Reference
168
-
See https://plot.ly/python/reference/#scatter3d and https://plot.ly/python/reference/#scatter-marker-sizeref <br>for more information and chart attribute options!
169
169
170
+
See https://plot.ly/python/reference/#scatter3d and https://plot.ly/python/reference/#scatter-marker-sizeref <br>for more information and chart attribute options!
[Dash](https://plot.ly/products/dash/) is an Open Source Python library which can help you convert plotly figures into a reactive, web-based application. Below is a simple example of a dashboard created using Dash. Its [source code](https://github.com/plotly/simple-example-chart-apps/tree/master/dash-3dscatterplot) can easily be deployed to a PaaS.
Copy file name to clipboardExpand all lines: doc/python/animations.md
+17-10
Original file line number
Diff line number
Diff line change
@@ -5,7 +5,7 @@ jupyter:
5
5
text_representation:
6
6
extension: .md
7
7
format_name: markdown
8
-
format_version: '1.1'
8
+
format_version: "1.1"
9
9
jupytext_version: 1.1.6
10
10
kernelspec:
11
11
display_name: Python 3
@@ -24,28 +24,29 @@ jupyter:
24
24
---
25
25
26
26
#### Animated figures with Plotly Express
27
+
27
28
Several Plotly Express functions support the creation of animated figures through the `animation_frame` and `animation_group` arguments.
28
29
29
30
Here is an example of an animated scatter plot creating using Plotly Express. Note that you should always fix the `x_range` and `y_range` to ensure that your data remains visible throughout the animation.
The remainder of this section describes the low-level API for constructing animated figures manually.
56
57
57
-
58
58
#### Frames
59
+
59
60
Along with `data` and `layout`, `frames` can be added as a key in a figure object. The `frames` key points to a list of figures, each of which will be cycled through when animation is triggered.
60
61
61
62
<!-- #region -->
63
+
62
64
#### Adding Control Buttons to Animations
65
+
63
66
You can add play and pause buttons to control your animated charts by adding an `updatemenus` array to the `layout` of your `figure`. More information on style and placement of the buttons is available in Plotly's [`updatemenus` reference](https://plot.ly/python/reference/#layout-updatemenus).
64
67
<br>
65
68
The buttons are defined as follows:
69
+
66
70
```
67
71
"updatemenus": [{"type": "buttons",
68
72
"buttons": [{"label": "Your Label",
69
73
"method": "animate",
70
74
"args": [See Below]}]}]
71
75
```
76
+
72
77
<!-- #endregion -->
73
78
74
79
#### Defining Button Arguments
80
+
75
81
-`None`: Setting `"args"` to undefined (i.e. `"args": [None]`) will create a simple play button that will animate all frames.
76
82
- string: Animate all frames with group `"<some string>"`. This is a way of scoping the animations in case you would prefer to animate without explicitly enumerating all frames.
77
83
-`["frame1", "frame2", ...]`: Animate a sequence of named frames.
78
84
-`[{data: [], layout: {}, traces: []}, {...}]`: Nearly identical to animating named frames; though this variant lets you inline data instead of adding it as named frames. This can be useful for interaction where it's undesirable to add and manage named frames for ephemeral changes.
79
85
-`[null]`: A simple way to create a pause button (requires `mode: "immediate"`). This argument dumps the currently queued frames (`mode: "immediate"`), and then animates an empty sequence of frames (`[null]`).
80
86
- <b>Please Note:</b> We <b>do not</b> recommend using: `[ ]`. This syntax may cause confusion because it looks indistinguishable from a "pause button", but nested properties have logic that treats empty arrays as entirely removable, so it will function as a play button.<br><br>
81
-
Refer to the examples below to see the buttons in action!
82
-
87
+
Refer to the examples below to see the buttons in action!
83
88
84
89
#### Simple Play Button
85
90
@@ -224,6 +229,7 @@ fig.show()
224
229
```
225
230
226
231
#### Using a Slider and Buttons
232
+
227
233
The following example uses the well known [Gapminder dataset](https://www.gapminder.org/tag/gdp-per-capita/) to exemplify animation capabilities. This bubble chart animation shows the change in 'GDP per Capita' against the 'Life Expectancy' of several countries from the year 1952 to 2007, colored by their respective continent and sized by population.
228
234
229
235
This is also an example of building up the structure of a figure as a Python dictionary, and then constructing a graph object figure from that dictionary.
@@ -378,9 +384,10 @@ fig.show()
378
384
```
379
385
380
386
#### Important Notes
381
-
- Defining `redraw`: Setting `redraw: false` is an optimization for scatter plots so that animate just makes changes without redrawing the whole plot. For other plot types, such as contour plots, every frame <b>must</b> be a total plot redraw, i.e. `redraw: true`.
382
387
388
+
- Defining `redraw`: Setting `redraw: false` is an optimization for scatter plots so that animate just makes changes without redrawing the whole plot. For other plot types, such as contour plots, every frame <b>must</b> be a total plot redraw, i.e. `redraw: true`.
383
389
384
390
#### Reference
391
+
385
392
For additional information and attributes for creating bubble charts in Plotly see: https://plot.ly/python/bubble-charts/.
386
393
For more documentation on creating animations with Plotly, see https://plot.ly/python/#animations.
0 commit comments