Skip to content

Commit 333787a

Browse files
committed
update plotly -- pie
1 parent 5f09444 commit 333787a

File tree

1 file changed

+389
-0
lines changed

1 file changed

+389
-0
lines changed

Plotly/pie.ipynb

Lines changed: 389 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,389 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 3,
6+
"metadata": {},
7+
"outputs": [
8+
{
9+
"data": {
10+
"text/html": [
11+
"<script type=\"text/javascript\">window.PlotlyConfig = {MathJaxConfig: 'local'};</script><script type=\"text/javascript\">if (window.MathJax) {MathJax.Hub.Config({SVG: {font: \"STIX-Web\"}});}</script><script>requirejs.config({paths: { 'plotly': ['https://cdn.plot.ly/plotly-latest.min']},});if(!window._Plotly) {require(['plotly'],function(plotly) {window._Plotly=plotly;});}</script>"
12+
],
13+
"text/vnd.plotly.v1+html": [
14+
"<script type=\"text/javascript\">window.PlotlyConfig = {MathJaxConfig: 'local'};</script><script type=\"text/javascript\">if (window.MathJax) {MathJax.Hub.Config({SVG: {font: \"STIX-Web\"}});}</script><script>requirejs.config({paths: { 'plotly': ['https://cdn.plot.ly/plotly-latest.min']},});if(!window._Plotly) {require(['plotly'],function(plotly) {window._Plotly=plotly;});}</script>"
15+
]
16+
},
17+
"metadata": {},
18+
"output_type": "display_data"
19+
}
20+
],
21+
"source": [
22+
"import plotly\n",
23+
"import plotly.graph_objs as go\n",
24+
"plotly.offline.init_notebook_mode(connected=True)"
25+
]
26+
},
27+
{
28+
"cell_type": "markdown",
29+
"metadata": {},
30+
"source": [
31+
"# Basic Pie Chart"
32+
]
33+
},
34+
{
35+
"cell_type": "code",
36+
"execution_count": 4,
37+
"metadata": {},
38+
"outputs": [
39+
{
40+
"data": {
41+
"application/vnd.plotly.v1+json": {
42+
"config": {
43+
"linkText": "Export to plot.ly",
44+
"plotlyServerURL": "https://plot.ly",
45+
"showLink": true
46+
},
47+
"data": [
48+
{
49+
"labels": [
50+
"Oxygen",
51+
"Hydrogen",
52+
"Carbon_Dioxide",
53+
"Nitrogen"
54+
],
55+
"type": "pie",
56+
"uid": "2e574503-a57d-4ea2-aa41-b770f8461ff6",
57+
"values": [
58+
4500,
59+
2500,
60+
1053,
61+
500
62+
]
63+
}
64+
],
65+
"layout": {}
66+
},
67+
"text/html": [
68+
"<div id=\"fc57a114-38da-42ff-b7fc-bab6594e18ba\" style=\"height: 525px; width: 100%;\" class=\"plotly-graph-div\"></div><script type=\"text/javascript\">require([\"plotly\"], function(Plotly) { window.PLOTLYENV=window.PLOTLYENV || {};window.PLOTLYENV.BASE_URL=\"https://plot.ly\";Plotly.newPlot(\"fc57a114-38da-42ff-b7fc-bab6594e18ba\", [{\"labels\": [\"Oxygen\", \"Hydrogen\", \"Carbon_Dioxide\", \"Nitrogen\"], \"values\": [4500, 2500, 1053, 500], \"type\": \"pie\", \"uid\": \"18aaba2e-5667-4f5f-9d10-a7d1e3578a3e\"}], {}, {\"showLink\": true, \"linkText\": \"Export to plot.ly\", \"plotlyServerURL\": \"https://plot.ly\"})});</script><script type=\"text/javascript\">window.addEventListener(\"resize\", function(){window._Plotly.Plots.resize(document.getElementById(\"fc57a114-38da-42ff-b7fc-bab6594e18ba\"));});</script>"
69+
],
70+
"text/vnd.plotly.v1+html": [
71+
"<div id=\"fc57a114-38da-42ff-b7fc-bab6594e18ba\" style=\"height: 525px; width: 100%;\" class=\"plotly-graph-div\"></div><script type=\"text/javascript\">require([\"plotly\"], function(Plotly) { window.PLOTLYENV=window.PLOTLYENV || {};window.PLOTLYENV.BASE_URL=\"https://plot.ly\";Plotly.newPlot(\"fc57a114-38da-42ff-b7fc-bab6594e18ba\", [{\"labels\": [\"Oxygen\", \"Hydrogen\", \"Carbon_Dioxide\", \"Nitrogen\"], \"values\": [4500, 2500, 1053, 500], \"type\": \"pie\", \"uid\": \"18aaba2e-5667-4f5f-9d10-a7d1e3578a3e\"}], {}, {\"showLink\": true, \"linkText\": \"Export to plot.ly\", \"plotlyServerURL\": \"https://plot.ly\"})});</script><script type=\"text/javascript\">window.addEventListener(\"resize\", function(){window._Plotly.Plots.resize(document.getElementById(\"fc57a114-38da-42ff-b7fc-bab6594e18ba\"));});</script>"
72+
]
73+
},
74+
"metadata": {},
75+
"output_type": "display_data"
76+
}
77+
],
78+
"source": [
79+
"labels = ['Oxygen','Hydrogen','Carbon_Dioxide','Nitrogen']\n",
80+
"values = [4500,2500,1053,500]\n",
81+
"\n",
82+
"trace = go.Pie(labels=labels, values=values)\n",
83+
"plotly.offline.iplot([trace], filename='basic_pie_chart')"
84+
]
85+
},
86+
{
87+
"cell_type": "markdown",
88+
"metadata": {},
89+
"source": [
90+
"# Styled Pie Chart"
91+
]
92+
},
93+
{
94+
"cell_type": "code",
95+
"execution_count": 5,
96+
"metadata": {},
97+
"outputs": [
98+
{
99+
"data": {
100+
"application/vnd.plotly.v1+json": {
101+
"config": {
102+
"linkText": "Export to plot.ly",
103+
"plotlyServerURL": "https://plot.ly",
104+
"showLink": true
105+
},
106+
"data": [
107+
{
108+
"hoverinfo": "label+percent",
109+
"labels": [
110+
"Oxygen",
111+
"Hydrogen",
112+
"Carbon_Dioxide",
113+
"Nitrogen"
114+
],
115+
"marker": {
116+
"colors": [
117+
"#FEBFB3",
118+
"#E1396C",
119+
"#96D38C",
120+
"#D0F9B1"
121+
],
122+
"line": {
123+
"color": "#000000",
124+
"width": 2
125+
}
126+
},
127+
"textfont": {
128+
"size": 20
129+
},
130+
"textinfo": "value",
131+
"type": "pie",
132+
"uid": "595b33b4-b572-44f5-9a18-99eeea5b0286",
133+
"values": [
134+
4500,
135+
2500,
136+
1053,
137+
500
138+
]
139+
}
140+
],
141+
"layout": {}
142+
},
143+
"text/html": [
144+
"<div id=\"74645c11-3167-49ac-bcf3-3f234588d068\" style=\"height: 525px; width: 100%;\" class=\"plotly-graph-div\"></div><script type=\"text/javascript\">require([\"plotly\"], function(Plotly) { window.PLOTLYENV=window.PLOTLYENV || {};window.PLOTLYENV.BASE_URL=\"https://plot.ly\";Plotly.newPlot(\"74645c11-3167-49ac-bcf3-3f234588d068\", [{\"hoverinfo\": \"label+percent\", \"labels\": [\"Oxygen\", \"Hydrogen\", \"Carbon_Dioxide\", \"Nitrogen\"], \"marker\": {\"colors\": [\"#FEBFB3\", \"#E1396C\", \"#96D38C\", \"#D0F9B1\"], \"line\": {\"color\": \"#000000\", \"width\": 2}}, \"textfont\": {\"size\": 20}, \"textinfo\": \"value\", \"values\": [4500, 2500, 1053, 500], \"type\": \"pie\", \"uid\": \"4702e940-ba85-43ca-8e5b-86ad1a94f830\"}], {}, {\"showLink\": true, \"linkText\": \"Export to plot.ly\", \"plotlyServerURL\": \"https://plot.ly\"})});</script><script type=\"text/javascript\">window.addEventListener(\"resize\", function(){window._Plotly.Plots.resize(document.getElementById(\"74645c11-3167-49ac-bcf3-3f234588d068\"));});</script>"
145+
],
146+
"text/vnd.plotly.v1+html": [
147+
"<div id=\"74645c11-3167-49ac-bcf3-3f234588d068\" style=\"height: 525px; width: 100%;\" class=\"plotly-graph-div\"></div><script type=\"text/javascript\">require([\"plotly\"], function(Plotly) { window.PLOTLYENV=window.PLOTLYENV || {};window.PLOTLYENV.BASE_URL=\"https://plot.ly\";Plotly.newPlot(\"74645c11-3167-49ac-bcf3-3f234588d068\", [{\"hoverinfo\": \"label+percent\", \"labels\": [\"Oxygen\", \"Hydrogen\", \"Carbon_Dioxide\", \"Nitrogen\"], \"marker\": {\"colors\": [\"#FEBFB3\", \"#E1396C\", \"#96D38C\", \"#D0F9B1\"], \"line\": {\"color\": \"#000000\", \"width\": 2}}, \"textfont\": {\"size\": 20}, \"textinfo\": \"value\", \"values\": [4500, 2500, 1053, 500], \"type\": \"pie\", \"uid\": \"4702e940-ba85-43ca-8e5b-86ad1a94f830\"}], {}, {\"showLink\": true, \"linkText\": \"Export to plot.ly\", \"plotlyServerURL\": \"https://plot.ly\"})});</script><script type=\"text/javascript\">window.addEventListener(\"resize\", function(){window._Plotly.Plots.resize(document.getElementById(\"74645c11-3167-49ac-bcf3-3f234588d068\"));});</script>"
148+
]
149+
},
150+
"metadata": {},
151+
"output_type": "display_data"
152+
}
153+
],
154+
"source": [
155+
"labels = ['Oxygen','Hydrogen','Carbon_Dioxide','Nitrogen']\n",
156+
"values = [4500,2500,1053,500]\n",
157+
"colors = ['#FEBFB3', '#E1396C', '#96D38C', '#D0F9B1']\n",
158+
"\n",
159+
"trace = go.Pie(\n",
160+
" labels=labels, values=values,\n",
161+
" hoverinfo='label+percent', \n",
162+
" textinfo='value', \n",
163+
" textfont=dict(size=20),\n",
164+
" marker=dict(\n",
165+
" colors=colors, \n",
166+
" line=dict(color='#000000', width=2)\n",
167+
" )\n",
168+
")\n",
169+
"plotly.offline.iplot([trace], filename='styled_pie_chart')"
170+
]
171+
},
172+
{
173+
"cell_type": "markdown",
174+
"metadata": {},
175+
"source": [
176+
"# Donut Chart"
177+
]
178+
},
179+
{
180+
"cell_type": "code",
181+
"execution_count": 14,
182+
"metadata": {},
183+
"outputs": [
184+
{
185+
"data": {
186+
"application/vnd.plotly.v1+json": {
187+
"config": {
188+
"linkText": "Export to plot.ly",
189+
"plotlyServerURL": "https://plot.ly",
190+
"showLink": true
191+
},
192+
"data": [
193+
{
194+
"domain": {
195+
"x": [
196+
0,
197+
0.48
198+
],
199+
"y": [
200+
0,
201+
1
202+
]
203+
},
204+
"hole": 0.4,
205+
"hoverinfo": "label+percent+name",
206+
"labels": [
207+
"US",
208+
"China",
209+
"European Union",
210+
"Russian Federation",
211+
"Brazil",
212+
"India",
213+
"Rest of World"
214+
],
215+
"name": "GHG Emissions",
216+
"type": "pie",
217+
"uid": "32fa5d30-977f-4fa3-bec9-30b7cdd52d19",
218+
"values": [
219+
16,
220+
15,
221+
12,
222+
6,
223+
5,
224+
4,
225+
42
226+
]
227+
},
228+
{
229+
"domain": {
230+
"x": [
231+
0.52,
232+
1
233+
],
234+
"y": [
235+
0,
236+
1
237+
]
238+
},
239+
"hole": 0.4,
240+
"hoverinfo": "label+percent+name",
241+
"labels": [
242+
"US",
243+
"China",
244+
"European Union",
245+
"Russian Federation",
246+
"Brazil",
247+
"India",
248+
"Rest of World"
249+
],
250+
"name": "CO2 Emissions",
251+
"text": [
252+
"CO2",
253+
"CO2",
254+
"CO2",
255+
"CO2",
256+
"CO2",
257+
"CO2",
258+
"CO2"
259+
],
260+
"textposition": "inside",
261+
"type": "pie",
262+
"uid": "e7b3bdb8-1c4e-4aec-a46b-e836aa8747cc",
263+
"values": [
264+
27,
265+
11,
266+
25,
267+
8,
268+
1,
269+
3,
270+
25
271+
]
272+
}
273+
],
274+
"layout": {
275+
"annotations": [
276+
{
277+
"font": {
278+
"size": 20
279+
},
280+
"showarrow": false,
281+
"text": "GHG",
282+
"x": 0.2,
283+
"y": 0.5
284+
},
285+
{
286+
"font": {
287+
"size": 20
288+
},
289+
"showarrow": false,
290+
"text": "CO2",
291+
"x": 0.8,
292+
"y": 0.5
293+
}
294+
],
295+
"title": "Global Emissions 1990-2011"
296+
}
297+
},
298+
"text/html": [
299+
"<div id=\"24076b94-e5d5-4436-b2f6-3c0dc001e9f7\" style=\"height: 525px; width: 100%;\" class=\"plotly-graph-div\"></div><script type=\"text/javascript\">require([\"plotly\"], function(Plotly) { window.PLOTLYENV=window.PLOTLYENV || {};window.PLOTLYENV.BASE_URL=\"https://plot.ly\";Plotly.newPlot(\"24076b94-e5d5-4436-b2f6-3c0dc001e9f7\", [{\"domain\": {\"x\": [0, 0.48], \"y\": [0, 1]}, \"hole\": 0.4, \"hoverinfo\": \"label+percent+name\", \"labels\": [\"US\", \"China\", \"European Union\", \"Russian Federation\", \"Brazil\", \"India\", \"Rest of World\"], \"name\": \"GHG Emissions\", \"values\": [16, 15, 12, 6, 5, 4, 42], \"type\": \"pie\", \"uid\": \"4353a1f2-5fd3-4d44-9ff3-d2d95a5c34cb\"}, {\"domain\": {\"x\": [0.52, 1], \"y\": [0, 1]}, \"hole\": 0.4, \"hoverinfo\": \"label+percent+name\", \"labels\": [\"US\", \"China\", \"European Union\", \"Russian Federation\", \"Brazil\", \"India\", \"Rest of World\"], \"name\": \"CO2 Emissions\", \"text\": [\"CO2\", \"CO2\", \"CO2\", \"CO2\", \"CO2\", \"CO2\", \"CO2\"], \"textposition\": \"inside\", \"values\": [27, 11, 25, 8, 1, 3, 25], \"type\": \"pie\", \"uid\": \"e7c12093-bc87-4e4c-9464-c984699a098c\"}], {\"annotations\": [{\"font\": {\"size\": 20}, \"showarrow\": false, \"text\": \"GHG\", \"x\": 0.2, \"y\": 0.5}, {\"font\": {\"size\": 20}, \"showarrow\": false, \"text\": \"CO2\", \"x\": 0.8, \"y\": 0.5}], \"title\": \"Global Emissions 1990-2011\"}, {\"showLink\": true, \"linkText\": \"Export to plot.ly\", \"plotlyServerURL\": \"https://plot.ly\"})});</script><script type=\"text/javascript\">window.addEventListener(\"resize\", function(){window._Plotly.Plots.resize(document.getElementById(\"24076b94-e5d5-4436-b2f6-3c0dc001e9f7\"));});</script>"
300+
],
301+
"text/vnd.plotly.v1+html": [
302+
"<div id=\"24076b94-e5d5-4436-b2f6-3c0dc001e9f7\" style=\"height: 525px; width: 100%;\" class=\"plotly-graph-div\"></div><script type=\"text/javascript\">require([\"plotly\"], function(Plotly) { window.PLOTLYENV=window.PLOTLYENV || {};window.PLOTLYENV.BASE_URL=\"https://plot.ly\";Plotly.newPlot(\"24076b94-e5d5-4436-b2f6-3c0dc001e9f7\", [{\"domain\": {\"x\": [0, 0.48], \"y\": [0, 1]}, \"hole\": 0.4, \"hoverinfo\": \"label+percent+name\", \"labels\": [\"US\", \"China\", \"European Union\", \"Russian Federation\", \"Brazil\", \"India\", \"Rest of World\"], \"name\": \"GHG Emissions\", \"values\": [16, 15, 12, 6, 5, 4, 42], \"type\": \"pie\", \"uid\": \"4353a1f2-5fd3-4d44-9ff3-d2d95a5c34cb\"}, {\"domain\": {\"x\": [0.52, 1], \"y\": [0, 1]}, \"hole\": 0.4, \"hoverinfo\": \"label+percent+name\", \"labels\": [\"US\", \"China\", \"European Union\", \"Russian Federation\", \"Brazil\", \"India\", \"Rest of World\"], \"name\": \"CO2 Emissions\", \"text\": [\"CO2\", \"CO2\", \"CO2\", \"CO2\", \"CO2\", \"CO2\", \"CO2\"], \"textposition\": \"inside\", \"values\": [27, 11, 25, 8, 1, 3, 25], \"type\": \"pie\", \"uid\": \"e7c12093-bc87-4e4c-9464-c984699a098c\"}], {\"annotations\": [{\"font\": {\"size\": 20}, \"showarrow\": false, \"text\": \"GHG\", \"x\": 0.2, \"y\": 0.5}, {\"font\": {\"size\": 20}, \"showarrow\": false, \"text\": \"CO2\", \"x\": 0.8, \"y\": 0.5}], \"title\": \"Global Emissions 1990-2011\"}, {\"showLink\": true, \"linkText\": \"Export to plot.ly\", \"plotlyServerURL\": \"https://plot.ly\"})});</script><script type=\"text/javascript\">window.addEventListener(\"resize\", function(){window._Plotly.Plots.resize(document.getElementById(\"24076b94-e5d5-4436-b2f6-3c0dc001e9f7\"));});</script>"
303+
]
304+
},
305+
"metadata": {},
306+
"output_type": "display_data"
307+
}
308+
],
309+
"source": [
310+
"# 使用字典形式\n",
311+
"fig = {\n",
312+
" \"data\": [\n",
313+
" {\n",
314+
" \"values\": [16, 15, 12, 6, 5, 4, 42],\n",
315+
" \"labels\": [\"US\", \"China\", \"European Union\", \"Russian Federation\", \"Brazil\", \"India\", \"Rest of World\"],\n",
316+
" # 设置显示区域占左半部分\n",
317+
" \"domain\": {\n",
318+
" \"x\": [0, .48],\n",
319+
" \"y\": [0, 1],\n",
320+
" },\n",
321+
" \"name\": \"GHG Emissions\",\n",
322+
" \"hoverinfo\":\"label+percent+name\",\n",
323+
" # 设置空心的大小\n",
324+
" \"hole\": .4,\n",
325+
" \"type\": \"pie\"\n",
326+
" },\n",
327+
" {\n",
328+
" \"values\": [27, 11, 25, 8, 1, 3, 25],\n",
329+
" \"labels\": [\"US\", \"China\", \"European Union\", \"Russian Federation\", \"Brazil\", \"India\", \"Rest of World\"],\n",
330+
" \"text\":[\"CO2\"] * 7,\n",
331+
" \"textposition\":\"inside\",\n",
332+
" # 设置显示区域占右半部分\n",
333+
" \"domain\": {\n",
334+
" \"x\": [.52, 1],\n",
335+
" \"y\": [0, 1],\n",
336+
" },\n",
337+
" \"name\": \"CO2 Emissions\",\n",
338+
" \"hoverinfo\":\"label+percent+name\",\n",
339+
" # 设置空心的大小\n",
340+
" \"hole\": .4,\n",
341+
" \"type\": \"pie\"\n",
342+
" }\n",
343+
" ],\n",
344+
" \"layout\": {\n",
345+
" \"title\":\"Global Emissions 1990-2011\",\n",
346+
" \"annotations\": [\n",
347+
" {\n",
348+
" \"font\": {\"size\": 20},\n",
349+
" \"showarrow\": False,\n",
350+
" \"text\": \"GHG\",\n",
351+
" \"x\": 0.20,\n",
352+
" \"y\": 0.5\n",
353+
" },\n",
354+
" {\n",
355+
" \"font\": {\"size\": 20},\n",
356+
" \"showarrow\": False,\n",
357+
" \"text\": \"CO2\",\n",
358+
" \"x\": 0.8,\n",
359+
" \"y\": 0.5\n",
360+
" }\n",
361+
" ]\n",
362+
" }\n",
363+
"}\n",
364+
"plotly.offline.iplot(fig, filename='donut')"
365+
]
366+
}
367+
],
368+
"metadata": {
369+
"kernelspec": {
370+
"display_name": "Python 3",
371+
"language": "python",
372+
"name": "python3"
373+
},
374+
"language_info": {
375+
"codemirror_mode": {
376+
"name": "ipython",
377+
"version": 3
378+
},
379+
"file_extension": ".py",
380+
"mimetype": "text/x-python",
381+
"name": "python",
382+
"nbconvert_exporter": "python",
383+
"pygments_lexer": "ipython3",
384+
"version": "3.6.5"
385+
}
386+
},
387+
"nbformat": 4,
388+
"nbformat_minor": 2
389+
}

0 commit comments

Comments
 (0)