Skip to content

standardize on df variable name #2007

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions doc/python/3d-bubble-charts.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ jupyter:
text_representation:
extension: .md
format_name: markdown
format_version: '1.1'
format_version: "1.1"
jupytext_version: 1.2.3
kernelspec:
display_name: Python 3
Expand All @@ -22,7 +22,8 @@ jupyter:
pygments_lexer: ipython3
version: 3.7.3
plotly:
description: How to make 3D Bubble Charts in Python with Plotly. Three examples
description:
How to make 3D Bubble Charts in Python with Plotly. Three examples
of 3D Bubble Charts.
display_as: 3d_charts
language: python
Expand All @@ -39,15 +40,13 @@ jupyter:
```python
import plotly.express as px
import numpy as np
gapminder = px.data.gapminder()
#gapminder.columns
fig = px.scatter_3d(gapminder, x='year', y='continent', z='pop', size='gdpPercap', color='lifeExp',
df = px.data.gapminder()
fig = px.scatter_3d(df, x='year', y='continent', z='pop', size='gdpPercap', color='lifeExp',
hover_data=['country'])
fig.update_layout(scene_zaxis_type="log")
fig.show()
```


#### Simple Bubble Chart

```python
Expand Down Expand Up @@ -85,6 +84,7 @@ fig.show()
```

#### Bubble Chart Sized by a Variable

Plot planets' distance from sun, density, and gravity with bubble size based on planet size

```python
Expand Down Expand Up @@ -125,6 +125,7 @@ fig.show()
```

#### Edit the Colorbar

Plot planets' distance from sun, density, and gravity with bubble size based on planet size

```python
Expand Down Expand Up @@ -165,5 +166,5 @@ fig.show()
```

#### Reference
See https://plot.ly/python/reference/#scatter3d and https://plot.ly/python/reference/#scatter-marker-sizeref <br>for more information and chart attribute options!

See https://plot.ly/python/reference/#scatter3d and https://plot.ly/python/reference/#scatter-marker-sizeref <br>for more information and chart attribute options!
13 changes: 6 additions & 7 deletions doc/python/3d-line-plots.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ jupyter:
text_representation:
extension: .md
format_name: markdown
format_version: '1.1'
format_version: "1.1"
jupytext_version: 1.2.3
kernelspec:
display_name: Python 3
Expand Down Expand Up @@ -38,20 +38,19 @@ jupyter:
```python
import plotly.express as px
import plotly.express as px
gapminder = px.data.gapminder().query("country=='Brazil'")
fig = px.line_3d(gapminder, x="gdpPercap", y="pop", z="year")
df = px.data.gapminder().query("country=='Brazil'")
fig = px.line_3d(df, x="gdpPercap", y="pop", z="year")
fig.show()
```

```python
import plotly.express as px
import plotly.express as px
gapminder = px.data.gapminder().query("continent=='Europe'")
fig = px.line_3d(gapminder, x="gdpPercap", y="pop", z="year", color='country')
df = px.data.gapminder().query("continent=='Europe'")
fig = px.line_3d(df, x="gdpPercap", y="pop", z="year", color='country')
fig.show()
```


#### 3D Line Plot of Brownian Motion

Here we represent a trajectory in 3D.
Expand Down Expand Up @@ -120,5 +119,5 @@ fig.show()
```

#### Reference
See https://plot.ly/python/reference/#scatter3d-marker-line for more information and chart attribute options!

See https://plot.ly/python/reference/#scatter3d-marker-line for more information and chart attribute options!
16 changes: 8 additions & 8 deletions doc/python/3d-scatter-plots.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ jupyter:
text_representation:
extension: .md
format_name: markdown
format_version: '1.1'
format_version: "1.1"
jupytext_version: 1.1.1
kernelspec:
display_name: Python 3
Expand Down Expand Up @@ -41,8 +41,8 @@ Like the [2D scatter plot](https://plot.ly/python/line-and-scatter/) `px.scatter

```python
import plotly.express as px
iris = px.data.iris()
fig = px.scatter_3d(iris, x='sepal_length', y='sepal_width', z='petal_width',
df = px.data.iris()
fig = px.scatter_3d(df, x='sepal_length', y='sepal_width', z='petal_width',
color='species')
fig.show()
```
Expand All @@ -51,8 +51,8 @@ A 4th dimension of the data can be represented thanks to the color of the marker

