<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          Pandas一行代碼繪制26種美圖

          共 6550字,需瀏覽 14分鐘

           ·

          2021-09-03 17:47

          本文目錄
          1、單組折線圖2、多組折線圖3、單組條形圖4、多組條形圖5、堆積條形圖6、水平堆積條形圖7、直方圖8、分面直方圖9、箱圖10、面積圖11、堆積面積圖12、散點圖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ù)表格27、更多pandas可視化精進資料

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

          • pandas.DataFrame.plot

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

          • pandas.Series.plot

          https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Series.plot.html?highlight=plot#pandas.Series.plot
          可繪制下面幾種圖,注意Dataframe和Series的細微差異:'area', 'bar', 'barh', 'box', 'density', 'hexbin', 'hist', 'kde', 'line', 'pie', 'scatter'導入依賴包

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

          1、單組折線圖

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

          2、多組折線圖

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

          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、散點圖

          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);

          27、更多pandas可視化精進資料

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

          -END-

          推薦閱讀:

          Pandas中的寶藏函數(shù)-transform

          Pandas中的寶藏函數(shù)-map

          Pandas中的寶藏函數(shù)-apply

          Pandas中的寶藏函數(shù)-applymap

          Pandas中的寶藏函數(shù)-agg()

          一文搞懂Pandas數(shù)據(jù)排序

          Pandas缺失值處理-判斷和刪除

          一網(wǎng)打盡Pandas中的各種索引 iloc,loc,ix,iat,at,直接索引


          一、Number(數(shù)字)
          全面掌握Python基礎,這一篇就夠了,建議收藏
          Python基礎之數(shù)字(Number)超級詳解
          Python隨機模塊22個函數(shù)詳解
          Python數(shù)學math模塊55個函數(shù)詳解
          二、String(字符串)
          Python字符串的45個方法詳解
          Pandas向量化字符串操作
          三、List(列表)
          超級詳解系列-Python列表全面解析
          Python輕量級循環(huán)-列表推導式
          四、Tuple(元組)
          Python的元組,沒想象的那么簡單
          五、Set(集合)
          全面理解Python集合,17個方法全解,看完就夠了
          六、Dictionary(字典)
          Python字典詳解-超級完整版
          七、內(nèi)置函數(shù)
          Python初學者必須吃透這69個內(nèi)置函數(shù)!
          八、正則模塊
          Python正則表達式入門到入魔
          筆記 | 史上最全的正則表達式
          八、系統(tǒng)操作
          Python之shutil模塊11個常用函數(shù)詳解
          Python之OS模塊39個常用函數(shù)詳解
          九、進階模塊
          【萬字長文詳解】Python庫collections,讓你擊敗99%的Pythoner
          高手如何在Python中使用collections模塊

          掃描關注本號↓

          瀏覽 64
          點贊
          評論
          收藏
          分享

          手機掃一掃分享

          分享
          舉報
          評論
          圖片
          表情
          推薦
          點贊
          評論
          收藏
          分享

          手機掃一掃分享

          分享
          舉報
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  亚洲中文第一页 | 色色激情 | 国产一区二区三区乱伦 | 暴操网站 | 北条麻妃无码一区二区 |