y = [10,3,2,5,7,3] x = [1,2,3,4,5,6] names = ["Apples", "Bananas", "Cherries", "Orages", 'Kiwi','Others'] plt.figure() plt.bar(y) plt.xticks(x, labels=names) plt.show()
时间: 2024-03-20 11:39:37 浏览: 43
series-sum.zip_4 3 2 1_series求和
这段代码存在问题,需要进行修改才能正常运行。可以尝试以下修改:
```
import matplotlib.pyplot as plt
y = [10,3,2,5,7,3]
x = [1,2,3,4,5,6]
names = ["Apples", "Bananas", "Cherries", "Oranges", 'Kiwi','Others']
plt.figure()
plt.bar(x,y)
plt.xticks(x, labels=names)
plt.show()
```
修改后的代码会生成一个柱状图,横坐标为水果名称,纵坐标为对应水果的数量。
阅读全文