The objective is to have subsets of plot on different facets which is achievable as below.
import seaborn as sns
import matplotlib.pyplot as plt
iris = sns.load_dataset("iris")
sns.displot ( data=iris, x='petal_width', col='species', col_wrap=2, bw_adjust=0.5,
kind="kde", rug=True)
plt.xticks ( fontsize=14, rotation=45, ha="right" )
plt.show()
which produce
However, I notice the
x-tick
rendering is not consistent between the top and bottom of the graph,upon setting the xticks
to 45
,
edit: Thanks to OP , the tick is now properly rotate 45 deg. However, the suggestion still have an issue when setting the xticks label. Specifically, the font size is not consistent.
The above graph was produced via the code below
import seaborn as sns
import matplotlib.pyplot as plt
iris = sns.load_dataset("iris")
g=sns.displot ( data=iris, x='petal_width', col='species', col_wrap=2, bw_adjust=0.5,
kind="kde", rug=True)
g.set_xticklabels(rotation=45)
header_name =['1a','1b','1c','1d']
value_tick = [0.5,1,1.5,3]
g.set_xticklabels ( rotation=45 )
plt.xticks ( fontsize=14, ticks=value_tick, labels=header_name, ha="right" )
Do you want all x-ticks
at 45 rotation? If yes then just try below code,
import seaborn as sns
import matplotlib.pyplot as plt
iris = sns.load_dataset("iris")
g = sns.displot ( data=iris, x='petal_width', col='species', col_wrap=2, bw_adjust=0.5,
kind="kde", rug=True);
g.set_xticklabels(rotation=45)
# plt.gca().set_xticks("fontsize"="14", "rotation":"45", "ha":"right" )
plt.show()
Edited: You can set fontsize
in the set_xticks
function itself. Refer below example:
import seaborn as sns
import matplotlib.pyplot as plt
iris = sns.load_dataset("iris")
g=sns.displot ( data=iris, x='petal_width', col='species', col_wrap=2, bw_adjust=0.5,
kind="kde", rug=True)
header_name =['1a','1b','1c','1d']
value_tick = [0.5,1,1.5,3]
g.set_xticklabels (fontsize=14, rotation=45 )
plt.xticks(ticks=value_tick, labels=header_name, ha="right" )
I would really recommend if you want to change the fontsize
for sns plot
use its own built-in functionality sns.set()
. That is way much easier.
import seaborn as sns
import matplotlib.pyplot as plt
# set font size using sns
sns.set(font_scale=1.5) # crazy big
iris = sns.load_dataset("iris")
g = sns.displot ( data=iris, x='petal_width', col='species', col_wrap=2, bw_adjust=0.5,
kind="kde", rug=True)
header_name =['1a','1b','1c','1d']
value_tick = [0.5,1,1.5,3]
g.set_xticklabels (rotation=45 )
plt.xticks ( ticks=value_tick, labels=header_name, ha="right" )
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.