1. 程式人生 > 實用技巧 >Python資料視覺化:畫餅狀圖、折線圖、圈圖

Python資料視覺化:畫餅狀圖、折線圖、圈圖

前言

本文的文字及圖片來源於網路,僅供學習、交流使用,不具有任何商業用途,版權歸原作者所有,如有問題請及時聯絡我們以作處理。

from math import pi
import matplotlib.pyplot as plt cat = ['Speed', 'Reliability', 'Comfort', 'Safety', 'Effieciency']
values = [90, 60, 65, 70, 40] N = len(cat) x_as = [n / float(N) * 2 * pi for n in range(N)] ax = plt.subplot(111) plt.xticks(x_as) ax.plot(x_as, values, linewidth=1, linestyle='solid', zorder=3)
plt.show()

import matplotlib.pyplot as plt
from palettable.colorbrewer.qualitative import Pastel1_7
my_dpi=96
plt.figure(figsize=(480/my_dpi, 480/my_dpi), dpi=my_dpi) names='groupA', 'groupB', 'groupC', 'groupD',
size=[12,11,3,30] my_circle=plt.Circle( (0,0), 0.7, color='white') plt.pie(size, labels=names, colors=Pastel1_7.hex_colors)
p=plt.gcf()
p.gca().add_artist(my_circle)
plt.show()

import pandas as pd
import matplotlib.pyplot as plt
df = pd.DataFrame([8,8,1,2], index=['a', 'b', 'c', 'd'], columns=['x'])
my_dpi=96
plt.figure(figsize=(480/my_dpi, 480/my_dpi), dpi=my_dpi)
df.plot(kind='pie', subplots=True, figsize=(8, 8))
plt.show()