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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T13:35:29+00:00 2026-06-09T13:35:29+00:00

I’m trying to shade points in a scatter plot based on a set of

  • 0

I’m trying to shade points in a scatter plot based on a set of values (from 0 to 1) picked from one of the already defined color maps, like Blues or Reds. I tried this:

import matplotlib
import matplotlib.pyplot as plt
from numpy import *
from scipy import *
fig = plt.figure()
mymap = plt.get_cmap("Reds")
x = [8.4808517662594909, 11.749082788323497, 5.9075039082855652, 3.6156231827873615, 12.536817102137768, 11.749082788323497, 5.9075039082855652, 3.6156231827873615, 12.536817102137768]
spaced_colors = linspace(0, 1, 10)
print spaced_colors
plt.scatter(x, x,
            color=spaced_colors,
            cmap=mymap)
# this does not work either
plt.scatter(x, x,
            color=spaced_colors,
            cmap=plt.get_cmap("gray"))

But it does not work, using either the Reds or gray color map. How can this be done?

edit: if I want to plot each point separately so it can have a separate legend, how can I do it? I tried:

fig = plt.figure()
mymap = plt.get_cmap("Reds")
data = np.random.random([10, 2])
colors = list(linspace(0.1, 1, 5)) + list(linspace(0.1, 1, 5))
print "colors: ", colors
plt.subplot(1, 2, 1)
plt.scatter(data[:, 0], data[:, 1],
           c=colors,
           cmap=mymap)
plt.subplot(1, 2, 2)
# attempt to plot first five points in five shades of red,
# with a separate legend for each point
for n in range(5):
    plt.scatter([data[n, 0]], [data[n, 1]],
               c=[colors[n]],
               cmap=mymap,
               label="point %d" %(n))
plt.legend()

but it fails. I need to make a call to scatter for each point so that it can have a separate label=, but still want each point to have a different shade of the color map as its color.
thanks.

  • 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-09T13:35:30+00:00Added an answer on June 9, 2026 at 1:35 pm

    If you really want to do this (what you describe in your edit), you have to “pull” the colors from your colormap (I have commented all changes I made to your code):

    import numpy as np
    import matplotlib.pyplot as plt 
    
    # plt.subplots instead of plt.subplot
    # create a figure and two subplots side by side, they share the
    # x and the y-axis
    fig, axes = plt.subplots(ncols=2, sharey=True, sharex=True)
    data = np.random.random([10, 2]) 
    # np.r_ instead of lists
    colors = np.r_[np.linspace(0.1, 1, 5), np.linspace(0.1, 1, 5)] 
    mymap = plt.get_cmap("Reds")
    # get the colors from the color map
    my_colors = mymap(colors)
    # here you give floats as color to scatter and a color map
    # scatter "translates" this
    axes[0].scatter(data[:, 0], data[:, 1], s=40,
                    c=colors, edgecolors='None',
                    cmap=mymap)
    for n in range(5):
        # here you give a color to scatter
        axes[1].scatter(data[n, 0], data[n, 1], s=40,
                        color=my_colors[n], edgecolors='None',
                        label="point %d" %(n))
    # by default legend would show multiple scatterpoints (as you would normally
    # plot multiple points with scatter)
    # I reduce the number to one here
    plt.legend(scatterpoints=1)
    plt.tight_layout()
    plt.show()
    

    colored-scatter

    However, if you only want to plot 10 values and want to name every single one,
    you should consider using something different, for instance a bar chart as in this
    example. Another opportunity would be to use plt.plot with a custom color cycle, like in this example.

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

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is

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.