简体   繁体   中英

X and Y must have same first dimensions

I'm trying to combine 2 data into one graph but I'm unable to do so and keep getting a value error that X and Y must have the same first dimension. Is there any alternative way?

plt.figure(figsize = (10, 6))
X=np.arange(2009,2020)
Y=plt.plot(Total_Energy["Years"],Total_Energy['Households'])
fig, ax = plt.subplots()

ax.plot(X,greenhouse[' Total Greenhouse Gas Emissions (Gg CO2-equivalent) '])
ax.plot(X, Y)

ax.title('Total Greenhouse Gas Emissions (Gg CO2-equivalent) ')
ax.ylabel('Gas Emission')
ax.xlabel('Households Energy Consumption')
plt.show()

It seems that the length of/the number of records in Y is around 100 but length of X is around 10.assuming X is the year and you want to plot a graph about gas emissions over time you need to get only last 12 items in Y, assuming the last item in Y is the gas emissions in year 2020.a simple solution is Y = Y[-12:] since the length of X is 12.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM