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

Skip to content

Commit 571ca11

Browse files
committed
Merge branch 'source-design-merge' into chart-studio-reorg
2 parents 6c7f8fe + 816afd3 commit 571ca11

11 files changed

+748
-31
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
---
2+
name: Branchvalues
3+
plot_url: https://codepen.io/plotly/embed/orjwem/?height=500&theme-id=15263&default-tab=result
4+
language: plotly_js
5+
suite: sunburst
6+
order: 1.5
7+
sitemap: false
8+
arrangement: horizontal
9+
markdown_content: |
10+
With branchvalues "total", the value of the parent represents the width of its wedge. In the example below,
11+
"Enoch" is 4 and "Awan" is 6 and so Enoch's width is 4/6ths of Awans. With branchvalues "remainder", the
12+
parent's width is determined by its own value plus those of its children. So, Enoch's width is 4/10ths of
13+
Awan's (4 / (6 + 4)).<br><br>Note that this means that the sum of the values of the children cannot exceed the
14+
value of their parent when branchvalues "total". When branchvalues "relative" (the default), children will not take
15+
up all of the space below their parent (unless the parent is the root and it has a value of 0).
16+
---
17+
var data = [
18+
{
19+
"type": "sunburst",
20+
"labels": ["Eve", "Cain", "Seth", "Enos", "Noam", "Abel", "Awan", "Enoch", "Azura"],
21+
"parents": ["", "Eve", "Eve", "Seth", "Seth", "Eve", "Eve", "Awan", "Eve" ],
22+
"values": [65, 14, 12, 10, 2, 6, 6, 4, 4],
23+
"leaf": {"opacity": 0.4},
24+
"marker": {"line": {"width": 2}},
25+
"branchvalues": 'total'
26+
}];
27+
28+
var layout = {
29+
"margin": {"l": 0, "r": 0, "b": 0, "t": 0},
30+
};
31+
32+
33+
Plotly.newPlot('myDiv', data, layout, {showSendToCloud: true})
34+
35+
myPlot = document.getElementById("myDiv");
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
---
2+
name: Advanced Hovertemplate
3+
plot_url: https://codepen.io/plotly/embed/eagwKe/?height=600&theme-id=15263&default-tab=result
4+
language: plotly_js
5+
suite: hover
6+
order: 4
7+
sitemap: false
8+
arrangement: horizontal
9+
---
10+
11+
Plotly.d3.csv(
12+
"https://raw.githubusercontent.com/plotly/datasets/master/job-automation-probability.csv",
13+
function(rows) {
14+
var x = [],
15+
y = [],
16+
s = [],
17+
c = [],
18+
t = [];
19+
20+
for (var i = 0; i < rows.length; i++) {
21+
row = rows[i];
22+
y.push(row["Average annual wage"]);
23+
x.push(row["prob"]);
24+
s.push(row["numbEmployed"]);
25+
c.push(row["education"]);
26+
t.push(row["short occupation"]);
27+
}
28+
29+
Plotly.newPlot("myDiv", {
30+
data: [
31+
{
32+
type: "scatter",
33+
mode: "markers",
34+
x: x,
35+
y: y,
36+
text: t,
37+
marker: { size: s, sizeref: 4000, sizemode: "area" },
38+
transforms: [{ type: "groupby", groups: c }],
39+
hovertemplate:
40+
"<b>%{text}</b><br><br>" +
41+
"%{yaxis.title.text}: %{y:$,.0f}<br>" +
42+
"%{xaxis.title.text}: %{x:.0%}<br>" +
43+
"Number Employed: %{marker.size:,}" +
44+
"<extra></extra>"
45+
}
46+
],
47+
layout: {
48+
title: "Higher Risk of Job Automation in Lower Paying Jobs",
49+
hovermode: "closest",
50+
hoverlabel: { bgcolor: "#FFF" },
51+
legend: {orientation: 'h', y: -0.3},
52+
xaxis: {
53+
tickformat: ".0%",
54+
title: "Automation Probability",
55+
zeroline: false
56+
},
57+
yaxis: {
58+
title: "Income",
59+
zeroline: false
60+
}
61+
},
62+
config: { responsive: true }
63+
});
64+
}
65+
);
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
---
2+
name: Hovertemplate
3+
plot_url: https://codepen.io/plotly/embed/wbgLjM/?height=600&theme-id=15263&default-tab=result
4+
language: plotly_js
5+
suite: hover
6+
order: 3
7+
sitemap: false
8+
arrangement: horizontal
9+
---
10+
11+
var data = [
12+
{
13+
type: 'scatter',
14+
mode: 'lines+markers',
15+
x: [1,2,3,4,5],
16+
y: [2.02825,1.63728,6.83839,4.8485,4.73463],
17+
hovertemplate: '<i>Price</i>: $%{y:.2f}' +
18+
'<br><b>X</b>: %{x}<br>' +
19+
'<b>%{text}</b>',
20+
text: ["Text A", "Text B", "Text C", "Text D", "Text E"],
21+
showlegend: false
22+
},
23+
{
24+
x: [1,2,3,4,5],
25+
y: [3.02825,2.63728,4.83839,3.8485,1.73463],
26+
hovertemplate: 'Price: %{y:$.2f}<extra></extra>',
27+
showlegend: false
28+
}
29+
];
30+
31+
var layout = {
32+
title: "Set hover text with hovertemplate",
33+
};
34+
35+
Plotly.newPlot('myDiv', data, layout);

