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 :: data type of none in python 
Python :: # Import KNeighborsClassifier from sklearn.neighbors 
Python :: convert uppercase to lowercase and vice versa in python 
Python :: uninstall python kali linux 
Python :: python printing 
Python :: == in python 
Python :: receipt data extraction python 
Python :: python if else interview questions 
Python :: pandas dataframe apply function with multiple arguments 
Python :: python builtwith 
Python :: image analysis python 
Python :: first n prime number finder in python 
Python :: How to sum a column in Python csv 
Python :: class views django slug 
Python :: how to remove last element from a list python 
Python :: how to get the user argent in django 
Python :: restricting user access to web pages 
Python :: print something after sec python 
Python :: eror api/kernelsUntitled.ipynb?kernel_name=python3 
Python :: Convert the below Series to pandas datetime : DoB = pd.Series(["07Sep59","01Jan55","15Dec47","11Jul42"]) 
Python :: python prime number 
Python :: python coding for y, you will also display a “bar” of ‘X’ characters to represent the number. For example, the prime number 2 would be represented as “X 2”. 
Shell :: pip install django storages 
Shell :: upgrade pip 
Shell :: install sklearn with conda 
Shell :: upgrade pillow version 
Shell :: docker rm all containers 
Shell :: How to restart Ubuntu via SSH? 
Shell :: conda install sklearn 
Shell :: installing ncurses library 
ADD CONTENT
Topic
Content
Source link
Name
3+8 =