A simple plot with a legend made with matplotlib produces the following: the markers at the left of the labels of my legend appear twice. Can anyone know why and how to avoid the problem? My command is:
pl.plot(x1,x2,'g^', label='regional')
pl.plot(y1,y2,'bo', label='local')
pl.legend( loc='upper left' )
Thank you
You can change the number of markers shown in the legend by using the
numpointskeyword:I believe the reason the markers appear twice (by default) is because matplotlib is trying to show the linestyle connectors between the markers. It looks a little odd when there is no connector.
If the plot had solid and dashed lines,
then the legend looks like this:
and now you can see the effect of the linestyle between the markers in the legend (as well as on the graph).
If you don’t want any legend handle at all, then you could use
For example,
You could use
to remove the legend marker as well.