fig = plt.figure() 的作用

fig = plt.figure()的作用是创建一个新的图形窗口(Figure对象),用于展示图形。Figure对象是matplotlib中的顶层容器,可以包含多个子图(Axes对象),并提供对图形的整体设置和管理。

在这段代码中,通过调用plt.figure()创建了一个新的图形窗口,并将其赋值给变量fig。接下来的代码会在这个图形窗口中绘制图形。

使用fig对象可以进行一系列图形设置,比如设置标题、坐标轴标签、图例等。通过fig对象还可以创建和管理子图,使得在同一个图形窗口中可以同时显示多个图形。

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
制作Mininst格式的数据,研究sklearn库等机器学习算法与库用得到。C++的VS2017测试通过。适用于车牌和数字识别。下面是Skearn测试程序。 #导入必备的包 import numpy as np import struct import matplotlib.pyplot as plt import os ##加载svm模型 from sklearn import svm ###用于做数据预处理 from sklearn import preprocessing import time #加载数据的路径 path='.' def load_mnist_train(path, kind='train'): labels_path = os.path.join(path,'%s-labels-idx1-ubyte'% kind) images_path = os.path.join(path,'%s-images-idx3-ubyte'% kind) with open(labels_path, 'rb') as lbpath: magic, n = struct.unpack('>II',lbpath.read(8)) labels = np.fromfile(lbpath,dtype=np.uint8) with open(images_path, 'rb') as imgpath: magic, num, rows, cols = struct.unpack('>IIII',imgpath.read(16)) images = np.fromfile(imgpath,dtype=np.uint8).reshape(len(labels), 784) return images, labels def load_mnist_test(path, kind='t10k'): labels_path = os.path.join(path,'%s-labels-idx1-ubyte'% kind) images_path = os.path.join(path,'%s-images-idx3-ubyte'% kind) with open(labels_path, 'rb') as lbpath: magic, n = struct.unpack('>II',lbpath.read(8)) labels = np.fromfile(lbpath,dtype=np.uint8) with open(images_path, 'rb') as imgpath: magic, num, rows, cols = struct.unpack('>IIII',imgpath.read(16)) images = np.fromfile(imgpath,dtype=np.uint8).reshape(len(labels), 784) return images, labels train_images,train_labels=load_mnist_train(path) test_images,test_labels=load_mnist_test(path) X=preprocessing.StandardScaler().fit_transform(train_images) X_train=X[0:60000] y_train=train_labels[0:60000] print(time.strftime('%Y-%m-%d %H:%M:%S')) model_svc = svm.LinearSVC() #model_svc = svm.SVC() model_svc.fit(X_train,y_train) print(time.strftime('%Y-%m-%d %H:%M:%S')) ##显示前30个样本的真实标签和预测值,用图显示 x=preprocessing.StandardScaler().fit_transform(test_images) x_test=x[0:10000] y_pred=test_labels[0:10000] print(model_svc.score(x_test,y_pred)) y=model_svc.predict(x) fig1=plt.figure(figsize=(8,8)) fig1.subplots_adjust(left=0,right=1,bottom=0,top=1,hspace=0.05,wspace=0.05) for i in range(100): ax=fig1.add_subplot(10,10,i+1,xticks=[],yticks=[]) ax.imshow(np.reshape(test_images[i], [28,28]),cmap=plt.cm.binary,interpolation='nearest') ax.text(0,2,"pred:"+str(y[i]),color='red') #ax.text(0,32,"real:"+str(test_labels[i]),color='blue') plt.show()

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

王摇摆

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值