Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

seaborn histplot modify legend

import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import seaborn as sns

df_dn = pd.DataFrame({'ktau': np.random.randn(4000).cumsum(),
                      'statind': np.repeat([*'abcd'], 1000)})

fig, ax1 = plt.subplots()
sp1 = sns.histplot(df_dn, x="ktau", hue="statind", hue_order=['a', 'b', 'c', 'd'],
                   element="step", stat="density", common_norm=True, fill=False, ax=ax1)
ax1.set_title(r'$d_n$')
ax1.set_xlabel(r'max($F_{a,max}$)')
ax1.set_ylabel(r'$	au_{ken}$')
legend = ax1.get_legend()
handles = legend.legendHandles
legend.remove()
ax1.legend(handles, ['dep-', 'ind-', 'ind+', 'dep+'], title='Stat.ind.')
plt.show()
Comment

sns histplot change legend labels

import seaborn as sns

# load the tips dataset
tips = sns.load_dataset("tips")
# plot
g = sns.lmplot(x="total_bill", y="tip", hue="smoker", data=tips, markers=["o", "x"], facet_kws={'legend_out': True})
# title
new_title = 'My title'
g._legend.set_title(new_title)
# replace labels
new_labels = ['label 1', 'label 2']
for t, l in zip(g._legend.texts, new_labels):
    t.set_text(l)
Comment

PREVIOUS NEXT
Code Example
Python :: python order by date 
Python :: python find largest variable 
Python :: openai python 
Python :: python make an object hashable 
Python :: Python NumPy repeat Function Syntax 
Python :: python multiline comment 
Python :: run flask in debug mode 
Python :: while loop python 
Python :: tab of nbextensions not showing in jupyter notebook 
Python :: remove element from dictionary python 
Python :: python bit shift by 3 
Python :: python count items in list 
Python :: python null 
Python :: read csv pandas 
Python :: django render template 
Python :: read json file using python 
Python :: check if a value is nan pandas 
Python :: combination of 1 2 3 4 5 python 
Python :: catalan number 
Python :: how to access dataframe row by datetime index 
Python :: index of a string index dataframe 
Python :: who created python 
Python :: How to join two dataframes by 2 columns so they have only the common rows? 
Python :: python read file into variable 
Python :: python dictionary default 
Python :: python code with sigma 
Python :: discord python tts 
Python :: how to extract words from string in python 
Python :: python series 
Python :: class python 
ADD CONTENT
Topic
Content
Source link
Name
7+6 =