2016-06-30 27 views
9

Il stripplot seaborn ha una funzione che consente hue.AttributeError: legenda proprietà sconosciuta in seaborn

Utilizzando l'esempio da https://stanford.edu/~mwaskom/software/seaborn/generated/seaborn.stripplot.html

import seaborn as sns 
sns.set_style("whitegrid") 
tips = sns.load_dataset("tips") 
ax = sns.stripplot(x=tips["total_bill"]) 
ax = sns.stripplot(x="sex", y="total_bill", hue="day", data=tips, jitter=True) 

enter image description here

In questo caso, la leggenda è piuttosto piccolo, mostrando un colore diverso per ogni giorno. Tuttavia, vorrei rimuovere la legenda.

Di norma, uno include un parametro legend=False. Tuttavia, per stripplot, questo sembra uscita un errore di attributo:

AttributeError: Unknown property legend 

si può rimuovere la leggenda per stripplots? Se è così, come si fa?

+0

Eventuali duplicati di [? Spostare Seaborn leggenda complotto per una posizione diversa] (http://stackoverflow.com/questions/27019079/move-seaborn -plot-legend-to-a-a-different-position) –

+0

@EliSadoff Sono un po 'lento: come rimuovi completamente la legenda? – ShanZhengYang

risposta

22

Usa ax.legend_.remove() come qui:

import seaborn as sns 
import matplotlib.pylab as plt 
sns.set_style("whitegrid") 
tips = sns.load_dataset("tips") 
ax = sns.stripplot(x="sex", y="total_bill", hue="day", data=tips, jitter=True) 

# remove legend from axis 'ax' 
ax.legend_.remove() 

plt.show() 

enter image description here

+0

Grazie per questo! – ShanZhengYang

Problemi correlati