1

I am trying to set up an animation chart in Python. Although the code "works" the chart is not displaying correctly.

When you look at the chart image below, as well as the data being fed in, you can tell that the chart/line graph that is being displayed is wrong.

The line is just going up up and away. There are no curves, etc. Even if I change the number from May_20 to 1, there is no dip in the graph. What did I do wrong?

def animate(i):
    df = pd.read_csv('file.csv')
    x = df['Date']
    y = df['Total']

    plt.cla()
    plt.plot(x, y, label='Total')

    plt.legend(loc='upper left')
    plt.tight_layout()


ani = FuncAnimation(plt.gcf(), animate, interval = 1000)

plt.tight_layout()
plt.show()

enter image description here

The data being fed in.

Date    Total
Jan_17  12,193,384
Feb_17  11,876,118
Mar_17  11,807,975
Apr_17  11,736,527
May_17  11,815,081
Jun_17  11,879,709
Jul_17  11,998,967
Aug_17  12,437,756
Sep_17  12,111,544
Oct_17  11,948,991
Nov_17  12,310,696
Dec_17  11,770,820
Jan_18  11,422,438
Feb_18  11,204,254
Mar_18  11,926,069
Apr_18  11,843,334
May_18  12,167,640
Jun_18  12,429,465
july_18 12,509,135
Aug_18  12,688,543
Sept_18 12,688,280
Oct_18  12,953,325
Nov_18  13,251,454
Dec_18  13,475,415
Jan_19  13,451,599
Feb_19  13,175,903
Mar _19 14,247,926
Apr _19 14,534,655
May _19 15,622,414
June _19    15,918,351
July _19    16,224,364
Aug _19 16,134,419
Sep _19 16,503,324
Oct _19 16,575,575
Nov_19  17,586,592
Dec_19  16,991,059
Jan_20  16,992,251
Feb_20  16,590,248
Mar_20  15,835,819
Apr_20  16,585,744
May_20  16,564,219
June_20 16,346,281
July_20 17,168,203

After changing the values from strings to int... my chart now looks like this:

enter image description here

On the Y axis, the number 12,193,384 is being cut to just above the 1.2 mark. Is there a better way to represent these numbers?

letsCode
  • 2,774
  • 1
  • 13
  • 37

0 Answers0