简体   繁体   中英

Seaborn lineplot hue input could not be interpreted

I am trying to plot my dataframe as a lineplot. The data is 2D movement data of x and y coordinates. The dataframe has a column which identifies the data of each individual by a unique ID and a column that identifies the test group of the individual and an additional relevant column that shows the timepoints.

    index  Location_Center_Y  unique_id Location_Center_X    classifier
0       0            872.044  B21                     0.000      ctrl
1       1            868.727  B21                    -3.317      ctrl
2       2            864.918  B21                    -7.126      ctrl
3       3            866.462  B21                    -5.582      ctrl

I do want to display the data of each individual in a lineplot and want the lines to have different colours based on the test group. Getting each individual as a single track I achieved by plotting the data of each individual at a time.

I tried using the input units='unique_id' but this unfortunately only works for seaborn.scatterplot. When using it with seaborn.lineplot it raises the error "ValueError: Could not interpret input 'unique_id'" But whatever, looping works. However I want it coloured by the different groups (classifier column). This should be doable by using the input argument hue='classifier'.

#looping through the individuals
for n in data.cells:
    ix=data.tracks[data.tracks['unique_id']==n]
    ax=sns.lineplot(ix['Location_Center_X_Zeroed'],
    ix['Location_Center_Y_Zeroed'], hue='classifier')

However, again this raises the error "ValueError: Could not interpret input 'unique_id'". So I have no idea how to group my plot.

I should get something like this but with only 2 colours

It's hard to be sure since you didn't provide enough data for me to directly try it out, but it seems like this is what you are looking for?

sns.lineplot(data=df, x='Location_Center_X', y='Location_Center_Y', 
             hue='classifier', units="unique_id", estimator=None)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM