如何更改海运图形级图的每个方面(子图)中标题的旋转。
我想把标签在顶部旋转90度,去掉底部的标签。
import seaborn as sns
sns.set_theme(style="whitegrid")
df = sns.load_dataset("exercise")
# Draw a pointplot to show pulse as a function of three categorical factors
g = sns.catplot(x="time", y="pulse", hue="kind", col="diet",
capsize=.2, palette="YlGnBu_d", height=6, aspect=.75,
kind="point", data=df)
g.despine(left=True)
发布于 2022-07-12 06:47:33
matplotlib.axes
方法。.get_title
获取现有标题,然后在.set_title
中使用rotation=
。python 3.10
**,** matplotlib 3.5.1
**,** seaborn 0.11.2
中测试的import seaborn as sns
df = sns.load_dataset("exercise")
# Draw a pointplot to show pulse as a function of three categorical factors
g = sns.catplot(x="time", y="pulse", hue="kind", col="diet",
capsize=.2, palette="YlGnBu_d", height=6, aspect=.75,
kind="point", data=df)
g.despine(left=True)
# rotate the xtick labels
g.set_xticklabels(rotation=30)
# flatten the array of axes for easy iteration and usage
axes = g.axes.flat
# rotate the titles by iterating through each axes
for ax in axes:
# get the current title
title = ax.get_title()
# set the title and rotate the text
ax.set_title(title, rotation=90)
# remove the yticks from the right Facet
axes[1].tick_params(left=False)
# remove all the xlabels
g.set(xlabel=None)
.get_xticklabels
和.set_xticklabels
来旋转xtick标签。import seaborn as sns
df = sns.load_dataset("exercise")
# Draw a pointplot to show pulse as a function of three categorical factors
ax = sns.pointplot(x="time", y="pulse", hue="kind", col="diet", capsize=.2, palette="YlGnBu_d", data=df)
# remove spines
ax.spines[['left', 'right', 'top']].set_visible(False)
# rotate the xtick labels
ax.set_xticklabels(labels=ax.get_xticklabels(), rotation=30)
# set the title and rotate the text
ax.set_title('Diet: Low/No Fat', rotation=90)
# move the legend
sns.move_legend(ax, bbox_to_anchor=(1.25, 0.5), loc='center right', frameon=False)
# remove the xlabels
ax.set(xlabel=None)
https://stackoverflow.com/questions/72953702
复制相似问题