Python 没有图例的 Pandas plot()

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20865487/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-18 21:25:50  来源:igfitidea点击:

Pandas plot() without a legend

pythonpandasplot

提问by Bilal Syed Hussain

Using the pandas library in python and using

在python中使用pandas库并使用

.plot()

on a dataframe, how do I display the plot without a legend?

在数据框上,如何显示没有图例的图?

采纳答案by Nipun Batra

There is a parameter in the function corresponding to legend; by default it is True

图例对应的函数中有一个参数;默认情况下它是 True

df.plot(legend=False)

Following is the definition of the .plot()method

下面是.plot()方法的定义

Definition: df.plot(frame=None, x=None, y=None, subplots=False, sharex=True, sharey=False, use_index=True, figsize=None, grid=None, legend=True, rot=None, ax=None, style=None, title=None, xlim=None, ylim=None, logx=False, logy=False, xticks=None, yticks=None, kind='line', sort_columns=False, fontsize=None, secondary_y=False, **kwds)

定义:df.plot(frame=None, x=None, y=None, subplots=False, sharex=True, sharey=False, use_index=True, figsize=None, grid=None, legend=True, rot=None, ax=None, style=None, title=None, xlim=None, ylim=None, logx=False, logy=False, xticks=None, yticks=None, kind='line', sort_columns=False, fontsize=None, secondary_y=False, **kwds)

回答by ImportanceOfBeingErnest

In order to remove a legend that has once been drawn, use

为了删除曾经绘制的图例,请使用

plt.gca().get_legend().remove()

assuming that you have imported matplotlib.pyplot as pltor

假设你已经import编辑matplotlib.pyplot as plt

ax.get_legend().remove()

if axis the axes where the legend resides.

ifax是图例所在的轴。

Alternatively, see Nipun Batras answer if there is some choice to turn the legend off from the beginning in which case one can simply use

或者,如果有一些选择从一开始就关闭图例,请参阅 Nipun Batras 回答,在这种情况下,可以简单地使用

df.plot(legend=False)