简体   繁体   English

条形图形状不匹配

[英]Bar Chart shape mismatch

I got this assignment about plotting a bar graph and a scatter plot using some excel sheet.我得到了关于使用一些 excel 表绘制条形图和散点图 plot 的任务。 The scatter plot works fine, but for some reason the bar graph is giving the shape mismatch error and I can't seem to figure out why, since I did the code a few days ago it seemed to work. scatter plot 工作正常,但由于某种原因,条形图给出了形状不匹配错误,我似乎无法弄清楚为什么,因为我几天前做了代码,它似乎工作。 This is the code:这是代码:

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

df=pd.read_excel('Salaries.xlsx',sheet_name='Salaries', header=1)

xl=[2,3,4]
y1=[5,5,5]
x2=[1,2,3,4,5]
y2=[2,3,2,3,4]
y3=[6,8,7,8,7]
plt.scatter(xl,y1)
plt.scatter(x2,y2,marker='s',color='r')
plt.scatter(x2,y3,marker='*',color='green')
plt.title('Scatter Plot Example')
plt.show

y1=[4,7,2,4,7,8,3]
x2=[2,4,6,8,10]
y2=[5,6,5,6,2]
plt.bar(xl,y1, label="Blue Bar", alpha=0.2, color='b')
plt.bar(x2,y2, label="Green Bar", alpha=0.3, color='g')
plt.plot()
plt.xlabel("Bar Number")
plt.ylabel("Bar Height")
plt.title("Bar Chart Test")
plt.legend()
plt.show()

It gives an error on the bar chart graph^, I'll attach a screenshot.它在条形图上给出错误^,我将附上屏幕截图。 Please help me fix this, Thank you请帮我解决这个问题,谢谢

The Error错误

Hi you've redefined only your y1, meaning your x1 is 3 long and your y1 is 7 long.嗨,您只重新定义了您的 y1,这意味着您的 x1 是 3 长,而您的 y1 是 7 长。 This is the source of your dimension mistmatch.这是您的尺寸不匹配的根源。

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

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