importmatplotlib.pyplotaspltimportnumpyasnp# 创建一个简单的数据集x=np.linspace(0,10,100)y=np.sin(x)# 使用 get_cmap 获取 'cool' 色彩映射cmap=plt.get_cmap('cool')# 使用 cool 色彩映射绘制彩色线条plt.scatter(x,y,c=y,cmap=cmap)plt.colorbar()plt.title('How2matplotlib.com - Cool Colorm...
4. 更新代码,使用新的替代方法替换matplotlib.cm.get_cmap 下面是一个使用matplotlib.cm.get_cmap的示例代码,以及如何使用matplotlib.colormaps.get_cmap来替换它的示例: python import matplotlib.pyplot as plt import matplotlib.cm as cm # 旧方法所在的模块 import matplotlib.colormaps as cmaps # 新方法所在...
3. 选择colormap Matplotlab中提供了很多colormap供我们选择,使用plt.get_cmap()函数来定义该图的colormap 二、伪彩色图 plt.pcolormesh() 伪彩色图是一个一个色块组成,其语法为 其中x,y是生成的二维坐标数组,z是二维数组上的数据,与x,y数组大小相同,cmap表示选择的颜色映射。 更多颜色映射可以查看: 附录3.3...
可以点击matplot cmap这里,里面有一个demo示例,会画一个包含matplot中所有cmap的图。 这里常见的cmap有: 纯色渐变系列: 比如说画灰度图的话,可以选择Greys这个cmap。 如何在画图中使用cmap 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 importmatplotlib.pyplot as plt ...
import matplotlib.pyplot as plt import matplotlib as mpl from matplotlib import cm from matplotlib.colors importListedColormap, LinearSegmentedColormap mpl.rcParams.update({'figure.dpi':150}) matplotlib.cm.get_cmap(name=None,lut=None) name:内置 colormap 的名称,如 'viridis'(默认),'spring' 等。
plt.imshow(I, cmap=plt.cm.get_cmap('Blues', 6))plt.colorbar()plt.clim(-1, 1); 离散色图的使用方式和其他色图没有任何区别。 例子:手写数字 最后我们来看一个很有实用价值的例子,让我们实现对一些手写数字图像数据的可视化分析。这个数据包含在 Sciki-Learn 中,以供包含有将近 2,000 张 大小的不...
在使用Matplotlib绘制图形时,其中有两个最为常用的场景。一个是画点,一个是画线。pyplot基本方法的使用如下表。 1. 绘制直线 在使用Matplotlib绘制线性图时,其中最简单的是绘制线图。在下面的实例代码中,使用Matplotlib绘制了一个简单的直线。具体实现过程如下: ...
import matplotlib.pyplot as plt x = np.linspace(-np.pi, np.pi, 30) # 在区间内生成30个等差数 y = np.sin(x) print('x = ', x) print('y = ', y) 1. 2. 3. 4. 5. 6. 输出: x = [-3.14159265 -2.92493109 -2.70826953 -2.49160797 -2.2749464 -2.05828484 ...
import matplotlib.pyplot as plt # 获取Legend对象 lg=plt.legend() print(lg.get_legend_handler_map()) 1. 2. 3. 4. {<class 'matplotlib.container.StemContainer'>: <matplotlib.legend_handler.HandlerStem object at 0x000000000EE1BF08>, <class 'matplotlib.container.ErrorbarContainer'>: <matplotl...