pandas學習筆記(十一):繪圖(Plotting)

(1)我們使用標準的matplotlib API參考來繪製數據圖表

import matplotlib.pyplot as plt
plt.close('all')
ts = pd.Series(np.random.randn(10),index=pd.date_range('21/6/2020',periods=10))
ts = ts.cumsum()
ts.plot()

在這裏插入圖片描述

ts = pd.Series(np.random.randn(1000),index=pd.date_range('21/6/2020',periods=1000))
ts.plot()

在這裏插入圖片描述

df = pd.DataFrame(np.random.randn(1000, 5), index=ts.index, columns=['Golang', 'C', 'Asm', 'Js','Py'])
df = df.cumsum()
plt.figure()
df.plot()
plt.legend(loc='best')

在這裏插入圖片描述

from matplotlib.ticker import FuncFormatter

data = {'Barton LLC': 109438.50,
        'Frami, Hills and Schmidt': 103569.59,
        'Fritsch, Russel and Anderson': 112214.71,
        'Jerde-Hilpert': 112591.43,
        'Keeling LLC': 100934.30,
        'Koepp Ltd': 103660.54,
        'Kulas Inc': 137351.96,
        'Trantow-Barrows': 123381.38,
        'White-Trantow': 135841.99,
        'Will LLC': 104437.60}
group_data = list(data.values())
group_names = list(data.keys())
group_mean = np.mean(group_data)
fig, ax = plt.subplots()
ax.barh(group_names, group_data)

在這裏插入圖片描述

由於maplotlib的API太多,這裏就不一一列舉出來,還是到官網去查看效果要好的多,官網有很多的例子供參考

  • matplotlib官網網址:https://matplotlib.org/
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章