【问题标题】:How reduce number of xlims?如何减少 xlims 的数量?
【发布时间】:2019-06-10 04:34:03
【问题描述】:

我想减少 xlim 标签,因为我使用的是日期时间信息,并且占用了 xlim 的较长空间。问题是我想读那个

所以我需要一些类似的东西来扩展它,我想

dates = pd.read_csv("EURUSDtest.csv")
dates = dates["Date"]+" " + dates["Time"]
plt.title("EUR/USD")
plt.plot(dates, data_pred)
plt.xticks(rotation="vertical")
plt.tick_params(labelsize=10)
plt.plot(forecasting)

问题...

【问题讨论】:

    标签: python pandas datetime matplotlib


    【解决方案1】:

    IIUC:您需要通过调用pd.to_datetime将日期列转换为pandas日期时间类型。

    import pandas as pd
    import numpy as np
    import matplotlib.pyplot as plt
    # To reproduce the issue you have lets create a date column as string
    df = pd.DataFrame({"Dates":pd.date_range(start='2018-1-1', end='2019-1-1', freq='15MIN').strftime("%m-%d-%Y %H-%M-%S")})
    # Convert the date string to date type 
    df["Dates"] = pd.to_datetime(df["Dates"])
    # Add column to assign some dummy values
    df = df.assign(VAL=np.linspace(10, 110, len(df)))
    # Plot the graph
    # Now the graph automatically adjusts the XLIM based on the size of the graph
    plt.title("eur/usd")
    plt.plot(df["Dates"], df["VAL"])
    plt.xticks(rotation="vertical")
    plt.show()
    

    但是,如果您需要根据自己的需要进一步控制 xlim,则需要阅读 matplotlib 教程。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-11-19
      • 1970-01-01
      • 1970-01-01
      • 2016-09-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多