My following code:
import numpy as np
from matplotlib import pyplot as plt
from matplotlib.pyplot import legend as legend
x = np.matrix(
[
[1, 1, 1, 1],
[2, 2, 2, 2],
[3, 3, 3, 3],
[4, 4, 4, 4]
]
)
y = x.transpose()
xx = x
yy = y+0.2
# Vertical Lines of grid:
plt.plot(x, y, 'b-o', label='data1')
plt.plot(xx, yy, 'r-*', label='data2')
legend()
plt.show()
generates figures looking like
I'd like to do two things:
- stop the legend from duplicating it self; it should only show each label once; something like
- position the legend nicely; say put it upper right corner with no overlap with the content of the graph
Easy/elegant solution is really appreciated. Thanks a lot.