[英]Plotting graph with Matplotlib
I have a Dataframe(153 rows X 2 columns) - with Column 1 - Complaint Type (String) and Column 2 - Count (int) 我有一个数据框(153行X 2列)-具有列1-投诉类型(字符串)和列2-计数(整数)
I need to plot this with y axis = count and x axis = complaint type(string) 我需要用y轴=计数和x轴=投诉类型(字符串)进行绘制
I saw an answer that i can use xticks to use string as my x axis labels - 我看到了一个答案,我可以使用xticks将字符串用作我的x轴标签-
x = np.array([0,1,2,3])
y = np.array([20,21,22,23])
my_xticks = ['John','Arnold','Mavis','Matt']
plt.xticks(x, my_xticks)
plt.plot(x, y)
plt.show()
But how can i plot when i don't even have integer/float values as my variables. 但是,当我什至没有整数/浮点值作为变量时,我该如何绘图。 I get Value Error: Cannot convert string to float. 我收到值错误:无法将字符串转换为浮点型。
如果需要条形图,可以调用df.plot.bar('Complaint Type', 'Count')
Use DataFrame.plot.bar
: 使用DataFrame.plot.bar
:
df.plot.bar(x='col1', y='col2')
Solution for lines with DataFrame.plot
: 使用DataFrame.plot
行的解决方案:
df.plot(x='col1', y='col2')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.