fig, ax = plt.subplots() 创建的ax如何设置横纵坐标轴的名称

fig, ax = plt.subplots()
ax.set_title('total_loss')
ax.set_ylabel('total_loss')
ax.set_xlabel('episode')

 

  • 2
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 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
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值