I want to create a custom scatter legend. I want it to show a single point in the legend, so I am using scatterpoints=1
. However it still plots 2-points and a line between them.
from matplotlib.patches import Patch
from matplotlib.lines import Line2D
markers = ['^', 's']
legend_elements=[Line2D([0], [0], marker=m, label=str(t)) for m,t in zip(markers,[1,2])]
plt.legend(handles=legend_elements, scatterpoints=1)
plt.show()
This is the result I get.
I suspect that the problem is caused because I use Line2D
, but I can't find another object to create the legend.
I am following instructions from: https://matplotlib.org/gallery/text_labels_and_annotations/custom_legends.html
Environment
- CentOS 7
- matplotlib 1.5.0
- Python 2.7.11 :: Anaconda 2.4.1 (64-bit)