def show_fashion_mnist(images, labels): d2l.use_svg_display() _, figs = d2l.plt.subplots(1, len(images), figsize=(12, 12)) for f, img, lbl in zip(figs, images, labels): f.imshow(img.reshape((28, 28)).asnumpy()) f.set_title(lbl) f.axes.get_xaxis().set_visible(False) f.axes.get_yaxis().set_visible(False)
def show_fashion_mnist(images, labels): d2l.use_svg_display() # Use svg format to display plo _, figs = d2l.plt.subplots(1, len(images), figsize=(12,12)) # _表示忽略 不使用该返回值 for f, img, lbl in zip(figs, images, labels): # 从压缩文件中直接读出数据(图像,标签) f.imshow(img.reshape((28,28)).asnumpy()) f.set_title(lbl) # 显示标签 f.axes.get_xaxis().set_visible(False) # 不显示坐标刻度X f.axes.get_yaxis().set_visible(False) # 不显示坐标刻度Y d2l.plt.show() # Pycharm中没有show()不会出现图片的
def __init__(self, xlabel=None, ylabel=None, legend=[], xlim=None, ylim=None, xscale='linear', yscale='linear', fmts=None, nrows=1, ncols=1, figsize=(3.5, 2.5)): """Incrementally plot multiple lines.""" d2l.use_svg_display() self.fig, self.axes = d2l.plt.subplots(nrows, ncols, figsize=figsize) if nrows * ncols == 1: self.axes = [ self.axes, ] # use a lambda to capture arguments self.config_axes = lambda: d2l.set_axes(self.axes[ 0], xlabel, ylabel, xlim, ylim, xscale, yscale, legend) self.X, self.Y, self.fmts = None, None, fmts
from mxnet.gluon import data as gdata import d2lzh as d2l from mxnet.gluon import nn import matplotlib from mxnet import init, autograd from mxnet import gluon train_data = gdata.vision.FashionMNIST(train=True) test_data = gdata.vision.FashionMNIST(train=False) batch_size = 256 data_iter = gdata.DataLoader(train_data, batch_size=batch_size, shuffle=True) d2l.use_svg_display() images, labels = train_data[0:9] def get_fashionmnist_label(labels): texts = [ 't-shirt', 'trouser', 'pullover', 'dress', 'coat', 'sandal', 'shirt', 'sneaker', 'bag', 'ankle boot' ] return [texts[int(i)] for i in labels] def show_fashion_mnist(images, labels): _, figs = d2l.plt.subplots(1, len(images), figsize=(12, 12)) for f, image, label in zip(figs, images, get_fashionmnist_label(labels)): f.imshow(image.reshape((28, 28)).asnumpy()) f.set_title(label) f.axes.get_xaxis().set_visible(False) f.axes.get_yaxis().set_visible(False) matplotlib.pyplot.show()