0

I am trying to draw a simple graph in python using matplotlib.I am not able to use pyplot.legend() method to display legend.Please help me.

I looked on the net and found a simple code which says it works:

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()

from the site http://queirozf.com/entries/matplotlib-examples-displaying-and-configuring-legends.

My code is below:

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()
Siong Thye Goh
  • 3,518
  • 10
  • 23
  • 31

1 Answers1

0

Write plt.legend(["Youtube views"]) next 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()
Andrea Mannari
  • 982
  • 1
  • 6
  • 9