[Python] Matplotlib showing chosen values instead of a normal range

Discussão em 'Python' iniciado por Stack, Maio 22, 2025.

  1. Stack

    Stack Membro Participativo

    I made a pretty simple script with python for a project, where i wanted to create a graph which shows water-production on the y-axis, and years on the x-axis. The graph is made by using a csv-file. However, for some reason the y-axis is only showing the chosen values for the x-values, instead of starting at 0 and increasing like usually. Basically it starts with 108 at the bottom, since that's the amount of produced water in the first year. Am i missing something? Here's my code:

    import pandas as pd
    import matplotlib.pyplot as plt
    filename = "Waterproduction.csv"
    data = pd.read_csv(filename, sep="\\t", encoding="Latin-1", engine="python")
    year = data.iloc[:, 0]
    water =data.iloc[:, 2]
    plt.figure()
    plt.plot(year, water, marker='o')
    plt.xlabel("Years")
    plt.ylabel("Waterproduction (mill. m³)")
    plt.title("Waterproduction")
    plt.show()

    Continue reading...

Compartilhe esta Página