我想知道如何使用python绘制关于强度的颜色。 例如,我有一个列表[0.1,0.5,1.0],我想在1.0上绘制最暗圆圈,0.5和第二个最暗圆圈为0.1。
非常感谢你的帮助。
答案 0 :(得分:1)
使用matplotlib,您可以这样做:
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')