matplotlib的plot()和pandas plot()之间的区别? [英] Difference between matplotlib's plot() and pandas plot()?
本文介绍了matplotlib的plot()和pandas plot()之间的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
matplotlib.pyplot.plot()
和pandas.DataFrame.plot()
有什么区别?
我们可以同时使用两者进行绘图,但是两者之间的度量差异是多少?
We can plot using both but what is the measure difference between both?
如何绘制条形图并按分类变量分组?
How can i draw bar chart and group by some categorical variable?
推荐答案
Matplotlib的pyplot是熊猫在其plot函数中使用的库.熊猫的情节只是方便的捷径. 对于条形图的问题:我建议使用Seaborn的 barplot ,类别为色调. 如果您只想使用熊猫,那么也许是这样的:
Matplotlib's pyplot is the library that Pandas use in their plot function. Pandas' plot is only a convenient shortcut. For the bar chart question: I would suggest using Seaborn's barplot, using the desired category as hue. If you wish to only use Pandas, then maybe something like:
df = pd.DataFrame(np.random.rand(10, 1), columns=['col_name'])
df['category'] = df.col_name>0.5
print(df)
col_name category
0 0.053908 False
1 0.136295 False
2 0.325790 False
3 0.362942 False
4 0.919924 True
5 0.406884 False
6 0.433959 False
7 0.725699 True
8 0.582537 True
9 0.608040 True
df.groupby('category').count().plot(kind='bar', legend=False)
这篇关于matplotlib的plot()和pandas plot()之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文