_posts/python/basic/sunburst/2015-06-30-sunburst-charts.html

Lines changed: 63 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ <h4 id="Version-Check">Version Check<a class="anchor-link" href="#Version-Check"
6060

6161

6262
<div class="output_text output_subarea output_execute_result">
63-
<pre>&#39;3.8.0rc1&#39;</pre>
63+
<pre>&#39;3.10.0&#39;</pre>
6464
</div>
6565

6666
</div>
@@ -128,7 +128,9 @@ <h3 id="Basic-Sunburst-Plot">Basic Sunburst Plot<a class="anchor-link" href="#Ba
128128
</div>
129129
<div class="inner_cell">
130130
<div class="text_cell_render border-box-sizing rendered_html">
131-
<h3 id="Sunburst-with-Repeated-Labels">Sunburst with Repeated Labels<a class="anchor-link" href="#Sunburst-with-Repeated-Labels">&#182;</a></h3>
131+
<h3 id="Branchvalues">Branchvalues<a class="anchor-link" href="#Branchvalues">&#182;</a></h3><p>With branchvalues "total", the value of the parent represents the width of its wedge. In the example below, "Enoch" is 4 and "Awan" is 6 and so Enoch's width is 4/6ths of Awans. With branchvalues "remainder", the parent's width is determined by its own value plus those of its children. So, Enoch's width is 4/10ths of Awan's (4 / (6 + 4)).</p>
132+
<p>Note that this means that the sum of the values of the children cannot exceed the value of their parent when branchvalues "total". When branchvalues "relative" (the default), children will not take up all of the space below their parent (unless the parent is the root and it has a value of 0).</p>
133+
132134
</div>
133135
</div>
134136
</div>
@@ -140,6 +142,62 @@ <h3 id="Sunburst-with-Repeated-Labels">Sunburst with Repeated Labels<a class="an
140142
<div class=" highlight hl-ipython3"><pre><span></span><span class="kn">import</span> <span class="nn">plotly.plotly</span> <span class="k">as</span> <span class="nn">py</span>
141143
<span class="kn">import</span> <span class="nn">plotly.graph_objs</span> <span class="k">as</span> <span class="nn">go</span>
142144

