【python】pandas & matplotlib 資料處理 繪製曲面圖

來源:互聯網
上載者:User

標籤:val   head   img   container   file   panel   tin   下載   tac   

Python matplotlib模組,是擴充的MATLAB的一個繪圖工具庫,它可以繪製各種圖形

建議安裝 Anaconda後使用 ,整合了很多第三庫,基本滿足大家的需求,,對應選擇python 2.7 或是 3.5 的就可以了:
 https://www.continuum.io/downloads#windows

指令碼預設執行方式:             1.擷取當前檔案夾下的1.log檔案             2.將資料格式化為矩陣             3.以矩陣的列索引為x座標,行索引為y座標,值為z座標             4.繪製曲面圖
測試資料
測試所用資料: r_gain= 79.000000f,  89.000000f, 104.000000f, 120.000000f, 135.000000f, 149.000000f, 160.000000f, 172.000000f, 176.000000f, 172.000000f, 164.000000f, 159.000000f, 143.000000f, 128.000000f, 113.000000f,  97.000000f,  81.000000f, r_gain= 84.000000f, 100.000000f, 120.000000f, 136.000000f, 156.000000f, 176.000000f, 192.000000f, 204.000000f, 208.000000f, 204.000000f, 196.000000f, 180.000000f, 164.000000f, 144.000000f, 124.000000f, 108.000000f,  92.000000f, r_gain= 91.000000f, 112.000000f, 132.000000f, 156.000000f, 176.000000f, 200.000000f, 224.000000f, 240.000000f, 248.000000f, 244.000000f, 228.000000f, 208.000000f, 188.000000f, 164.000000f, 140.000000f, 120.000000f,  99.000000f, r_gain= 99.000000f, 120.000000f, 144.000000f, 172.000000f, 200.000000f, 228.000000f, 256.000000f, 276.000000f, 284.000000f, 280.000000f, 264.000000f, 240.000000f, 208.000000f, 180.000000f, 156.000000f, 132.000000f, 105.000000f, r_gain=107.000000f, 128.000000f, 156.000000f, 184.000000f, 216.000000f, 256.000000f, 288.000000f, 308.000000f, 320.000000f, 316.000000f, 296.000000f, 264.000000f, 228.000000f, 196.000000f, 164.000000f, 140.000000f, 113.000000f, r_gain=111.000000f, 132.000000f, 160.000000f, 192.000000f, 232.000000f, 272.000000f, 304.000000f, 332.000000f, 340.000000f, 336.000000f, 316.000000f, 284.000000f, 244.000000f, 204.000000f, 172.000000f, 144.000000f, 117.000000f, r_gain=109.000000f, 136.000000f, 164.000000f, 196.000000f, 232.000000f, 276.000000f, 312.000000f, 336.000000f, 348.000000f, 344.000000f, 320.000000f, 288.000000f, 248.000000f, 208.000000f, 172.000000f, 144.000000f, 117.000000f, r_gain=111.000000f, 132.000000f, 160.000000f, 192.000000f, 228.000000f, 268.000000f, 304.000000f, 328.000000f, 340.000000f, 332.000000f, 312.000000f, 280.000000f, 240.000000f, 200.000000f, 168.000000f, 140.000000f, 119.000000f, r_gain=101.000000f, 128.000000f, 152.000000f, 180.000000f, 212.000000f, 248.000000f, 280.000000f, 304.000000f, 312.000000f, 308.000000f, 288.000000f, 260.000000f, 224.000000f, 192.000000f, 160.000000f, 136.000000f, 109.000000f, r_gain= 95.000000f, 116.000000f, 140.000000f, 164.000000f, 192.000000f, 224.000000f, 248.000000f, 272.000000f, 280.000000f, 272.000000f, 256.000000f, 232.000000f, 200.000000f, 176.000000f, 152.000000f, 128.000000f, 101.000000f, r_gain= 87.000000f, 108.000000f, 128.000000f, 148.000000f, 172.000000f, 192.000000f, 216.000000f, 232.000000f, 236.000000f, 232.000000f, 220.000000f, 200.000000f, 180.000000f, 156.000000f, 136.000000f, 116.000000f,  95.000000f, r_gain= 80.000000f,  96.000000f, 112.000000f, 132.000000f, 148.000000f, 168.000000f, 180.000000f, 192.000000f, 196.000000f, 196.000000f, 184.000000f, 172.000000f, 156.000000f, 136.000000f, 120.000000f, 104.000000f,  88.000000f, r_gain= 69.000000f,  85.000000f,  96.000000f, 111.000000f, 127.000000f, 141.000000f, 153.000000f, 160.000000f, 164.000000f, 159.000000f, 157.000000f, 145.000000f, 135.000000f, 120.000000f, 104.000000f,  88.000000f,  77.000000f,

曲面圖指令碼
# -*- coding: utf-8 -*- from matplotlib import pyplot as pltfrom mpl_toolkits.mplot3d import Axes3Dfrom pandas import DataFrame  def draw(x, y, z):    ‘‘‘    採用matplolib繪製曲面圖    :param x: x軸座標數組    :param y: y軸座標數組    :param z: z軸座標數組    :return:    ‘‘‘    X = x    Y = y    Z = z     fig = plt.figure()    ax = fig.add_subplot(111, projection=‘3d‘)    ax.plot_trisurf(X, Y, Z)    plt.show() if __name__ == ‘__main__‘:    ‘‘‘       預設執行方式:             1.擷取當前檔案夾下的1.log檔案             2.將資料格式化為矩陣             3.以矩陣的列索引為x座標,行索引為y座標,值為z座標             4.繪製曲面圖    ‘‘‘    data = {}    index_origin = 0    f = open("1.log")    line = f.readline()    while line:        data[index_origin] = line.split(‘=‘)[-1].replace(‘ ‘, ‘‘).split(‘f,‘)[0:-1]        index_origin = index_origin + 1        line = f.readline()    f.close()    df = DataFrame(data)    df = df.T     x = []    for i in range(len(df.index)):        x = x + list(df.columns)    print(x)     y = []    for i in range(len(df.index)):        for m in range(17):            y.append(i)    print(y)     z = []    for i in range(len(df.index)):        z = z + df[i:i + 1].values.tolist()[0]    z = map(float, z)    print (z)    draw(x, y, z)

【python】pandas & matplotlib 資料處理 繪製曲面圖

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.