-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpie_chart.py
More file actions
95 lines (78 loc) · 1.9 KB
/
pie_chart.py
File metadata and controls
95 lines (78 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
"""
Illustrate Pie chart options
"""
import os
from numpy.random import randint
from openpyxl import Workbook
from pandas import DataFrame
from sql2excel.chart import PieChart
n_slices = 10
fields = [f"Scientific Field ({i})" for i in range(1, n_slices + 1)]
values = randint(100, 1000, size=n_slices)
df = DataFrame({"Field": fields, "Publication": values})
wb = Workbook()
ws = wb.active
chart = PieChart()
chart.plot(df, ws, section_heading="Pie Chart: default options")
# All options are turned off
chart.plot(
df,
ws,
section_heading="Pie Chart: all options are False",
show_percentage=False,
show_category=False,
show_legend_key=False,
show_values=False,
show_series_name=False,
show_legend=False,
)
# Showing percentages and values
chart.plot(
df,
ws,
section_heading="Pie Chart: showing percentages and values",
show_percentage=True,
show_category=False,
show_legend_key=False,
show_values=True,
show_series_name=False,
)
# Showing categories, percentages, and values
chart.plot(
df,
ws,
section_heading="Pie Chart: showing categories, percentages, and values",
show_percentage=True,
show_category=True,
show_legend_key=False,
show_values=True,
show_series_name=False,
)
# Showing everything
chart.plot(
df,
ws,
section_heading="Pie Chart: showing everything",
show_percentage=True,
show_category=True,
show_legend_key=True,
show_values=True,
show_series_name=True,
title="This is a custom title",
)
# Using Openpyxl default colors
chart.plot(
df,
ws,
section_heading="Pie Chart: openpyxl colors",
show_percentage=True,
show_category=False,
show_legend_key=False,
show_values=True,
show_series_name=False,
openpyxl_color=True,
)
file_name = os.path.join(
os.path.dirname(os.path.dirname(__file__)), "data", "pie_chart.xlsx"
)
wb.save(file_name)