Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8632015
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:17:42+00:00 2026-06-12T09:17:42+00:00

A simple plot with a legend made with matplotlib produces the following: the markers

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T09:17:43+00:00Added an answer on June 12, 2026 at 9:17 am

    You can change the number of markers shown in the legend by using the numpoints keyword:

    import matplotlib.pyplot as plt
    import numpy as np
    x1 = y1 = np.linspace(0, 10, 100)
    x2 = np.sin(x1)
    y2 = np.cos(y1)
    plt.plot(x1,x2,'g--^', label='regional')
    plt.plot(y1,y2,'b-o', label='local')
    plt.legend( loc='upper left', numpoints = 1 )
    plt.show()
    

    enter image description here


    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,

    plt.plot(x1,x2,'g--^', label='regional')
    plt.plot(y1,y2,'b-o', label='local')
    

    then the legend looks like this:

    enter image description here

    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

    plt.legend(..., handlelength=0)
    

    For example,

    import numpy as np
    import matplotlib.pyplot as plt
    
    x1 = y1 = np.linspace(0, 10, 100)
    x2 = np.sin(x1)
    y2 = np.cos(y1)
    plt.plot(x1,x2,'g--^', label='regional')
    plt.plot(y1,y2,'b-o', label='local')
    plt.legend(loc='best', numpoints=1, handlelength=0)
    plt.show()
    

    enter image description here

    You could use

    plt.legend(loc='best', numpoints=1, handlelength=0, 
               markerscale=0, handletextpad=0)
    

    to remove the legend marker as well.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For a simple plot below, is there a way to make matplotlib populate the
From the documentation for ggplot2's geom_tile() function, we have the following simple plot: #
I've created a simple hexbin plot with matplotlib.pyplot. I haven't changed any default settings.
I know I can create a 3D surface plot in MATLAB by doing: x
I am using matplotlib.pyplot.scatter to draw some simple scatter plot. However, something wrong appears
Does anyone know how I can get control of the ordering of legends in
Following works, (copy & paste into R) a=123 plot(1,1) legend('bottomleft',legend=bquote(theta == .(a))) I want
I'm trying to create a pretty simple scatter plot with two data series. I
Simple case of trying to prove I can convert NSString to NSDate . Create
Simple Inject is throwing the following exception when attempting to register my DbContext. The

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.