gpt4 book ai didi

python - 从数据集在 seaborn 的线图中创建多条线

转载 作者:行者123 更新时间:2023-12-01 21:51:27 25 4
gpt4 key购买 nike

我有一个大数据集,我想在 seaborn 中将其绘制为线图。

我的数据集由不同数据中特定植物的不同测量值组成,所以基本上我想将数据集中的每一行绘制为折线图中的一条线,正如我在这张图片中尝试展示的那样:

enter image description here

为了这个目标,我尝试在下一个代码中使用 seaborn:

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns

####THERE WAS MORE PROCESSING OF THE DATA THAT I BELIEVE IS IRRELEVANT

####Here I have tried to determine what I want in my axis. I haven't really use the value wavelength

#X axis
wavelength=new_db.columns.values[5:]

#y axis- values
#basically the outcome of this suppose to be a table with only values when ach row represents a hour
colum=new_db.columns.tolist()
new_db=new_db[cols[1:]]

#here i'm trying to create the plot
sns.set(style="whitegrid")
sns.lineplot(data=new_db, palette="tab10", linewidth=2.5)

#ERROR

ValueError: These style levels are missing dashes: set(['747.5', '814.81', '842.44', '906.34', '433.71', '667.2', '431.09', '512.97', '850.75', '882.67', '751.61', '911.92', '601.11', '847.98', '917.5', '828.61', '679.4', '440.29', '705.21', '729.74', '421.9', '959.5', '648.26', '956.69', '446.87', '445.55', '727.01', '605.14', '506.33', '856.29', '531.58', '889.63', '576.97', '924.49', '503.68', '897.98', '707.93', '970.73', '953.89', '839.67', '510.31', '678.04', '772.17', '473.24', '659.08', '813.43', '442.92', '781.78', '688.9', '623.98', '684.82', '634.76', '834.14', '955.29', '575.63', '589.03', '817.57', '474.56', '638.81', '935.68', '454.77', '571.62', '871.55', '587.69', '987.61'...............

(原始消息更长,数字更多。)

我也试过用这个来创建它:

sns.set(style="whitegrid")
ax = sns.lineplot(x="wavelength", y="new_db")

但是出现了这个错误:

ValueError: Could not interpret input 'wavelength'

我不知道怎么解决。

这是我最终想要得到的产品:

enter image description here

最佳答案

转置你的 DataFrame 怎么样?

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns

df = pd.DataFrame(np.random.rand(3, 10)).T
print(df)

数据框:

          0         1         2
0 0.341005 0.925077 0.541746
1 0.324769 0.558320 0.902804
2 0.647871 0.630663 0.607212
3 0.722298 0.745091 0.630445
4 0.209836 0.386576 0.076790
5 0.347911 0.237178 0.446102
6 0.174991 0.777129 0.109934
7 0.022564 0.388223 0.464438
8 0.359771 0.722761 0.837942
9 0.091696 0.474859 0.840078

情节

sns.lineplot(data=df.iloc[:, :2])

结果:

enter image description here

关于python - 从数据集在 seaborn 的线图中创建多条线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59375456/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com