【问题标题】:Legend not dispalyed [duplicate]图例未显示[重复]
【发布时间】:2019-11-28 03:07:19
【问题描述】:

我正在尝试使用 matplotlib 在 python 中绘制一个简单的图形。我无法使用 pyplot.legend() 方法来显示图例。请帮助我。

我在网上查找了一个简单的代码,它说它有效:

import numpy as np
import matplotlib.pyplot as plt

# generate random data for plotting
x = np.linspace(0.0,100,50)
y = np.random.normal(size=50)

plt.plot(x,y)

# call method plt.legend
plt.legend(['line plot 1'])

plt.show()

来自网站 http://queirozf.com/entries/matplotlib-examples-displaying-and-configuring-legends.

我的代码如下:

import matplotlib.pyplot as plt
%matplotlib inline
views = [123,56,64,54,223,5523]
days = range(1,7)
plt.xlabel("Days")
plt.ylabel("Views")
plt.title("You Tube views")
plt.legend(["Youtube views"])
plt.plot(days,views)
plt.show()

【问题讨论】:

    标签: matplotlib legend title


    【解决方案1】:

    接下来写 plt.legend(["Youtube views"]) plt.plot(days,views)强>

    plt.xlabel("Days")
    plt.ylabel("Views")
    plt.title("You Tube views")
    plt.plot(days,views)
    plt.legend(["Youtube views"])
    plt.show()
    

    【讨论】:

      猜你喜欢
      • 2021-03-09
      • 2017-04-19
      • 2013-03-03
      • 1970-01-01
      • 2021-12-17
      • 2021-10-22
      • 2016-10-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多