1

I'm wondering how to plot colors with respect of intensity using python. For example I have a list [0.1, 0.5, 1.0], and I would like to plot circles with darkest circle on 1.0, and second darkest circle for 0.5 and third darkest circle for 0.1.

Thanks a lot for helping.

Juan
  • 11
  • 1
  • 2
  • See if this answers your question: http://stackoverflow.com/questions/12965075/matplotlib-scatter-plot-colour-as-function-of-third-variable/12965761#12965761 – Warren Weckesser Oct 28 '15 at 02:30
  • Thanks a lot. I just got problem solved by using "plt.cm.Greys" in matplotlib. – Juan Oct 28 '15 at 02:41

1 Answers1

1

Using matplotlib, you could do something like this:

from __future__ import division
from matplotlib import pyplot as plt
import numpy as np

plt.ion()

centers = [0.1, 0.5, 1.0]
radii = [0.1, 0.2, 0.3]
num_circs = len(centers)

# make plot
fig, ax = plt.subplots(figsize=(6, 6))
red = np.linspace(0, 1, num_circs)
green = 0. * red
blue = 1. - red
colors = np.array([red, green, blue]).T
power = 1.5  # adjust this upward to make brightness fall off faster
for ii, (center_x, radius) in enumerate(zip(centers, radii)):
    color = colors[ii]
    brightness = ((num_circs-ii) / num_circs)**power  # low ii is brighter
    color = color * brightness
    circle = plt.Circle((center_x, 0.), radius, color=color)
    ax.add_artist(circle)
_ = plt.axis([-0.3, 1.5, -0.9, 0.9], 'equal')
plt.savefig('circles.png')

which produces this: circles.png

dslack
  • 835
  • 6
  • 17