Skip to content

Commit 115cd5c

Browse files
committed
added scalegroup example
1 parent a0db69d commit 115cd5c

File tree

1 file changed

+30
-23
lines changed

1 file changed

+30
-23
lines changed

notebooks/pie-charts.md

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,14 @@ from plotly.subplots import make_subplots
8888

8989
labels = ["US", "China", "European Union", "Russian Federation", "Brazil", "India",
9090
"Rest of World"]
91-
trace0 = go.Pie(labels=labels, values=[16, 15, 12, 6, 5, 4, 42], name="GHG Emissions")
92-
trace1 = go.Pie(labels=labels, values=[27, 11, 25, 8, 1, 3, 25], name="CO2 Emissions")
9391

9492
# Create subplots: use 'domain' type for Pie subplot
9593
fig = make_subplots(rows=1, cols=2, specs=[[{'type':'domain'}, {'type':'domain'}]])
96-
fig.add_traces([trace0, trace1], rows=[1, 1], cols=[1, 2])
94+
fig.add_trace(go.Pie(labels=labels, values=[16, 15, 12, 6, 5, 4, 42], name="GHG Emissions"),
95+
1, 1)
96+
fig.add_trace(go.Pie(labels=labels, values=[27, 11, 25, 8, 1, 3, 25], name="CO2 Emissions"),
97+
1, 2)
98+
9799
# Use `hole` to create a donut-like pie chart
98100
fig.update_traces(hole=.4, hoverinfo="label+percent+name")
99101

@@ -126,21 +128,19 @@ irises_colors = ['rgb(33, 75, 99)', 'rgb(79, 129, 102)', 'rgb(151, 179, 100)',
126128
cafe_colors = ['rgb(146, 123, 21)', 'rgb(177, 180, 34)', 'rgb(206, 206, 40)',
127129
'rgb(175, 51, 21)', 'rgb(35, 36, 21)']
128130

129-
# Define pie charts
130-
night_pie = go.Pie(labels=labels, values=[38, 27, 18, 10, 7], name='Starry Night',
131-
marker_colors=night_colors)
132-
sunflowers_pie = go.Pie(labels=labels, values=[28, 26, 21, 15, 10], name='Sunflowers',
133-
marker_colors=sunflowers_colors)
134-
irises_pie = go.Pie(labels=labels, values=[38, 19, 16, 14, 13], name='Irises',
135-
marker_colors=irises_colors)
136-
cafe_pie = go.Pie(labels=labels, values=[31, 24, 19, 18, 8], name='The Night Café',
137-
marker_colors=cafe_colors)
138-
139-
# Create subplots, using 'domain' type for pie charts
131+
# Create subplots, using 'domain' type for pie charts
140132
specs = [[{'type':'domain'}, {'type':'domain'}], [{'type':'domain'}, {'type':'domain'}]]
141133
fig = make_subplots(rows=2, cols=2, specs=specs)
142-
fig.add_traces([irises_pie, cafe_pie, night_pie, sunflowers_pie],
143-
rows=[1, 1, 2, 2], cols=[1, 2, 1, 2])
134+
135+
# Define pie charts
136+
fig.add_trace(go.Pie(labels=labels, values=[38, 27, 18, 10, 7], name='Starry Night',
137+
marker_colors=night_colors), 1, 1)
138+
fig.add_trace(go.Pie(labels=labels, values=[28, 26, 21, 15, 10], name='Sunflowers',
139+
marker_colors=sunflowers_colors), 1, 2)
140+
fig.add_trace(go.Pie(labels=labels, values=[38, 19, 16, 14, 13], name='Irises',
141+
marker_colors=irises_colors), 2, 1)
142+
fig.add_trace(go.Pie(labels=labels, values=[31, 24, 19, 18, 8], name='The Night Café',
143+
marker_colors=cafe_colors), 2, 2)
144144

145145
# Tune layout and hover info
146146
fig.update_traces(hoverinfo='label+percent+name', textinfo='none')
@@ -151,17 +151,24 @@ fig = go.Figure(fig)
151151
fig.show()
152152
```
153153

154+
#### Plot chart with area proportional to total count
155+
156+
Plots in the same `scalegroup` are represented with an area proportional to their total size.
157+
154158
```python
155159
import plotly.graph_objects as go
160+
from plotly.subplots import make_subplots
156161

157-
labels = ['Oxygen','Hydrogen','Carbon_Dioxide','Nitrogen']
158-
values1 = [4500, 2500, 1053, 500]
159-
values2 = [40, 250, 153, 50]
162+
labels = ["Asia", "Europe", "Africa", "Americas", "Oceania"]
160163

161-
# Use `hole` to create a donut-like pie chart
162-
fig = go.Figure()
163-
fig.add_trace(go.Pie(labels=labels, values=values1, hole=.5, scalegroup='one'))
164-
fig.add_trace(go.Pie(labels=labels, values=values2, scalegroup='one'))
164+
fig = make_subplots(1, 2, specs=[[{'type':'domain'}, {'type':'domain'}]],
165+
subplot_titles=['1980', '2007'])
166+
fig.add_trace(go.Pie(labels=labels, values=[4, 7, 1, 7, 0.5], scalegroup='one',
167+
name="World GDP 1980"), 1, 1)
168+
fig.add_trace(go.Pie(labels=labels, values=[21, 15, 3, 19, 1], scalegroup='one',
169+
name="World GDP 2007"), 1, 2)
170+
171+
fig.update_layout(title_text='World GDP')
165172
fig.show()
166173
```
167174

0 commit comments

Comments
 (0)