[英]How do I plot a .csv file as a bar graph correctly?
I have imported, successfully, a .csv file with film information and have begun the process of creating a bar graph to show each film's gross, with the gross as x-axis and the film title as the y-axis. 我已经成功导入了一个带有电影信息的.csv文件,并开始创建一个条形图来显示每部电影的粗体,粗略为x轴,电影标题为y轴。 I'm not sure why the code below is wrong. 我不确定为什么下面的代码是错误的。 Any help would be appreciated. 任何帮助,将不胜感激。
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
table = pd.read_csv('C:/Users/*****/Desktop/Python/Fav_Movies.csv')
plt.bar(x=np.arange(0,5),height=table['monies'])
plt.title("FILMS")
plt.xticks(np.arange(0,23), table['title'], rotation=50)
plt.xlabel("TITLE")
plt.ylabel("GROSS")
plt.show()
the error I get is 我得到的错误是
"ValueError: shape mismatch: objects cannot be broadcast to a single shape." “ValueError:形状不匹配:对象无法广播到单个形状。”
I have looked it up but I don't understand. 我查了一下,但我不明白。 Thanks. 谢谢。
将plt.bar行替换为:
plt.barh(table.title, table.monies, align='center')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.