importmatplotlib.pyplotaspltimportnumpyasnp# 创建数据x=np.linspace(0,10,100)y=np.sin(x)# 创建图形plt.figure(figsize=(10,6))plt.scatter(x,y,c=y,cmap='viridis')plt.colorbar(label='Sin(x)')plt.title('How2matplotlib.co
10)fig,(ax1,ax2)=plt.subplots(1,2,figsize=(10,4))fig.suptitle('How2matplotlib.com: Normal vs Reversed Grayscale Colormap')# 正常灰度色彩映射im1=ax1.imshow(data,cmap='gray')ax1.set_title('Normal Gray')plt.colorbar(im1,ax=ax1)# 反转灰度色彩映射im2=ax2.imshow(data,cmap='gray_r...
rect = mpatches.Rectangle(xy2,0.2,0.1,color='r') ax.add_patch(rect) # 画多边形 图形中心-边数-中心到顶点长度-颜色 polygon = mpatches.RegularPolygon(xy3,5,0.1,color='g') ax.add_patch(polygon) # 画椭圆形 圆心-长直径-短直径-颜色 ellipse = mpatches.Ellipse(xy4,0.4,0.2,color='y')...
matplotlib.colors.SymLogNorm(linthresh,linscale=1.0,vmin=None,vmax=None,clip=False,*,base=10) linthresh:设定线性映射区间 [-linthresh, linthresh] linscale:设定线性区间占用 colormap 的相对宽度 base:对数底数 N = 200 X,Y = np.mgrid[-6:6:complex(0,N),0:1:complex(0,N)] Z1 = np.fli...
https://matplotlib.org/stable/users/explain/colors/colormapnorms.html 例子: importnumpyasnpimportmatplotlib.pyplotaspltfrommatplotlibimportcm, colors ax = plt.gca() cmap = plt.get_cmap('coolwarm')# need to normalize because color maps are defined in [0, 1]norm = colors.TwoSlopeNorm(1, vmi...
→ plt.get_cmap(“viridis_r”) … get a discrete colormap? → plt.get_cmap(“viridis”, 10) … show a figure for one second? → fig.show(block=False), time.sleep(1) ax.grid() ax.patch.set_alpha(0) ax.set_[xy]lim(vmin, vmax) ax.set_[xy]label(label) ax.set_[xy]ticks(...
cmap = grayscale_cmap(cmap) grayscale = cmap(np.arange(cmap.N)) fig, ax = plt.subplots(2, figsize=(6, 2), subplot_kw=dict(xticks=[], yticks=[])) ax[0].imshow([colors], extent=[0, 10, 0, 1]) ax[1].imshow...
1)ListedColormap ListedColormap 将它们的颜色值存储在 .colors 属性中,因此可以使用 colors 属性直接访问组成色图的颜色列表。 也可以通过调用viridis来间接访问它,该viridis的值数组与colormap的长度相匹配。 请注意,返回的列表是 RGBA Nx4 数组的形式,其中 N 是色图的长度。 import numpy as np from matplotlib...
lines=plt.plot(x1,y1,x2,y2)# 使用关键字参数plt.setp(lines,color='r',linewidth=2.0)# 或...
importmatplotlib.pyplotaspltimportmatplotlib.colorsasmcolorsimportnumpyasnp# 创建自定义颜色映射colors=['red','yellow','green']n_bins=100cmap=mcolors.LinearSegmentedColormap.from_list('custom_cmap',colors,N=n_bins)# 生成数据data=np.random.randn(100,100)plt.figure(figsize=(10,8))plt.imshow(dat...