2

I have a big dataset that I would like to plot as a line plot in seaborn.

My dataset is consisted of different measurments of specific plant that were taken in different data, so basically I would like to plot each row in my dataset as one line in the line plot as I have tried to demonstrate in this image:

enter image description here

For that goal I have tried to use seaborn with the next code:

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'...............

(The original message was much longer with more numbers.)

I have tried also to create it with this:

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

but got this error:

ValueError: Could not interpret input 'wavelength'

I don't know how to solve it.

This is the prosuct I would like to get in the end:

enter image description here

3 Answers 3

4

How about transposing you 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)

DataFrame:

          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

Plot

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

Result:

enter image description here

Sign up to request clarification or add additional context in comments.

2 Comments

that looks good and the transposing worked though I don't know what it really does. Could you change theoretically the names in the legend?
It basically swaps the rows and columns. Add df.columns = ['label 1', 'label 2', 'label 3'] before plotting to add names in the legend.
2

I think the default len for dash styles list is 6. If you want more styles, you have to define them manually and add them through:

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,...)

1 Comment

Can you elaborate on the logic of how to create the dash_styles? I am not able to understand it.
1

Just put dashes=False and it should solve your issue and then you can build on that using the various parameters.

sns.lineplot(data=df,  dashes = False)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.