Issue
I don't understand what I am doing wrong here. I want to change 0 and 1 in the legend to "zero" and "one" but somehow this changes colour in the legend as well.
This is how I get to the first picture:
sns.scatterplot(ax = axes, data = data_pcoa, x = "Coordinate 0",
y = "Coordinate 1", hue = "Number", palette = ["orange", "blue"])
axes.set(xlabel = "1st PCo", ylabel = "2nd PCo")
axes.legend()
This is how I get to the second picture:
sns.scatterplot(ax = axes, data = data_pcoa, x = "Coordinate 0",
y = "Coordinate 1", hue = "Number", palette = ["orange", "blue"])
axes.set(xlabel = "1st PCo", ylabel = "2nd PCo")
axes.legend(labels = ['zero', 'one'])
As you can see, in the second picture the legend titles have changed but the colours no longer match those of the plot.
Solution
I solved the problem by creating a custom legend. This is not very elegant but it does the job. It is weird though, because when I use the axes.legend(labels = ["zero", "one"]
on a similar dataset it does work. Anyhow, this solved my problem (but I would love to know a more elegant solution):
legend_elements = [Line2D([0], [0], color = 'w', markerfacecolor = 'b', marker = 'o', label='one', markersize=8),
Line2D([0], [0], color = 'w', markerfacecolor = 'orange', marker='o', label='zero', markersize=8)]
Answered By - JonnDough
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.