基于【matplotlib】【imshow】【cmap】绘制【numpy.ndarray】二维数组的“二维码”
来源:互联网 发布:cd刻录软件 编辑:程序博客网 时间:2024/06/01 08:18
基于 matplotlib 画 numpy.ndarray 二维数组的二维图/灰度图:
全文参考:http://matplotlib.org/examples/color/colormaps_reference.html
import numpy as npimport pandas as pdimport matplotlib as mplimport matplotlib.pyplot as plttrain_data_source = pd.read_csv('df_recon_train', header=0, encoding='utf-8')train_data = train_data_source.drop(['uid', 'y'], axis=1)
#以train_data的第一行数据为例,画二维数组的二维图row_ins = train_data[0:1].values[0]row_ins_rect = row_ins[::-1].reshape(45, 46)fig = plt.figure()ax1 = fig.add_subplot(1,2,1)ax1.imshow(row_ins_rect, cmap=plt.cm.gray_r)ax2 = fig.add_subplot(1,2,2)ax2.imshow(row_ins_rect, cmap=plt.cm.hot_r)plt.show()
implot = plt.imshow(row_ins_rect, cmap="summer")#选一个漂亮的颜色plt.show()
import numpy as npimport matplotlib.pyplot as plt# Have colormaps separated into categories:# http://matplotlib.org/examples/color/colormaps_reference.htmlcmaps = [('Perceptually Uniform Sequential', ['viridis', 'inferno', 'plasma', 'magma']), ('Sequential', ['Blues', 'BuGn', 'BuPu', 'GnBu', 'Greens', 'Greys', 'Oranges', 'OrRd', 'PuBu', 'PuBuGn', 'PuRd', 'Purples', 'RdPu', 'Reds', 'YlGn', 'YlGnBu', 'YlOrBr', 'YlOrRd']), ('Sequential (2)', ['afmhot', 'autumn', 'bone', 'cool', 'copper', 'gist_heat', 'gray', 'hot', 'pink', 'spring', 'summer', 'winter']), ('Diverging', ['BrBG', 'bwr', 'coolwarm', 'PiYG', 'PRGn', 'PuOr', 'RdBu', 'RdGy', 'RdYlBu', 'RdYlGn', 'Spectral', 'seismic']), ('Qualitative', ['Accent', 'Dark2', 'Paired', 'Pastel1', 'Pastel2', 'Set1', 'Set2', 'Set3']), ('Miscellaneous', ['gist_earth', 'terrain', 'ocean', 'gist_stern', 'brg', 'CMRmap', 'cubehelix', 'gnuplot', 'gnuplot2', 'gist_ncar', 'nipy_spectral', 'jet', 'rainbow', 'gist_rainbow', 'hsv', 'flag', 'prism'])]nrows = max(len(cmap_list) for cmap_category, cmap_list in cmaps)gradient = np.linspace(0, 1, 256)gradient = np.vstack((gradient, gradient))def plot_color_gradients(cmap_category, cmap_list): fig, axes = plt.subplots(nrows=nrows) fig.subplots_adjust(top=0.95, bottom=0.01, left=0.2, right=0.99) axes[0].set_title(cmap_category + ' colormaps', fontsize=14) for ax, name in zip(axes, cmap_list): ax.imshow(gradient, aspect='auto', cmap=plt.get_cmap(name)) pos = list(ax.get_position().bounds) x_text = pos[0] - 0.01 y_text = pos[1] + pos[3]/2. fig.text(x_text, y_text, name, va='center', ha='right', fontsize=10) # Turn off *all* ticks & spines, not just the ones with colormaps. for ax in axes: ax.set_axis_off()for cmap_category, cmap_list in cmaps: plot_color_gradients(cmap_category, cmap_list)plt.show()
0 0
- 基于【matplotlib】【imshow】【cmap】绘制【numpy.ndarray】二维数组的“二维码”
- matplotlib中使用imshow绘制二维图
- matplotlib中使用imshow绘制二维图
- numpy ndarray 数组对象
- numpy-数组对象ndarray
- Numpy ndarray数组切片
- Numpy的ndarray简介
- Numpy的ndarray
- Python:numPy 的 ndarray
- 什么是Numpy的ndarray
- numpy数组 ndarray对象基本知识
- numpy.ndarray 交换多维数组(矩阵)的行/列
- Chapter4-1 NumPy的ndarray:一种多维数组对象
- NumPy的ndArray——多维数组对象
- nditer —— numpy.ndarray 多维数组的迭代
- Python科学计算--NumPy的数组对象ndarray
- Python numpy中数组(ndarray)的运用
- Matplotlib调用imshow()函数绘制热图
- 什么是DRM
- 谈谈为什么写单元测试
- Hibernate学习之----环境搭建
- 内嵌驱动入口简单解释
- console类型
- 基于【matplotlib】【imshow】【cmap】绘制【numpy.ndarray】二维数组的“二维码”
- eclipse中优化导入项目花费的时间
- Linux下的platform总线驱动代码分析
- cmake工具简介
- centos6.5安装mysql
- Thread 1: breakpoint 2.2
- java之excel模板下载
- Java String类的练习和常用方法
- iOS开发 - 用AFNetworking实现https单向验证,双向验证