从数据集在 seaborn 的线图中创建多条线
Creating multiple lines in lineplot in seaborn from dataset
我有一个大数据集,我想在 seaborn 中将其绘制为线图。
我的数据集由不同数据中特定植物的不同测量值组成,所以基本上我想将数据集中的每一行绘制为折线图中的一条线,正如我试图在此图像中演示的那样:
为了这个目标,我尝试将 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'
不知道怎么解决
这是我最终想要得到的产品:
转置你的 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])
结果:
我认为破折号样式列表的默认长度是6。如果你想要更多样式,你必须手动定义它们并通过以下方式添加它们:
dash_styles = ["",
(4, 1.5),
(1, 1),
(3, 1, 1.5, 1),
(5, 1, 1, 1),
(5, 1, 2, 1, 2, 1),
(2, 2, 3, 1.5),
(1, 2.5, 3, 1.2),
# etc
]
sns.lineplot(..., dashes=dash_styles,...)
只需输入 dashes=False,它应该可以解决您的问题,然后您可以使用各种参数在此基础上进行构建。
sns.lineplot(data=df, dashes = False)
我有一个大数据集,我想在 seaborn 中将其绘制为线图。
我的数据集由不同数据中特定植物的不同测量值组成,所以基本上我想将数据集中的每一行绘制为折线图中的一条线,正如我试图在此图像中演示的那样:
为了这个目标,我尝试将 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'
不知道怎么解决
这是我最终想要得到的产品:
转置你的 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])
结果:
我认为破折号样式列表的默认长度是6。如果你想要更多样式,你必须手动定义它们并通过以下方式添加它们:
dash_styles = ["",
(4, 1.5),
(1, 1),
(3, 1, 1.5, 1),
(5, 1, 1, 1),
(5, 1, 2, 1, 2, 1),
(2, 2, 3, 1.5),
(1, 2.5, 3, 1.2),
# etc
]
sns.lineplot(..., dashes=dash_styles,...)
只需输入 dashes=False,它应该可以解决您的问题,然后您可以使用各种参数在此基础上进行构建。
sns.lineplot(data=df, dashes = False)