环境和包:
环境
python:python-3.12.0-amd64包:
matplotlib 3.8.2
代码:
import matplotlib.pyplot as plt
import matplotlib as mpl
import numpy as np
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.ticker as ticker
def map_rate(X: list, to_min: float, to_max: float) -> list:
"""区间映射
Attribute:
- X: 需要映射的列表
- to_min: 要映射到的最小值
- to_max: 要映射到的最大值
"""
x_min = min(X)
x_max = max(X)
return list([int(round(to_min + ((to_max - to_min) / (x_max - x_min)) * (i - x_min), 1)) for i in X])
# rainbow色带
def rainbow(x):
# rainbow色带
data = [(125, 0, 255), (99, 0, 255), (80, 0, 255), (70, 0, 255), (60, 0, 255), (50, 0, 255), (40, 0, 255),
(30, 0, 255), (20, 0, 255), (10, 0, 255), (4, 0, 255), (0, 2, 255), (0, 7, 255), (0, 11, 255), (0, 16, 255)
, (0, 20, 255), (0, 25, 255), (0, 29, 255), (0, 34, 255), (0, 38, 255), (0, 43, 255), (0, 47, 255),
(0, 52, 255), (0, 56, 255), (0, 61, 255), (0, 65, 255)
, (0, 70, 255), (0, 74, 255), (0, 79, 255), (0, 83, 255), (0, 88, 255), (0, 92, 255), (0, 97, 255),
(0, 101, 255), (0, 106, 255), (0, 110, 255), (0, 115, 255), (0, 119, 255)
, (0, 124, 255), (0, 128, 255), (0, 133, 255), (0, 137, 255), (0, 142, 255), (0, 146, 255), (0, 151, 255),
(0, 155, 255), (0, 160, 255), (0, 164, 255), (0, 169, 255), (0, 173, 255)
, (0, 178, 255), (0, 182, 255), (0, 187, 255), (0, 191, 255), (0, 196, 255), (0, 200, 255), (0, 205, 255),
(0, 209, 255), (0, 214, 255), (0, 218, 255), (0, 223, 255), (0, 227, 255)
, (0, 232, 255), (0, 236, 255), (0, 241, 255), (0, 245,