0

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

enter image description here 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.

enter image description here

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" )
mpx
  • 3,081
  • 2
  • 26
  • 56

1 Answers1

1

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()

Output

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" )

Output1

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" )

Output2

Jay Patel
  • 1,374
  • 1
  • 8
  • 17
  • Thanks for the suggestion jay, can you please check the edited post as other issue still remain – mpx Mar 04 '21 at 04:36
  • Hi @jay, appreciate if you can share some thought about the issue post in this link: https://stackoverflow.com/questions/66469403/how-to-shift-suptitle-in-seaborn-displot – mpx Mar 04 '21 at 06:29