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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:48:22+00:00 2026-05-28T06:48:22+00:00

I have an array of y-values that form a line. Additionally, I have an

  • 0

I have an array of y-values that form a line. Additionally, I have an array with the same number of elements as the y-array of values ranging from 0 to 1. We’ll call this array ‘z’. I want to plot the array of y-values so that the color of each point corresponds with the z-value.

In gnuplot, you can do this using the ‘lc variable’:

plot ’data’ using 1:2:3 with points lc variable  

Using the advice from here: Matplotlib scatterplot; colour as a function of a third variable

, I was able to use a scatter plot, which did work:

import matplotlib as mpl  
import matplotlib.pyplot as plt  

plt.scatter(x, y, c=z, s=1, edgecolors='none', cmap=mpl.cm.jet)  
plt.colorbar()  
plt.show()  

Is there a way to do this with the plot method in matplotlib, similar to this?

plt.plot(x, y, c=z)

When I tried the above code, all of the lines just appeared black.

  • 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-05-28T06:48:22+00:00Added an answer on May 28, 2026 at 6:48 am

    you can use scatter:

    plt.scatter(range(len(y)), y, c=z, cmap=cm.hot)
    

    here you have the ipython -pylab session:

    In [27]: z = [0.3,0.4,0.5,0.6,0.7,0.2,0.3,0.4,0.5,0.8,0.9]
    
    In [28]: y = [3, 7, 5, 6, 4, 8, 3, 4, 5, 2, 9]
    
    In [29]: plt.scatter(range(len(y)), y, s=60, c=z, cmap=cm.hot)
    Out[29]: <matplotlib.collections.PathCollection at 0x9ec8400>
    

    enter image description here

    If you want to use plot you can get the equivalent figure as above with (pycrust session):

    >>> from matplotlib import pyplot as plt
    >>> from matplotlib import cm
    >>> y = [3,7,5,6,4,8,3,4,5,2,9]
    >>> z = [0.3,0.4,0.5,0.6,0.7,0.2,0.3,0.4,0.5,0.8,0.9]
    >>> for x, (v, c) in enumerate(zip(y,z)):
    ...      plt.plot(x,v,marker='o', color=cm.hot(c))
    ...      
    [<matplotlib.lines.Line2D object at 0x0000000008C42518>]
    [<matplotlib.lines.Line2D object at 0x0000000008C426D8>]
    [<matplotlib.lines.Line2D object at 0x0000000008C42B38>]
    [<matplotlib.lines.Line2D object at 0x0000000008C452B0>]
    [<matplotlib.lines.Line2D object at 0x0000000008C45438>]
    [<matplotlib.lines.Line2D object at 0x0000000008C45898>]
    [<matplotlib.lines.Line2D object at 0x0000000008C45CF8>]
    [<matplotlib.lines.Line2D object at 0x0000000008C48198>]
    [<matplotlib.lines.Line2D object at 0x0000000008C485F8>]
    [<matplotlib.lines.Line2D object at 0x0000000008C48A58>]
    [<matplotlib.lines.Line2D object at 0x0000000008C4B1D0>]
    >>> plt.show()
    >>> 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I just have the array of 15 values that all need to be inserted
I have a set of values that I'm pushing into an array in the
I have an array that has keys and values. For eg: Array ( [name]
I have an array that contains the RGB colour values for each pixel in
I have an array that has a lot of values including a lot of
Lets say I have an array numbers that contains the following values: int numbers
I have a fitness function that is scoring the values on an int array
I have an array that I want to sort based on the value of
I have one array. I want that array to retain its value between function
i have a form that consist of two textfield and one combobox. 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.