I want to read an Excel file, sum the values for the years 2021, 2020 and 2019 for the locations from the same region (region B) and then create a graph with two lines (for region A and B) which will show how the values for both regions have changed during the years.
I tried with this code:
import matplotlib.pyplot as plt
import pandas as pd
excel_file_path = "Testfile.xlsx"
df = pd.read_excel(excel_file_path)
x = ["2021", "2020", "2019"]
y1 = df_region["Values2021"]
y2 = df_region["Values2020"]
y3 = df_region["Values2019"]
fig = plt.figure(figsize=(20,5))
plt.plot(x, y1, color = 'red', label = "A")
plt.plot(x, y2, color = 'blue', label = "B")
plt.legend(loc='best')
plt.show()
But it isn't working for me - I get the following error:
"Exception has occurred: ValueError x and y must have same first dimension, but have shapes (3,) and (2,)"
What do I need to do to get the result that I want? Any help would be greatly appreciated.
