python - 绘制 DataFrame 字典

标签 python dictionary pandas matplotlib

我有一个 dictionaryDataFrames我想用于绘图。这是数据的示例:

import pandas as pd
import numpy as np

np.random.seed(5)
first = pd.DataFrame(columns=range(1,4),data=np.random.rand(3,3), index=range(1,4))
second = pd.DataFrame(columns=range(1,4),data=np.random.rand(3,3)+0.2, index=range(1,4))
third = pd.DataFrame(columns=range(1,4),data=np.random.rand(3,3)+0.05, index=range(1,4))
fourth= pd.DataFrame(columns=range(1,4),data=np.random.rand(3,3)-0.2, index=range(1,4))

d={'frame_1':first,'frame_2':second,'frame_3':third,'frame_4':fourth}

#This is what it looks like
d
    {'frame_1':           1         2         3
 1  0.221993  0.870732  0.206719
 2  0.918611  0.488411  0.611744
 3  0.765908  0.518418  0.296801, 'frame_2':           1         2         3
 1  0.387721  0.280741  0.938440
 2  0.641309  0.358310  1.079937
 3  0.474086  0.614235  0.496080, 'frame_3':           1         2         3
 1  0.678788  0.629838  0.649929
 2  0.315819  0.334686  0.303588
 3  0.377564  0.194164  0.215613, 'frame_4':           1         2         3
 1  0.763931  0.760227 -0.011585
 2 -0.175693  0.004556  0.499844
 3  0.579515 -0.177067  0.377663}

最终,我想要 9 个单独的图表,这些图表绘制了 DataFrame 中每个元素组合的演变情况。 (11,12,13,..) 以 1,2,3,4(与“frame_1”、“frame_2”等相关)为 x 轴。需要明确的是,这意味着第一个图(与 11 相关)应包含值 0.221993、0.387721、0.678788 和 0.763931。

通常我总是解释我自己试图解决的问题。但是,在这种情况下,我对可能的解决方案一无所知。

注意:实际数据集为 10x10 DataFramesdictionary包含 75 个这样的数据帧,所以我更喜欢尽可能多的自动化。

最佳答案

我不确定我是否理解您想要的结果,但是:

for k in d:
    ax = d[k].plot()
给出:
enter image description here
enter image description here
enter image description here

关于python - 绘制 DataFrame 字典,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33166414/

相关文章:

python - AWS python Lambda 无法访问 EFS 文件

python - 重新训练 MobileNet SSD V1 COCO 后,Tensorflow 的 pb 和 pbtxt 文件不适用于 OpenCV

python - 在 Python 3 中使用 Python 2 字典比较

python - 根据数据框中的列创建虚拟列

python - 获取创建的对象将被赋予的属性名称

python - xpath 不包含 A 和 B

python - 读取后使用不同的行作为 pandas 中的标签

python - 根据列值突出显示数据框中的行?

r - 是否可以在 R 中使用类似字典的对象将一个字符串映射到另一个字符串?

python - 我正在尝试计算 txt 文件中的所有字母,然后按降序显示