I am trying to plot my data on a chart with matplotlib but I keep getting an error that states that 12.7799 cannot be interpreted as a data type. It works when I take out the figure of the predicted gas prices but not when I include it in. I have tried to convert it to an int but the error still keeps showing up.
#Comparing Gas Prices in Ireland From 2021 & 2022 import time import matplotlib.pyplot as plt import numpy as np #The first number is the gas price in July of 2021 and the second number is the gas price in July of 2022 gp = [1.75, 2.13] diff = round(gp - gp, 2) diff1 = '€' + str(diff) percInc = round(((gp - gp) / gp) * 100, 2) percInc1 = str(percInc) + '%' print('Today we will be comparing the Gas Prices in Ireland from 2021 & 2022') time.sleep(4) print('Gas Prices in July 2021 were €1.75 per litre and in July 2022 were €2.13 per litre.') time.sleep(2) print('The difference in price between 2021 and 2022 is', diff1) time.sleep(2) print('The percentage increase in price was',percInc1) time.sleep(2) print('') print('Now it is your turn to predict the gas prices in 2023') userInf = int(input('Enter the inflation rate for the next year (whole number between -10 and 10: ')) gp1 = gp * userInf gp23 = gp1 + gp print('The predicted price for 2023 is', gp23) x = np.array(['2021', '2022', '2023']) y = np.array([gp, gp], gp23) #where problem occurs plt.title('Comparing Gas Prices in Ireland') plt.xlabel('Years') plt.ylabel('Prices') plt.bar(x,y, align='edge', width=-0.4) plt.show()
This is the error I am receiving
Traceback (most recent call last): File "main.py", line 30, in <module> y = np.array([gp, gp], gp23) TypeError: Cannot interpret '12.779999999999998' as a data type
Can anyone please help me identify the mistake?