国产一级a片免费看高清,亚洲熟女中文字幕在线视频,黄三级高清在线播放,免费黄色视频在线看

打開APP
userphoto
未登錄

開通VIP,暢享免費(fèi)電子書等14項(xiàng)超值服

開通VIP
Python pandas更是可視化工具!

眾所周知pandas是一個(gè)Python很強(qiáng)大的數(shù)據(jù)處理工具,其實(shí),pandas更是一個(gè)強(qiáng)大的可視化工具,可以輕松將DataFrame、Series類別數(shù)據(jù)可視化展示。

本文簡(jiǎn)單介紹pandas常用支持圖表。

pandas可視化主要依賴下面兩個(gè)函數(shù):

  • pandas.DataFrame.plot
  • pandas.Series.plot

注意Dataframe和Series可視化的細(xì)微差異


本文目錄

0、準(zhǔn)備工作
1、單組折線圖
2、多組折線圖
3、單組條形圖
4、多組條形圖
5、堆積條形圖
6、水平堆積條形圖
7、直方圖
8、分面直方圖
9、箱圖
10、面積圖
11、堆積面積圖
12、散點(diǎn)圖
13、單組餅圖
14、多組餅圖
15、分面圖
16、hexbin圖
17、andrews_curves圖
18、核密度圖
19、parallel_coordinates圖
20、autocorrelation_plot圖
21、radviz圖
22、bootstrap_plot圖
23、子圖(subplot)
24、子圖任意排列
25、圖中繪制數(shù)據(jù)表格

0、準(zhǔn)備工作

導(dǎo)入依賴包

import matplotlib.pyplot as plt 
import numpy as np
import pandas as pd
from pandas import DataFrame,Series
plt.style.use('dark_background')#設(shè)置繪圖風(fēng)格

1、單組折線圖

np.random.seed(0)#使得每次生成的隨機(jī)數(shù)相同
ts = pd.Series(np.random.randn(1000), index=pd.date_range('1/1/2000', periods=1000))
ts1 = ts.cumsum()#累加
ts1.plot(kind='line')#默認(rèn)繪制折線圖

2、多組折線圖

np.random.seed(0)
df = pd.DataFrame(np.random.randn(10004), index=ts.index, columns=list('ABCD'))
df = df.cumsum()
df.plot()#默認(rèn)繪制折線圖

3、單組條形圖

df.iloc[5].plot(kind='bar')

4、多組條形圖

df2 = pd.DataFrame(np.random.rand(104), columns=['a''b''c''d'])
df2.plot.bar()

5、堆積條形圖

df2.plot.bar(stacked=True)

6、水平堆積條形圖

df2.plot.barh(stacked=True)

7、直方圖

df4 = pd.DataFrame(
    {
        'a': np.random.randn(1000) + 1,
        'b': np.random.randn(1000),
        'c': np.random.randn(1000) - 1,
    },
    columns=['a''b''c'],
)
df4.plot.hist(alpha=0.8)

8、分面直方圖

df.diff().hist(color='r', alpha=0.9, bins=50)

9、箱圖

df = pd.DataFrame(np.random.rand(105), columns=['A''B''C''D''E'])
df.plot.box()

10、面積圖

df = pd.DataFrame(np.random.rand(104), columns=['a''b''c''d'])
df.plot.area()

11、堆積面積圖

df.plot.area(stacked=False)

12、散點(diǎn)圖

ax = df.plot.scatter(x='a', y='b', color='r', label='Group 1',s=90)
df.plot.scatter(x='c', y='d', color='g', label='Group 2', ax=ax,s=90)

13、單組餅圖

series = pd.Series(3 * np.random.rand(4), index=['a''b''c''d'], name='series')
series.plot.pie(figsize=(66))

14、多組餅圖

df = pd.DataFrame(
    3 * np.random.rand(42), index=['a''b''c''d'], columns=['x''y']
)
df.plot.pie(subplots=True, figsize=(84))

