简体   繁体   English

X 和 Y 必须具有相同的第一个维度

[英]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.我正在尝试将 2 个数据合并到一个图表中,但我无法这样做,并且不断收到 X 和 Y 必须具有相同的第一维的值错误。 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.似乎 Y 中记录的长度/数量约为 100,但 X 的长度约为 10。假设 X 是年份,并且您想要 plot 一张关于气体排放随时间变化的图表,您只需要获得最后 12 项Y,假设 Y 中的最后一项是 2020 年的气体排放量。一个简单的解决方案是 Y = Y[-12:],因为 X 的长度是 12。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Python的简单与复合兴趣; “ x和y必须具有相同的第一尺寸” - Simple & Compounded Interest with Python; “x and y must have the same first dimensions” x和y必须具有相同的第一尺寸,但形状为(30,)和(1,) - x and y must have same first dimension, but have shapes (30,) and (1,) ValueError:x 和 y 必须具有相同的第一维,但具有形状 (6,) 和 (8,) - ValueError: x and y must have same first dimension, but have shapes (6,) and (8,) ValueError:x 和 y 必须具有相同的第一维,但具有形状 (1, 2) 和 (2,) - ValueError: x and y must have same first dimension, but have shapes (1, 2) and (2,) ValueError:x 和 y 必须具有相同的第一维,但具有形状 - ValueError: x and y must have same first dimension, but have shapes 输入错误,然后输入值错误:x 和 y 必须具有相同的第一维 - Type error, and then ValueError: x and y must have same first dimension Python ValueError:x 和 y 必须具有相同的第一维 - Python ValueError: x and y must have same first dimension 值错误:x和y必须具有相同的第一维 - Value Error: x and y must have the same first dimension 错误:x 和 y 必须具有相同的第一维 - Error: x and y must have the same first dimension 编辑:绘制 function,x 和 y 必须具有相同的第一维 - EDIT:plotting the function, x and y must have the same first dimension
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM