I am trying to change the default color scheme used by Seaborn on plots, I just want something simple, for instance the HLS scheme shown on their documentation. However their methods don't seem to work, and I can only assume that's due to my use of "hue" but I cannot figure out how to make it work properly. Here's the current code, datain is just a text file of the correct number of columns of numbers, with p as an indexing value:
import pandas as pd
import numpy as np
datain = np.loadtxt("data.txt")
df = pd.DataFrame(data = datain, columns = ["t","p","x","y","z"])
ax3 = sns.lineplot("t", "x", sns.color_palette("hls"), data = df[df['p'].isin([0,1,2,3,4])], hue = "p")
plt.show()
The code plots the first few data sets out of a file, and they come out in that weird purple pastel choice that seaborn seems to default to if I don't include the sns.color_palette function. If I include it I get the error:
TypeError: lineplot() got multiple values for keyword argument 'hue'
Which seems a bit odd given the format accepted for the lineplot function.
First thing: You need to stick to the correct syntax. A palette is supplied via the palette
argument. Just putting it as the third argument of lineplot
will let it be interpreted as the third argument of lineplot
which happens to be hue
.
Then you will need to make sure the palette has as many colors as you have different p
values.
import seaborn as sns
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
datain = np.c_[np.arange(50),
np.tile(range(5),10),
np.linspace(0,1)+np.tile(range(5),10)/0.02]
df = pd.DataFrame(data = datain, columns = ["t","p","x"])
ax = sns.lineplot("t", "x", data = df, hue = "p",
palette=sns.color_palette("hls", len(df['p'].unique())))
plt.show()