```python
import plotly.express as px
iris = px.data.iris()
fig = px.scatter_3d(iris, x='sepal_length', y='sepal_width', z='petal_width',
df = px.data.iris()
fig = px.scatter_3d(df, x='sepal_length', y='sepal_width', z='petal_width',
color='petal_length', symbol='species')
fig.show()
```
Expand All @@ -63,8 +63,8 @@ It is possible to customize the style of the figure through the parameters of `p

```python
import plotly.express as px
iris = px.data.iris()
fig = px.scatter_3d(iris, x='sepal_length', y='sepal_width', z='petal_width',
df = px.data.iris()
fig = px.scatter_3d(df, x='sepal_length', y='sepal_width', z='petal_width',
color='petal_length', size='petal_length', size_max=18,
symbol='species', opacity=0.7)

Expand Down Expand Up @@ -122,7 +122,6 @@ fig.show()

### Dash App


[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.

```python
Expand All @@ -136,4 +135,5 @@ IFrame(src= "https://dash-simple-apps.plotly.host/dash-3dscatterplot/code", widt
```

#### Reference

See https://plot.ly/python/reference/#scatter3d for more information and chart attribute options!
27 changes: 17 additions & 10 deletions doc/python/animations.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ jupyter:
text_representation:
extension: .md
format_name: markdown
format_version: '1.1'
format_version: "1.1"
jupytext_version: 1.1.6
kernelspec:
display_name: Python 3
Expand All @@ -24,28 +24,29 @@ jupyter:
---

#### Animated figures with Plotly Express

Several Plotly Express functions support the creation of animated figures through the `animation_frame` and `animation_group` arguments.

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.

```python
import plotly.express as px
gapminder = px.data.gapminder()
px.scatter(gapminder, x="gdpPercap", y="lifeExp", animation_frame="year", animation_group="country",
df = px.data.gapminder()
px.scatter(df, x="gdpPercap", y="lifeExp", animation_frame="year", animation_group="country",
size="pop", color="continent", hover_name="country",
log_x=True, size_max=55, range_x=[100,100000], range_y=[25,90])
```

#### Animated Bar Charts with Plotly Express

Note that you should always fix the `y_range` to ensure that your data remains visible throughout the animation.
Note that you should always fix the `y_range` to ensure that your data remains visible throughout the animation.

```python
import plotly.express as px

gapminder = px.data.gapminder()
df = px.data.gapminder()

fig = px.bar(gapminder, x="continent", y="pop", color="continent",
fig = px.bar(df, x="continent", y="pop", color="continent",
animation_frame="year", animation_group="country", range_y=[0,4000000000])
fig.show()
```
Expand All @@ -54,32 +55,36 @@ fig.show()

The remainder of this section describes the low-level API for constructing animated figures manually.


#### Frames

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.

<!-- #region -->

#### Adding Control Buttons to Animations

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).
<br>
The buttons are defined as follows:

```
"updatemenus": [{"type": "buttons",
"buttons": [{"label": "Your Label",
"method": "animate",
"args": [See Below]}]}]
```

<!-- #endregion -->

#### Defining Button Arguments

- `None`: Setting `"args"` to undefined (i.e. `"args": [None]`) will create a simple play button that will animate all frames.
- 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.
- `["frame1", "frame2", ...]`: Animate a sequence of named frames.
- `[{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.
- `[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]`).
- <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>
Refer to the examples below to see the buttons in action!

Refer to the examples below to see the buttons in action!

#### Simple Play Button

Expand Down Expand Up @@ -224,6 +229,7 @@ fig.show()
```

#### Using a Slider and Buttons

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.

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.
Expand Down Expand Up @@ -378,9 +384,10 @@ fig.show()
```

#### Important Notes
- 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`.

- 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`.

#### Reference

For additional information and attributes for creating bubble charts in Plotly see: https://plot.ly/python/bubble-charts/.
For more documentation on creating animations with Plotly, see https://plot.ly/python/#animations.
Loading