I am plotting a bunch of lines using seaborn to color them based on a variable, then I've done some peakfinding to label the specific peaks. For some reason, sns.lineplot works exactly as expected, however, when trying to use sns.scatterplot with almost identical parameters it throws a value error about my colors being unsupported.
Versions for packages I think are relevent: python: 3.8.10 matplotlib: 3.4.3 seaborn: 0.11.2 pandas: 1.3.0 numpy: 1.21.0
minimum reproducible example:
# imports
import pandas as pd
import numpy as np
import seaborn as sns
from scipy import signal
import matplotlib.pyplot as plt
# generate some data
x=np.arange(0,10,0.1)
y=np.sin(x)
df_test1 = pd.DataFrame({'x': x,
'y':y,
'color': ['Penguin']*50 ['Octopus']*50})
# find peaks from the data that we want to mark on our graph
df_test2 = pd.DataFrame()
for c in df_test1['color'].unique():
data = pd.DataFrame()
pks = signal.find_peaks(df_test1.loc[df_test1['color']==c, 'y'],
height=0.2, width=2)
data['x'] = df_test1.loc[df_test1['color']==c,'x'].iloc[pks[0]]
data['Height'] = pks[1]['peak_heights']
data['color'] = c
df_test2 = pd.concat([df_test2, data], ignore_index=True)
# printing the peaks dataframe just to confirm there are things to plot.
print(df_test2)
fig, axes = plt.subplots(1, 2, figsize=(8,8), sharey='row', sharex=True)
# plotting the line I want - this works
sns.lineplot(data=df_test1, x='x', y='y', hue='color', estimator=None, legend=False, ax=axes[0])
sns.lineplot(data=df_test1, x='x', y='y', hue='color', estimator=None, legend=False, ax=axes[1])
# labeling the peaks - This is where I get my error
sns.scatterplot(data=df_test2, x='x', y='Height', hue='color', style='color', legend=False, ax=axes[0])
# the work around I found is comment out the line above, and run the line below:
sns.lineplot(data=df_test2, x='x', y='Height', hue='color', estimator=None, legend=False, ax=axes[1],
markers=True, marker='X', linestyle='',)
fig.tight_layout()
plt.show()
In making a minimal reproducible example I found a workaround, but I'm wondering if this is a seaborn bug or something I am misunderstanding. I also spent a lot of time searching for a solution, so I'm hoping this post can help someone else in the same boat.
Edit: Removed the estimator parameter (as per Trenton) and still the same error. I'll try updating my seaborn and matplotlib though.
Edit2: Updating seaborn and matplotlib worked, so my guess is that there was a bug that got corrected.
CodePudding user response:
Updating seaborn and matplotlib worked, so my guess is that there was a bug that got corrected.