Open roberthsu2003 opened 1 month ago
Python code:
# How to draw pie chart ?
# Please visit https://matplotlib.org/stable/api/_as_gen/matplotlib.axes.Axes.pie.html
import matplotlib.pyplot as plt
def main():
labels:list = ['Nokia', 'Samsung', 'Apple', 'Lumia']
values:list = [20, 30, 45, 10]
colors:list = ['yellow', 'green', 'red', 'blue']
# 把 Nokia 切出來
explode = (0.3, 0, 0, 0)
fig = plt.figure(figsize=(4.9, 4.15))
axes = fig.add_subplot()
axes.pie(
values,
center=(0.25, 0.1),
radius=1.3,
labels=labels,
colors=colors,
shadow=True,
startangle=180.0,
explode=explode,
autopct='%1.1f%%')
plt.show()
if __name__ == "__main__":
main()
Result:
labels = ['Nokia', 'Samsung', 'Apple', 'Lumia'] values = [20, 30, 45, 10] colors = ['yellow', 'green', 'red', 'blue']
import matplotlib.pyplot as plt
def main():
labels = ['Nokia', 'Samsung', 'Apple', 'Lumia']
values = [20, 30, 45, 10]
colors = ['yellow', 'green', 'red', 'blue']
figure = plt.figure(figsize=(5.0,5.0))
axes = figure.add_subplot()
axes.pie(values,explode=[0.3,0,0,0], labels=labels, colors=colors, autopct='%1.1f%%', shadow=1, startangle=180)
plt.show()
if __name__ == '__main__':
main()
import matplotlib.pyplot as plt
labels = ['Nokia', 'Samsung', 'Apple', 'Lumia']
values = [20, 30, 45, 10]
explode = (0.2, 0, 0, 0)
fig, ax = plt.subplots()
ax.pie(values, labels=labels,explode=explode,autopct='%1.1f%%',
shadow=True,startangle=180,
colors=['yellow', 'green', 'red', 'blue'])
plt.show()
import matplotlib.pyplot as plt
labels = ['Nokia', 'Samsung', 'Apple', 'Lumia']
values = [20, 30, 45, 10]
colors = ['yellow', 'green', 'red', 'blue']
explode = (0.3, 0, 0, 0)
plt.pie(values, explode=explode, labels=labels, colors=colors, autopct='%1.1f%%', startangle=180, shadow=True)
plt.axis('equal')
plt.show()
pie文件說明