【问题标题】:Data file plot and over plot using AxesGrid toolkit使用 AxesGrid 工具包绘制数据文件和过图
【发布时间】:2014-08-28 19:49:11
【问题描述】:

我有一个数据文件,类似于:

 X   Y   Density
 0   0   2.366
 0   1   3.365
 1   0   6.325
 1   1   36.65

我想读取这类数据并使用matplotlib AxesGrid 绘制它。

绘制该数据后,我想在该图上过度绘制(即同一图中的两个密度场)类似类型的数据文件。谁能给我一个简单的python脚本?

【问题讨论】:

    标签: python matplotlib


    【解决方案1】:

    您可以使用普通方式读取文件

    f = open("yourfile.txt", "r")
    f.readlines()
    

    或者你可以使用 numpy

    import numpy as np
    x,y,z = np.loadtxt("yourfile.txt", skiprows=1).transpose() #skiprows to skip the headings
    

    为什么需要 AxesGrid?如果你所有的文件都和你发布的一样,那么你可以用

    import matplotlib.pyplot as plt
    plt.imshow(z.reshape(2,2), interpolation="nearest")
    plt.show()
    

    清除剧情

    plt.clf()
    

    然后重新绘制你想要的任何东西。

    【讨论】:

      猜你喜欢
      • 2021-06-06
      • 2020-08-07
      • 1970-01-01
      • 2010-09-25
      • 1970-01-01
      • 2023-03-04
      • 1970-01-01
      • 1970-01-01
      • 2015-12-21
      相关资源
      最近更新 更多