如何在线状图的轴上显示所有日期?

时间:2020-03-26 08:54:00

标签: python matplotlib seaborn

我正在尝试使用seaborn绘制线图,并在我附加的图像链接中 似乎它没有在x轴上显示所需的日期(每天)。如何修复此图表?

%matplotlib inline
import matplotlib as mpl
import matplotlib.pyplot as plt
mpl.style.use(['ggplot'])
import seaborn as sns
sns.set_style("whitegrid")

fig, g = plt.subplots(figsize = (20,6))
g = sns.lineplot(x="photosim_date", y="tdpower_mean", hue="tool_id", style="tool_id", data=df1, dashes=False, ax=g)
plt.ylim(80,140)
plt.title("L8 PhotoSIM SDET TDP Data")
plt.show(g)

enter image description here

1 个答案:

答案 0 :(得分:0)

您可以更改x轴tick locator

loc = matplotlib.dates.DayLocator(bymonthday=range(1,32))
ax.xaxis.set_major_locator(loc)

请注意,在这种情况下,轴标签很可能会重叠。您可以使用fig.autofmt_xdate()自动旋转标签。