/ Python And R Data science skills: 74 Legend in metplotlib plots

Sunday 18 February 2018

74 Legend in metplotlib plots

https://vlrtraining.com/courses/python-data-science-beginner-tutorial 74 Legend in metplotlib plots
In [2]:
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(0, 5, 11)
y = x ** 2 
%matplotlib inline
In [29]:
fig = plt.figure()

ax = fig.add_axes([0,0,1,1])

ax.plot(x, y,"r")
ax.plot(y, x,"g")
#ax.legend()
Out[29]:
[<matplotlib.lines.Line2D at 0xb9255c0>]
In [31]:
fig = plt.figure()

ax = fig.add_axes([0,0,1,1])

ax.plot(x, y,"g")
ax.plot(y, x,"r")
ax.legend()
No handles with labels found to put in legend.
Out[31]:
<matplotlib.legend.Legend at 0xa861128>
In [32]:
fig = plt.figure()

ax = fig.add_axes([0,0,1,1])

ax.plot(x, y,"g",label="x,y")
ax.plot(y, x,"r",label="y,x")
ax.legend()
Out[32]:
<matplotlib.legend.Legend at 0x8190ac8>
In [33]:
fig = plt.figure()

ax = fig.add_axes([0,0,1,1])

ax.plot(x, y,label="x,y")
ax.plot(y, x,label="y,x")
ax.legend(loc=4)
Out[33]:
<matplotlib.legend.Legend at 0xb95c358>
In [34]:
fig = plt.figure()

ax = fig.add_axes([0,0,1,1])

ax.plot(x, y,label="x,y")
ax.plot(y, x,label="y,x")
ax.legend(loc=5)
Out[34]:
<matplotlib.legend.Legend at 0xa7f8f60>
In [36]:
fig = plt.figure()

ax = fig.add_axes([0,0,1,1])

ax.plot(x, y,label="x,y")
ax.plot(y, x,label="y,x")
ax.legend(loc=(0.4,0.2))
Out[36]:
<matplotlib.legend.Legend at 0xba25550>
In [37]:
fig = plt.figure()

ax = fig.add_axes([0,0,1,1])

ax.plot(x, x**2, label="x**2")
ax.plot(x, x**3, label="x**3")
ax.legend()
Out[37]:
<matplotlib.legend.Legend at 0xba8f3c8>

No comments:

Post a Comment