seaborn x label日期格式的aldign,星期几的缩写

问题描述 投票:0回答:1

如何将星期几的缩写调整为同一水平?当前,它是交替的。

ta-

import pandas as pd
import seaborn as sns; sns.set()

df = pd.DataFrame({'dt':['2020-01-01', '2020-01-02', '2020-01-03', '2020-01-04'], 'foo':[10, 15, 8, 13]})
df['dt'] = pd.to_datetime(df['dt'])
display(df)

ax = sns.lineplot(x='dt', y='foo', data=df)

import matplotlib.dates as mdates
date_form = DateFormatter("%a %d-%m")
ax.xaxis.set_major_formatter(date_form)
ax.xaxis.set_major_locator(mdates.DayLocator(interval=1))
plt.xticks(rotation=90, horizontalalignment='center', fontsize=28)
''
python matplotlib seaborn date-format
1个回答
1
投票

最简单的对齐刻度标签起始位置的方法是旋转另一种方式:

plt.xticks(rotation=-90, ha='center', fontsize=28)

rotated clockwise

或者,刻度线标签可以垂直对齐到底部,但随后需要向下移动。确切的距离取决于字体,字体大小和文本长度:

plt.xticks(rotation=90, ha='center', va='bottom', fontsize=28)
plt.tick_params(axis='x', which='major', pad=150)

rotated anti clockwise

© www.soinside.com 2019 - 2024. All rights reserved.