Skip to content

Commit 42746dc

Browse files
Merge branch 'doc-prod'
2 parents 0753196 + d66e771 commit 42746dc

File tree

3 files changed

+51
-5
lines changed

3 files changed

+51
-5
lines changed

Diff for: doc/python/sunburst-charts.md

+20
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,26 @@ fig = px.sunburst(df, path=['continent', 'country'], values='pop',
8888
fig.show()
8989
```
9090

91+
### Sunburst of a rectangular DataFrame with discrete color argument in px.sunburst
92+
93+
When the argument of `color` corresponds to non-numerical data, discrete colors are used. If a sector has the same value of the `color` column for all its children, then the corresponding color is used, otherwise the first color of the discrete color sequence is used.
94+
95+
```python
96+
import plotly.express as px
97+
df = px.data.tips()
98+
fig = px.sunburst(df, path=['sex', 'day', 'time'], values='total_bill', color='day')
99+
fig.show()
100+
```
101+
102+
In the example below the color of `Saturday` and `Sunday` sectors is the same as `Dinner` because there are only Dinner entries for Saturday and Sunday. However, for Female -> Friday there are both lunches and dinners, hence the "mixed" color (blue here) is used.
103+
104+
```python
105+
import plotly.express as px
106+
df = px.data.tips()
107+
fig = px.sunburst(df, path=['sex', 'day', 'time'], values='total_bill', color='time')
108+
fig.show()
109+
```
110+
91111
### Rectangular data with missing values
92112

93113
If the dataset is not fully rectangular, missing values should be supplied as `None`. Note that the parents of `None` entries must be a leaf, i.e. it cannot have other children than `None` (otherwise a `ValueError` is raised).

Diff for: doc/python/treemaps.md

+30-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ jupyter:
66
extension: .md
77
format_name: markdown
88
format_version: '1.2'
9-
jupytext_version: 1.3.0
9+
jupytext_version: 1.3.1
1010
kernelspec:
1111
display_name: Python 3
1212
language: python
@@ -20,7 +20,7 @@ jupyter:
2020
name: python
2121
nbconvert_exporter: python
2222
pygments_lexer: ipython3
23-
version: 3.7.3
23+
version: 3.6.8
2424
plotly:
2525
description: How to make Treemap Charts with Plotly
2626
display_as: basic
@@ -66,17 +66,42 @@ fig.show()
6666

6767
If a `color` argument is passed, the color of a node is computed as the average of the color values of its children, weighted by their values.
6868

69+
**Note**: for best results, ensure that the first `path` element is a single root node. In the examples below we are creating a dummy column containing identical values for each row to achieve this.
70+
6971
```python
7072
import plotly.express as px
7173
import numpy as np
7274
df = px.data.gapminder().query("year == 2007")
73-
fig = px.treemap(df, path=['continent', 'country'], values='pop',
75+
df["world"] = "world" # in order to have a single root node
76+
fig = px.treemap(df, path=['world', 'continent', 'country'], values='pop',
7477
color='lifeExp', hover_data=['iso_alpha'],
7578
color_continuous_scale='RdBu',
7679
color_continuous_midpoint=np.average(df['lifeExp'], weights=df['pop']))
7780
fig.show()
7881
```
7982

83+
### Treemap of a rectangular DataFrame with discrete color argument in px.treemap
84+
85+
When the argument of `color` corresponds to non-numerical data, discrete colors are used. If a sector has the same value of the `color` column for all its children, then the corresponding color is used, otherwise the first color of the discrete color sequence is used.
86+
87+
```python
88+
import plotly.express as px
89+
df = px.data.tips()
90+
df["all"] = "all" # in order to have a single root node
91+
fig = px.treemap(df, path=['all', 'sex', 'day', 'time'], values='total_bill', color='day')
92+
fig.show()
93+
```
94+
95+
In the example below the color of Saturday and Sunday sectors is the same as Dinner because there are only Dinner entries for Saturday and Sunday. However, for Female -> Friday there are both lunches and dinners, hence the "mixed" color (blue here) is used.
96+
97+
```python
98+
import plotly.express as px
99+
df = px.data.tips()
100+
df["all"] = "all" # in order to have a single root node
101+
fig = px.treemap(df, path=['all', 'sex', 'day', 'time'], values='total_bill', color='time')
102+
fig.show()
103+
```
104+
80105
### Rectangular data with missing values
81106

82107
If the dataset is not fully rectangular, missing values should be supplied as `None`.
@@ -93,8 +118,9 @@ sales = [1, 3, 2, 4, 1, 2, 2, 1, 4, 1]
93118
df = pd.DataFrame(
94119
dict(vendors=vendors, sectors=sectors, regions=regions, sales=sales)
95120
)
121+
df["all"] = "all" # in order to have a single root node
96122
print(df)
97-
fig = px.treemap(df, path=['regions', 'sectors', 'vendors'], values='sales')
123+
fig = px.treemap(df, path=['all', 'regions', 'sectors', 'vendors'], values='sales')
98124
fig.show()
99125
```
100126
### Basic Treemap with go.Treemap

Diff for: doc/python/v4-migration.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ To migrate version 3 "online" functionality, first install the `chart-studio` pa
5252
$ pip install chart-studio
5353
```
5454

55-
of conda.
55+
or conda.
5656

5757
```
5858
$ conda install -c plotly chart-studio

0 commit comments

Comments
 (0)