【问题标题】:colors in matplotlib with respect of intensitymatplotlib 中关于强度的颜色
【发布时间】:2015-10-28 01:57:42
【问题描述】:

我想知道如何使用 python 根据强度绘制颜色。 例如,我有一个列表 [0.1, 0.5, 1.0],我想在 1.0 上绘制最暗的圆圈,在 0.5 上绘制第二个最暗的圆圈,在 0.1 上绘制第三个最暗的圆圈。

非常感谢您的帮助。

【问题讨论】:

标签: python matplotlib plot


【解决方案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')

产生这个:

【讨论】:

    猜你喜欢
    • 2016-09-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-27
    相关资源
    最近更新 更多