如何使用matplotlib为n组4列的集合编制索引以打印多个绘图?

2024-09-25 08:40:07 发布

您现在位置:Python中文网/ 问答频道 /正文

我想知道如何用python编程方式索引/访问一些数据。 我有一组钻孔的柱状数据:深度,温度,梯度,伽马。有n个钻孔。我有一个标题,其中列出了钻孔名称和数字标识。例如:

Bore_name,Bore_ID,,,Bore_name,Bore_ID,,,, ... 
<a row of headers>
depth,temp,gradient,gamma,depth,temp,gradient,gamma ...

我不知道如何索引数据,除了粗鲁的迭代:

^{pr2}$

这种方式似乎很简单,但我最近一直在使用R,并且已经习惯了它们通过从头解释的类和子类引用数据对象的方式。在


Tags: 数据name名称id标题编程方式温度
3条回答

如果你喜欢R数据表,有一些(至少)尝试通过NumPy核心中的附加类和外部Python库在NumPy中重新创建该功能。我发现最有希望的是费尔南多·佩雷斯的图书馆。下面是它的工作原理。在

>>> # create a NumPy array for use as our data set
>>> import numpy as NP
>>> D = NP.random.randint(0, 10, 40).reshape(8, 5)

>>> # create some generic row and column names to pass to the constructor
>>> row_ids = [ "row{0}".format(c) for c in range(D1.shape[0]) ]
>>> rows = 'rows_id', row_ids

>>> variables = [ "col{0}".format(c) for c in range(D1.shape[1]) ]
>>> cols = 'variable', variables

实例化DataArray实例,方法是调用构造函数并传入一个普通的NumPy数组和一个元组列表,每个轴一个元组,由于ndim=2,列表中有两个元组,每个元组由axis label(str)和该轴的标签序列(list)组成。在

^{pr2}$

以下是命名行和列的习惯用法:

row0, row1 = np.ones((2,5))

for col in range(0, tdata.shape[1], 4):
   depth,temp,gradient,gamma = tdata[:, col:col+4] .T
   pl.plot( temp, depth )

另请参见namedtuple

^{pr2}$

datarray(谢谢道格)当然更一般。在

您可以将数据放入每个钻孔的dict,由钻孔id和值作为dicts,标题作为键。大致如下:

data = {boreid1:{"temp":temparray, ...}, boreid2:{"temp":temparray}}

使用这些方法,从文件中读取可能会有点麻烦,但是对于绘图,您可以做一些类似的事情

^{pr2}$

相关问题 更多 >