plt.plot()和object.plot()有什么区别 [英] what's the difference between plt.plot(), object.plot()

查看:93
本文介绍了plt.plot()和object.plot()有什么区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我做了一个清单

> Book_of_Death_Count

1.0    49
2.0    73
3.0    97
4.0    27
5.0    61
Name: Book of Death, dtype: int64*

当我键入

a = Book_of_Death_Count.plot(),
b = plt.plot(Book_of_Death_Count)

两者的结果相同,但是:

The result of the two is the same, but:

  • a.set_xticks(np.arange(1,6))有效;

b.set_xticks(np.arange(1,6)) 不起作用.

这两个代码有什么区别?

What's the difference of these two code?

推荐答案

你的列表"是一个 熊猫DataFrame 对象.当您调用 Book_of_Death_Count.plot() 时,您正在使用函数 该类的所有方法.

your "list" is a pandas DataFrame object. When you call Book_of_Death_Count.plot() you are using the function DataFrame.plot(), which returns (in most cases) an Axes object. Therefore a is of Type Axes and you can use it to access all the methods of that class.

使用 <代码>plt.plot(),返回值是Line2D 对象.如果您需要访问Axes对象(例如,修改刻度线),请使用a = plt.gca().

这篇关于plt.plot()和object.plot()有什么区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