【问题标题】:How to show all dates in the axis of a line plot seaborn?如何在线图seaborn的轴上显示所有日期?
【发布时间】:2020-03-26 08:54:00
【问题描述】:

我正在尝试使用 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)

【问题讨论】:

    标签: python matplotlib seaborn


    【解决方案1】:

    您可以更改 x 轴 tick locator

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

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

    【讨论】:

    • Diziet 爵士,您非常乐于助人。谢谢你帮助我。
    猜你喜欢
    • 2019-06-08
    • 2020-09-03
    • 1970-01-01
    • 2018-01-02
    • 2017-06-10
    • 2017-10-28
    相关资源
    最近更新 更多