"Python" Pandas & matplotlib Data processing drawing surface plots

Source: Internet
Author: User

Python matplotlib module, a drawing tool library for extended Matlab, that can draw a variety of graphics

It is recommended to install Anaconda after use, integration of a lot of third library, basically meet the needs of everyone, the corresponding choice Python 2.7 or 3.5 of the can:
https://www.continuum.io/downloads#windows

脚本默认执行方式:             1.获取当前文件夹下的1.log文件             2.将数据格式化为矩阵             3.以矩阵的列索引为x坐标,行索引为y坐标,值为z坐标             4.绘制曲面图
test Data
测试所用数据: 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,

Surface Chart Scripts
# -*- coding: utf-8 -*-from matplotlib import pyplot as pltfrom mpl_toolkits.mplot3d import Axes3Dfrom pandas import DataFramedef 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 Data processing drawing surface plots

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.