Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3bc18ed

Browse files
committed
added discrete color examples
1 parent e2a4633 commit 3bc18ed

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

doc/python/sunburst-charts.md

Lines changed: 20 additions & 0 deletions
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).

doc/python/treemaps.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,26 @@ fig = px.treemap(df, path=['continent', 'country'], values='pop',
7777
fig.show()
7878
```
7979

80+
### Treemap of a rectangular DataFrame with discrete color argument in px.treemap
81+
82+
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.
83+
84+
```python
85+
import plotly.express as px
86+
df = px.data.tips()
87+
fig = px.treemap(df, path=['sex', 'day', 'time'], values='total_bill', color='day')
88+
fig.show()
89+
```
90+
91+
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.
92+
93+
```python
94+
import plotly.express as px
95+
df = px.data.tips()
96+
fig = px.treemap(df, path=['sex', 'day', 'time'], values='total_bill', color='time')
97+
fig.show()
98+
```
99+
80100
### Rectangular data with missing values
81101

82102
If the dataset is not fully rectangular, missing values should be supplied as `None`.

0 commit comments

Comments
 (0)