4.1 使用 LinearSegmentedColormap LinearSegmentedColormap 允许你通过定义颜色锚点来创建自定义的色彩映射表。 示例代码: importmatplotlib.pyplotaspltimportmatplotlib.colorsascolorsimportnumpyasnp# 定义颜色锚点colors_list=['#ff0000','#00ff00'
importnumpyasnpimportmatplotlib.pyplotaspltfrommatplotlib.colorsimportLinearSegmentedColormapcolors=["#56B4E9","#E69F00","#F0E442","#0072B2","#D55E00","#CC79A7","#999999"]n_bins=[3,6,10,100]# Discretizes the interpolation into binscmap_name='my_list'cm=LinearSegmentedColormap.from_l...
from matplotlib.colors import LinearSegmentedColormap # 定义自定义颜色映射的RGB值 colors = [(0, 0, 1), (0, 1, 1), (1, 1, 0), (1, 0, 0)] # 创建自定义颜色映射对象 custom_cmap = LinearSegmentedColormap.from_list('my_cmap', colors) # 创建一个随机数据数组 data = np.random.ran...
from matplotlib.colors import LinearSegmentedColormap, Normalize, rgba_to_rgb, to_hexcolors = [‘rgba(102, 204, 255, .3)’, ‘rgba(0, 128, 255, .8)’, ‘rgba(153, 0, 255, .3)’, ‘rgba(255, 204, 0, .8)’] # rgba颜色字符串列表(包含透明度)或rgb颜色字符串列表(不包含透明度)...
colors.LinearSegmentedColormap.from_list('cmap', c, 201) norm = mpl.colors.Normalize(vmin=e.min(), vmax=e.max()) cbar = fig.colorbar(mpl.cm.ScalarMappable(norm=norm, cmap=cmap), cax=bax, orientation='vertical') cbar.ax.tick_params(labelsize=12) cbar.set_label('RMSE', fontsize...
这样就可以生成colormap了,取多少个点比较随意,这里仿照官方取256个点: newcmap=LinearSegmentedColormap('testCmap',segmentdata=cdict,N=256) 最后我们整理一下,写成函数的形式: defcustomize_cmap(vmin,vmax,vsep,cmin,cmax,csep):frommatplotlib.colorsimportLinearSegmentedColormapsep=(vsep-vmin)/(vmax-vmin)...
categories = ['苹果', '香蕉', '橙子']values = [3, 7, 5]plt.bar(categories, values, color=plt.cm.tab10.colors[:len(categories)])plt.title('用Tab10渐变区分分类数据')plt.show()自定义你的颜色 想要你的图表看起来独一无二?试试自定义颜色吧!你可以通过RGB值、十六进制颜色代码或是简单的...
https://matplotlib.org/stable/gallery/color/colormap_reference.html import matplotlib.pyplot as plt import numpy as np import matplotlib as mpl from matplotlib.colors import LinearSegmentedColormap, ListedColormap viridis = mpl.colormaps['viridis'] ...
from matplotlib.colors import LinearSegmentedColormap # 定义颜色点 colors = [(0, 0, 1), (1, 0, 0)] # 蓝色到红色 # 创建色彩映射表 cmap = LinearSegmentedColormap.from_list('blue_to_red', colors) # 使用色彩映射表绘制图像 data = plt.rand(10, 10) ...
Matplotlib perceptually uniform colormap visualization example. Image by Author. Creating and Modifying Matplotlib Colormaps Although Matplotlib has a wide variety of built-in colormaps, there are scenarios where you would want to customize your colors. The key tools for creating custom colormaps in ...