cmap=mcolors.LinearSegmentedColormap.from_list("my_colormap",["blue","red"])x=np.linspace(0,10,100)y=np.sin(x)plt.scatter(x,y,c=y,cmap=cmap)plt.colorbar()plt.show() Python Copy Output: 4. 调整Colormap亮度 有时候我们希望调整colormap的亮度,以便更好地展示数据。下面是一个示例代码,...
importmatplotlib.pyplotaspltimportnumpyasnp# 创建数据x=np.linspace(0,10,100)y=np.cos(x)# 创建图形plt.figure(figsize=(10,6))plt.scatter(x,y,c=y,cmap='plasma')plt.colorbar(label='Cos(x)')plt.title('使用 plasma 色彩映射表 - how2matplotlib.com')plt.xlabel('X')plt.ylabel('Y')plt...
import matplotlib.pyplot as plt from matplotlib import cm plt.figure(dpi=150) ##ListedColormap #取多种颜色 plt.subplot(1,4,1) #plt.bar(range(5),range(1,6),color=plt.cm.Accent(range(5))) #plt.bar(range(5),range(1,6),color=plt.cm.get_cmap('Accent')(range(5))) plt.bar(rang...
一、获取colormap 首先,先看看如何从内置的 colormap 中获取新的 colormap 及其颜色值。 import numpy as np import matplotlib.pyplot as plt import matplotlib as mpl from matplotlib import cm from matplotlib.colors importListedColormap, LinearSegmentedColormap mpl.rcParams.update({'figure.dpi':150}) ma...
在使用python 的 matplotlib库 时,可以使用现成的color map,也可以自定义colormap。 代码语言:javascript 代码运行次数:0 from matplotlibimportcolors from matplotlibimportcm # 使用现成的 color map cmap=cm.get_cmap('Set1')res=cmap(score_map)# 会根据 score map 的值从 cmap 中找 color,返回的是 rgba ...
import colorbm as cbm cbm.pcolor('crest').show() 如果安装成功便可输出类似下方图片。 色彩图与色板名称说明 为了输入方便,所有的色彩图与色板名称均采用小写字母 色板的使用 调用pal()类以使用色板,该类下面有4种方法: as_cmap:此方法返回Colormap object ...
pi, 100) # X values from 0 to 2π (one complete cycle) y = np.sin(x) # Y values (sine of X) # Create a figure and axis plt.figure(figsize=(10, 6)) # Create a scatter plot with a cyclic colormap # Color points by their position in the sine wave cycle points = plt....
colors.ListedColormap()子类 ListedColormap()类从颜色列表生成一个colormap。 classmatplotlib.colors.ListedColormap(colors, name='from_list', N=None) AI代码助手复制代码 **colors**参数有两种形式: matplotlib接受的规范的颜色列表,如['r', 'g', 'b'], 或['C0', 'C3', 'C7'],等,详见基础篇;...
#设定每个图的colormap和colorbar所表示范围是一样的,即归一化 norm = matplotlib.colors.Normalize(vmin=160, vmax=300) #显示图形,此处没有使用contourf #>>>ctf=plt.contourf(grid_x,grid_y,grid_z) gci=plt.imshow(grid_z.T, extent=extent, origin='lower',cmap=cmap, norm=norm) ...
#指定colormap cmap = .jet #设定每个图的colormap和colorbar所表示范围是一样的,即归一化 norm = matplotlib.colors.Normalize(vmin=160, vmax=300) #显示图形,此处没有使用contourf #>>>ctf=plt.contourf(grid_x,grid_y,grid_z) gci=plt.imshow(grid_z.T, extent=extent, origin='lower',cmap=cmap,...