In seaborn lmplot function we have hue argument that will automatically draw a colorbar on the right side. How can I disable/remove the colorbar?
Here are a sample code that will generate a colorbar
df = pd.DataFrame({'x':[1,2,3,1,2,3,1,2,3],'y':[1,2,3,2,3,4,3,4,5],'color':['a','a','a','b','b','b','c','c','c']})
facets = sns.lmplot(data=df, x='x', y='y', hue='color', fit_reg=False)
facets.fig.show()
I tried to call the colorbar object and remove it. In the traditional matplotlib way we can use
collection = ax.scatter(x='a', y='b', data=df)
colorbar = fig.colorbar(collection)
to call it, but I can't see how it works for lmplot. Another alternative way is in sns.heatmap function, where it provides a cbar argument
sns.heatmap(crosstab, cbar=False)
But in lmplot there is not cbar option. What is the best way to do it in lmplot?
A colorbar in Matplotlib/Seaborn is actually like a legend but for continuous data (what you get in a heatmap). In this case, since you have discrete labels (a = blue, b = orange, c = green), you need to access the legend
. You can read about the distinction more in the Python Data Science Handbook
Most plot types in Seaborn now already support passing a legend
argument into the plot method, such as:
facets = sns.lmplot(data=df, x='x', y='y', hue='color', fit_reg=False, legend=False)
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.