Juan
Juan

Reputation: 11

colors in matplotlib with respect of intensity

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.

Upvotes: 1

Views: 3421

Answers (1)

dslack
dslack

Reputation: 845

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

Upvotes: 1

Related Questions