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 9187823
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T19:52:06+00:00 2026-06-17T19:52:06+00:00

In matplotlib, I am using a loop to plot a graph, with each step

  • 0

In matplotlib, I am using a loop to plot a graph, with each step only plotting one data point (X[index], Y[index]) with a specific color C[index], so that it will assign a color to each point. In total, I use 8 colors to represent my data points, so I hope I can have a legend with these 8 colors and each one represents one meaning.

This is my code. Thanks for help. : )

for index in range(0,len(X)):
  plt.plot(X[index],Y1[index], marker = 'o', markersize = 10, color = C[index])  
  plt.xlabel("the percentage of students' credit hours found in instructor data", fontsize=14, color ="blue")
  plt.ylabel("total number of writing assinments", fontsize=14, color="blue")
  plt.axis([0, 100, 0, max(Y1)]) 
plt.show()
  • 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-17T19:52:08+00:00Added an answer on June 17, 2026 at 7:52 pm

    An example straight from the matplotlib documentation:

    The kwargs can be used to set line properties (any property that has a set_* method). You can use this to set a line label (for auto legends), linewidth, anitialising, marker face color, etc. Here is an example:

        plot([1,2,3], [1,2,3], 'go-', label='line 1', linewidth=2)
        plot([1,2,3], [1,4,9], 'rs',  label='line 2')
        axis([0, 4, 0, 10])
        legend()
    

    So, if you set the label property for each line, you should just be able to call legend() afterwards and it will automagically generate the legend with appropriate labels.

    If you want to do something fancier with the legend, they also have documentation for that.

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

Sidebar

Related Questions

I'm using matplotlib to plot data as a function of time in hh:mm:ss.ms format
I am using matplotlib and Tkinter to plot some data. When I press a
I'm using matplotlib to plot some data as 2D curves in a 3D axes.
Hi I am trying to plot this using matplotlib's step function from matplotlib.pyplot import
I need to get a plot that fits the data automatically using matplotlib. This
Hi probably quite a simple question but.. When plotting a graph using matplotlib.pyplot my
I'm plotting a timeseries in pandas using matplotlib and I'm trying to color a
I am plotting 20 different lines on a single plot using matplotlib. I use
I am using matplotlib to fit some data to a grid and plot it
I'm trying to plot a graph in matplotlib using numpy and meshgrid. I want

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.