145+
<span class="n">trace</span> <span class="o">=</span> <span class="n">go</span><span class="o">.</span><span class="n">Sunburst</span><span class="p">(</span>
146+
<span class="n">labels</span><span class="o">=</span><span class="p">[</span> <span class="s2">&quot;Eve&quot;</span><span class="p">,</span> <span class="s2">&quot;Cain&quot;</span><span class="p">,</span> <span class="s2">&quot;Seth&quot;</span><span class="p">,</span> <span class="s2">&quot;Enos&quot;</span><span class="p">,</span> <span class="s2">&quot;Noam&quot;</span><span class="p">,</span> <span class="s2">&quot;Abel&quot;</span><span class="p">,</span> <span class="s2">&quot;Awan&quot;</span><span class="p">,</span> <span class="s2">&quot;Enoch&quot;</span><span class="p">,</span> <span class="s2">&quot;Azura&quot;</span><span class="p">],</span>
147+
<span class="n">parents</span><span class="o">=</span><span class="p">[</span><span class="s2">&quot;&quot;</span><span class="p">,</span> <span class="s2">&quot;Eve&quot;</span><span class="p">,</span> <span class="s2">&quot;Eve&quot;</span><span class="p">,</span> <span class="s2">&quot;Seth&quot;</span><span class="p">,</span> <span class="s2">&quot;Seth&quot;</span><span class="p">,</span> <span class="s2">&quot;Eve&quot;</span><span class="p">,</span> <span class="s2">&quot;Eve&quot;</span><span class="p">,</span> <span class="s2">&quot;Awan&quot;</span><span class="p">,</span> <span class="s2">&quot;Eve&quot;</span> <span class="p">],</span>
148+
<span class="n">values</span><span class="o">=</span><span class="p">[</span> <span class="mi">65</span><span class="p">,</span> <span class="mi">14</span><span class="p">,</span> <span class="mi">12</span><span class="p">,</span> <span class="mi">10</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">6</span><span class="p">,</span> <span class="mi">6</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">4</span><span class="p">],</span>
149+
<span class="n">branchvalues</span><span class="o">=</span><span class="s2">&quot;total&quot;</span><span class="p">,</span>
150+
<span class="n">outsidetextfont</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&quot;size&quot;</span><span class="p">:</span> <span class="mi">20</span><span class="p">,</span> <span class="s2">&quot;color&quot;</span><span class="p">:</span> <span class="s2">&quot;#377eb8&quot;</span><span class="p">},</span>
151+
<span class="n">marker</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&quot;line&quot;</span><span class="p">:</span> <span class="p">{</span><span class="s2">&quot;width&quot;</span><span class="p">:</span> <span class="mi">2</span><span class="p">}},</span>
152+
<span class="p">)</span>
153+
154+
<span class="n">layout</span> <span class="o">=</span> <span class="n">go</span><span class="o">.</span><span class="n">Layout</span><span class="p">(</span>
155+
<span class="n">margin</span> <span class="o">=</span> <span class="n">go</span><span class="o">.</span><span class="n">layout</span><span class="o">.</span><span class="n">Margin</span><span class="p">(</span><span class="n">t</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">l</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">r</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">b</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>
156+
<span class="p">)</span>
157+
158+
<span class="n">py</span><span class="o">.</span><span class="n">iplot</span><span class="p">(</span><span class="n">go</span><span class="o">.</span><span class="n">Figure</span><span class="p">([</span><span class="n">trace</span><span class="p">],</span> <span class="n">layout</span><span class="p">),</span> <span class="n">filename</span><span class="o">=</span><span class="s1">&#39;basic_sunburst_chart_total_branchvalues&#39;</span><span class="p">)</span>
159+
</pre></div>
160+
161+
</div>
162+
</div>
163+
</div>
164+
165+
<div class="output_wrapper">
166+
<div class="output">
167+
168+
169+
<div class="output_area">
170+
171+
<div class="prompt output_prompt">Out[3]:</div>
172+
173+
174+
175+
<div class="output_html rendered_html output_subarea output_execute_result">
176+
<iframe id="igraph" scrolling="no" style="border:none;" seamless="seamless" src="https://plot.ly/~PythonPlotBot/3396.embed" height="525px" width="100%"></iframe>
177+
</div>
178+
179+
</div>
180+
181+
</div>
182+
</div>
183+
184+
</div>
185+
<div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt">
186+
</div>
187+
<div class="inner_cell">
188+
<div class="text_cell_render border-box-sizing rendered_html">
189+
<h3 id="Sunburst-with-Repeated-Labels">Sunburst with Repeated Labels<a class="anchor-link" href="#Sunburst-with-Repeated-Labels">&#182;</a></h3>
190+
</div>
191+
</div>
192+
</div>
193+
<div class="cell border-box-sizing code_cell rendered">
194+
<div class="input">
195+
<div class="prompt input_prompt">In&nbsp;[4]:</div>
196+
<div class="inner_cell">
197+
<div class="input_area">
198+
<div class=" highlight hl-ipython3"><pre><span></span><span class="kn">import</span> <span class="nn">plotly.plotly</span> <span class="k">as</span> <span class="nn">py</span>
199+
<span class="kn">import</span> <span class="nn">plotly.graph_objs</span> <span class="k">as</span> <span class="nn">go</span>
200+
143201

144202
<span class="n">trace</span> <span class="o">=</span> <span class="n">go</span><span class="o">.</span><span class="n">Sunburst</span><span class="p">(</span>
145203
<span class="n">ids</span><span class="o">=</span><span class="p">[</span>
@@ -186,7 +244,7 @@ <h3 id="Sunburst-with-Repeated-Labels">Sunburst with Repeated Labels<a class="an
186244

187245
<div class="output_area">
188246

189-
<div class="prompt output_prompt">Out[3]:</div>
247+
<div class="prompt output_prompt">Out[4]:</div>
190248

191249

192250

@@ -211,7 +269,7 @@ <h3 id="Large-Number-of-Slices">Large Number of Slices<a class="anchor-link" hre
211269
</div>
212270
<div class="cell border-box-sizing code_cell rendered">
213271
<div class="input">
214-
<div class="prompt input_prompt">In&nbsp;[4]:</div>
272+
<div class="prompt input_prompt">In&nbsp;[5]:</div>
215273
<div class="inner_cell">
216274
<div class="input_area">
217275
<div class=" highlight hl-ipython3"><pre><span></span><span class="kn">import</span> <span class="nn">plotly.plotly</span> <span class="k">as</span> <span class="nn">py</span>
@@ -264,7 +322,7 @@ <h3 id="Large-Number-of-Slices">Large Number of Slices<a class="anchor-link" hre
264322

265323
<div class="output_area">
266324

267-
<div class="prompt output_prompt">Out[4]:</div>
325+
<div class="prompt output_prompt">Out[5]:</div>
268326

269327

270328

_posts/python/basic/sunburst/sunburst-charts.ipynb

Lines changed: 57 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
{
2929
"data": {
3030
"text/plain": [
31-
"'3.8.0rc1'"
31+
"'3.10.0'"
3232
]
3333
},
3434
"execution_count": 1,
@@ -90,7 +90,10 @@
9090
"cell_type": "markdown",
9191
"metadata": {},
9292
"source": [
93-
"### Sunburst with Repeated Labels"
93+
"### Branchvalues ###\n",
94+
"With branchvalues \"total\", the value of the parent represents the width of its wedge. In the example below, \"Enoch\" is 4 and \"Awan\" is 6 and so Enoch's width is 4/6ths of Awans. With branchvalues \"remainder\", the parent's width is determined by its own value plus those of its children. So, Enoch's width is 4/10ths of Awan's (4 / (6 + 4)).\n",
95+
"\n",
96+
"Note that this means that the sum of the values of the children cannot exceed the value of their parent when branchvalues \"total\". When branchvalues \"relative\" (the default), children will not take up all of the space below their parent (unless the parent is the root and it has a value of 0)."
9497
]
9598
},
9699
{
@@ -101,7 +104,7 @@
101104
{
102105
"data": {
103106
"text/html": [
104-
"<iframe id=\"igraph\" scrolling=\"no\" style=\"border:none;\" seamless=\"seamless\" src=\"https://plot.ly/~PythonPlotBot/3328.embed\" height=\"525px\" width=\"100%\"></iframe>"
107+
"<iframe id=\"igraph\" scrolling=\"no\" style=\"border:none;\" seamless=\"seamless\" src=\"https://plot.ly/~PythonPlotBot/3396.embed\" height=\"525px\" width=\"100%\"></iframe>"
105108
],
106109
"text/plain": [
107110
"<chart_studio.tools.PlotlyDisplay object>"
@@ -112,6 +115,52 @@
112115
"output_type": "execute_result"
113116
}
114117
],
118+
"source": [
119+
"import plotly.plotly as py\n",
120+
"import plotly.graph_objs as go\n",
121+
"\n",
122+
"trace = go.Sunburst(\n",
123+
" labels=[ \"Eve\", \"Cain\", \"Seth\", \"Enos\", \"Noam\", \"Abel\", \"Awan\", \"Enoch\", \"Azura\"],\n",
124+
" parents=[\"\", \"Eve\", \"Eve\", \"Seth\", \"Seth\", \"Eve\", \"Eve\", \"Awan\", \"Eve\" ],\n",
125+
" values=[ 65, 14, 12, 10, 2, 6, 6, 4, 4],\n",
126+
" branchvalues=\"total\",\n",
127+
" outsidetextfont = {\"size\": 20, \"color\": \"#377eb8\"},\n",
128+
" marker = {\"line\": {\"width\": 2}},\n",
129+
")\n",
130+
"\n",
131+
"layout = go.Layout(\n",
132+
" margin = go.layout.Margin(t=0, l=0, r=0, b=0)\n",
133+
")\n",
134+
"\n",
135+
"py.iplot(go.Figure([trace], layout), filename='basic_sunburst_chart_total_branchvalues')"
136+
]
137+
},
138+
{
139+
"cell_type": "markdown",
140+
"metadata": {},
141+
"source": [
142+
"### Sunburst with Repeated Labels"
143+
]
144+
},
145+
{
146+
"cell_type": "code",
147+
"execution_count": 4,
148+
"metadata": {},
149+
"outputs": [
150+
{
151+
"data": {
152+
"text/html": [
153+
"<iframe id=\"igraph\" scrolling=\"no\" style=\"border:none;\" seamless=\"seamless\" src=\"https://plot.ly/~PythonPlotBot/3328.embed\" height=\"525px\" width=\"100%\"></iframe>"
154+
],
155+
"text/plain": [
156+
"<chart_studio.tools.PlotlyDisplay object>"
157+
]
158+
},
159+
"execution_count": 4,
160+
"metadata": {},
161+
"output_type": "execute_result"
162+
}
163+
],
115164
"source": [
116165
"import plotly.plotly as py\n",
117166
"import plotly.graph_objs as go\n",
@@ -162,7 +211,7 @@
162211
},
163212
{
164213
"cell_type": "code",
165-
"execution_count": 4,
214+
"execution_count": 5,
166215
"metadata": {},
167216
"outputs": [
168217
{
@@ -174,7 +223,7 @@
174223
"<chart_studio.tools.PlotlyDisplay object>"
175224
]
176225
},
177-
"execution_count": 4,
226+
"execution_count": 5,
178227
"metadata": {},
179228
"output_type": "execute_result"
180229
}
@@ -306,6 +355,9 @@
306355
}
307356
],
308357
"metadata": {
358+
"jupytext": {
359+
"notebook_metadata_filter": "all,-language_info,-kernelspec"
360+
},
309361
"kernelspec": {
310362
"display_name": "Python 3",
311363
"language": "python",

0 commit comments

Comments
 (0)