1. <strong id="7actg"></strong>
    2. <table id="7actg"></table>

    3. <address id="7actg"></address>
      <address id="7actg"></address>
      1. <object id="7actg"><tt id="7actg"></tt></object>

        牛批了,1 行 Python 代碼就可實現(xiàn)炫酷可視化

        共 1959字,需瀏覽 4分鐘

         ·

        2020-12-08 14:05


        之前畫圖一直在用 matlibplot、pyecharts,最近學習了一個新的可視化庫--cufflinks,用了兩天我已經(jīng)深深愛上它了

        主要是因為它用法簡單、圖形漂亮、代碼量少,用一兩行代碼,就能畫出非常漂亮的圖形

        下面我們一起來看看吧!

        1.用法簡單

        cufflinks庫主要和dataFrame數(shù)據(jù)結合使用,繪圖函數(shù)就是 dataFrame.iplot,記住這個就行了,但是 iplot 函數(shù)里的參數(shù)很多,一些參數(shù)說明如下:

        kind:圖的種類,如 scatter、pie、histogram 等mode:lines、markers、lines+markers,分別表示折線、點、折線和點colors:軌跡對應的顏色dash:軌跡對應的虛實線,solid、dash、dashdot 三種width:軌跡的粗細xTitle:橫坐標名稱yTitle:縱坐標的名稱title:圖表的標題

        如下圖,df為隨機生成的dataFrame數(shù)據(jù),kind='bar'表示柱狀圖,title代表標題,xTitle命名X軸,yTitle命名Y軸:

        import?pandas?as?pd
        import?numpy?as?np
        import?cufflinks?as?cf
        df=pd.DataFrame(np.random.rand(12,?4),?columns=['a',?'b',?'c',?'d'])
        df.iplot(kind?='bar',title='示例',?xTitle?=?'X軸',?yTitle?='Y軸')

        2.少量代碼就能畫出非常漂亮的圖形

        cufflinks為我們提供了豐富的主題樣式,支持包括polar、pearl、henanigans、solar、ggplot、space和white等7種主題。

        折線圖

        cf.datagen.lines(4,10).iplot(mode='lines+markers',theme='solar')

        cufflinks使用datagen生成隨機數(shù),figure定義為lines形式,cf.datagen.lines(2,10)的具體形式如下:

        cf.datagen.lines(2,10)??#2代表2組,10代表10天

        WCB.EHOAA.CQ
        2015-01-01-0.052580-0.351618
        2015-01-021.056254-1.476417
        2015-01-030.0780171.129168
        2015-01-040.2821410.908655
        2015-01-050.960537-0.223996
        2015-01-061.4203550.212851
        2015-01-072.2661440.358502
        2015-01-080.0080341.086130
        2015-01-091.8769462.226895
        2015-01-101.8556252.852383

        散點圖

        df?=?pd.DataFrame(np.random.rand(50,?4),?columns=['a',?'b',?'c',?'d'])
        df.iplot(kind='scatter',mode='markers',colors=['orange','teal','blue','yellow'],size=20,theme='solar')

        氣泡圖

        df.iplot(kind='bubble',x='a',y='b',size='c',theme='solar')

        subplots 子圖

        df=cf.datagen.lines(4)
        df.iplot(subplots=True,shape=(4,1),shared_xaxes=True,vertical_spacing=.02,fill=True,theme='ggplot')

        箱形圖

        cf.datagen.box(20).iplot(kind='box',legend=False,theme='ggplot')

        直方圖

        df.iloc[:,0:3].iplot(kind='histogram')

        3D圖

        cf.datagen.scatter3d(5,4).iplot(kind='scatter3d',x='x',y='y',z='z',text='text',categories='categories')

        怎么樣?是不是很方便,希望我的介紹能夠起到拋磚引玉的作用,cufflinks庫還有更豐富的繪圖功能等著你去挖掘。

        瀏覽 62
        點贊
        評論
        收藏
        分享

        手機掃一掃分享

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

        手機掃一掃分享

        分享
        舉報
        1. <strong id="7actg"></strong>
        2. <table id="7actg"></table>

        3. <address id="7actg"></address>
          <address id="7actg"></address>
          1. <object id="7actg"><tt id="7actg"></tt></object>
            亲孑伦XX Xⅹ熟女 | 歪歪色漫 | 国产日B大白奶美女 | 操逼毛片免费看 | 日本乱伦无码视频 | 美女自拍视频 | 国产高清一区 | www.色老板 | 熟妇综合| 特级西西444WWW视频 |