Matplotlib: Customize number of markers shown in legend

Matplotlib is a plotting library written in Python that can be used to create all sorts of plots. If markers are being used in the plot, then two markers at the end points of a line are shown in the legend.

You may want to customize the number of markers shown in the legend. For example, I like to have one marker shown in the middle of the line segments displayed in the legend.

To customize the number of markers shown in the legend assign that value to the named argument numpoints in the call to pyplot.legend():

matplotlib.pyplot.legend( ..., numpoints=1 )

Tried with: Matplotlib 1.2, Python 3.2.3 and Windows 7 x64

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.