15、分面圖

import matplotlib as mpl
mpl.rc_file_defaults()
plt.style.use('fivethirtyeight')
from pandas.plotting import scatter_matrix
df = pd.DataFrame(np.random.randn(10004), columns=['a''b''c''d'])
scatter_matrix(df, alpha=0.2, figsize=(66), diagonal='kde')
plt.show()

16、hexbin圖

df = pd.DataFrame(np.random.randn(10002), columns=['a''b'])
df['b'] = df['b'] + np.arange(1000)
df.plot.hexbin(x='a', y='b', gridsize=25)

17、andrews_curves圖

from pandas.plotting import andrews_curves
mpl.rc_file_defaults()
data = pd.read_csv('iris.data.txt')
plt.style.use('dark_background')
andrews_curves(data, 'Name')

18、核密度圖

ser = pd.Series(np.random.randn(1000))
ser.plot.kde()

19、parallel_coordinates圖

from pandas.plotting import parallel_coordinates
data = pd.read_csv('iris.data.txt')
plt.figure()
parallel_coordinates(data, 'Name')

20、autocorrelation_plot圖

from pandas.plotting import autocorrelation_plot
plt.figure();
spacing = np.linspace(-9 * np.pi, 9 * np.pi, num=1000)
data = pd.Series(0.7 * np.random.rand(1000) + 0.3 * np.sin(spacing))
autocorrelation_plot(data)

21、radviz圖

from pandas.plotting import radviz
data = pd.read_csv('iris.data.txt')
plt.figure()
radviz(data, 'Name')

22、bootstrap_plot圖

from pandas.plotting import bootstrap_plot
data = pd.Series(np.random.rand(1000))
bootstrap_plot(data, size=50, samples=500, color='grey')

23、子圖(subplot)

df = pd.DataFrame(np.random.randn(10004), index=ts.index, columns=list('ABCD'))
df.plot(subplots=True, figsize=(66))

24、子圖任意排列

df.plot(subplots=True, layout=(23), figsize=(66), sharex=False)
fig, axes = plt.subplots(44, figsize=(99))
plt.subplots_adjust(wspace=0.5, hspace=0.5)
target1 = [axes[0][0], axes[1][1], axes[2][2], axes[3][3]]
target2 = [axes[3][0], axes[2][1], axes[1][2], axes[0][3]]
df.plot(subplots=True, ax=target1, legend=False, sharex=False, sharey=False);
(-df).plot(subplots=True, ax=target2, legend=False, sharex=False, sharey=False)

25、圖中繪制數(shù)據(jù)表格

from pandas.plotting import table
mpl.rc_file_defaults()
#plt.style.use('dark_background')
fig, ax = plt.subplots(11)
table(ax, np.round(df.describe(), 2), loc='upper right', colWidths=[0.20.20.2]);
df.plot(ax=ax, ylim=(02), legend=None);

參考

https://pandas.pydata.org/pandas-docs/stable/user_guide/cookbook.html#cookbook-plotting

https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.plot.html?highlight=plot#pandas.DataFrame.plot

https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Series.plot.html?highlight=plot#pandas.Series.plot

-END-

微信交流

備注來意(交流、合作等等)

本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊舉報(bào)
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
Pandas進(jìn)階修煉120題,給你深度和廣度的船新體驗(yàn)
pandas可視化(2)【官方文檔解讀】-- 條形圖、直方圖
25000字玩轉(zhuǎn) Pandas, 這一篇給力了!
數(shù)據(jù)可視化干貨:使用pandas和seaborn制作炫酷圖表(附代碼)
學(xué)習(xí)pandas下的dataframe畫圖參數(shù)
用Python自動(dòng)實(shí)現(xiàn)圖表可視化操作,提高工作效率,又能有更多的時(shí)間摸魚了~
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長(zhǎng)圖 關(guān)注 下載文章
綁定賬號(hào)成功
后續(xù)可登錄賬號(hào)暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服