【发布时间】: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