python曲线有颜色范围_python-Matplotlib-基于光谱颜色的曲线下的颜色

本文介绍如何使用Python的Matplotlib库,基于波长和RGB转换函数,为曲线下的区域填充颜色,创建一种光谱颜色效果。通过调整函数,设置不同波长对应的透明度,并使用LinearSegmentedColormap创建自定义颜色映射。
摘要由CSDN通过智能技术生成

首先,您需要一个将波长作为输入并返回RGB颜色的函数.可以找到一个这样的函数here.可以对其进行调整,使其还返回一个alpha值,该值在可见颜色范围之外小于1.

此功能可用于创建颜色图.使用体面的归一化可以将波长范围映射到0到1之间的范围,以便可以在imshow图中使用此色图.

import numpy as np

import matplotlib.pyplot as plt

import matplotlib.colors

def wavelength_to_rgb(wavelength, gamma=0.8):

''' taken from http://www.noah.org/wiki/Wavelength_to_RGB_in_Python

This converts a given wavelength of light to an

approximate RGB color value. The wavelength must be given

in nanometers in the range from 380 nm through 750 nm

(789 THz through 400 THz).

Based on code by Dan Bruton

http://www.physics.sfasu.edu/astro/color/spectra.html

Additionally alpha value set to 0.5 outside range

'''

wavelength = float(wavelength)

if wavelength >= 380 and wavelength <= 750:<

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值