[Python] Python - Pyplot x-axis not showing on graph

Discussão em 'Python' iniciado por Stack, Março 17, 2025.

  1. Stack

    Stack Membro Participativo

    pyplot is not showing the x-axis on the graph:

    import pandas as pd
    import matplotlib.pyplot as plt

    df = pd.read_csv('sitka_weather_2014.csv')

    df['AKST'] = pd.to_datetime(df.AKST)
    df['Dates'] = df['AKST'].dt.strftime('%b %d, %Y')
    df.set_index("Dates", inplace= True)

    # Plot Data
    fig = plt.figure(dpi=256, figsize=(14, 7))
    plt.title("Daily high and low temperature - 2014")

    df['Max TemperatureF'].plot(linewidth=1, c='blue', label="Max Temperature °F")
    df['Min TemperatureF'].plot(linewidth=1, c='red', label="Min Temperature °F")

    plt.grid(True)
    plt.rc('grid', linestyle=":", linewidth=1, color='gray')

    plt.legend(loc='upper left')

    plt.xlabel('', fontsize=10)
    plt.ylabel("Temperature (°F)", fontsize=10)
    plt.tick_params(axis='both', which='major', labelsize=10)
    fig.autofmt_xdate(rotation=45)

    plt.show()


    The x-axis should be the index of the Pandas Dataframe (df) containing the dates.

    [​IMG]

    Continue reading...

Compartilhe esta Página