[英]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.