matplotlib使用

matplotlib在vscode上使用 在terminal输入pip install matplotlib安装,回车即可。 阅读详情

基本语法

导入库

import matplotlin.pyplot as plt
import numpy as np

plt 和ax.区别

  • plt. 先生成一个画布,在画布中生成的区域进行画图,当然plt也可以划分区域plt.subplot(111)
  • ax. 先生成一画布,在画布上选定一个区域进行画图add_subplot(xyz)第一个数字x代表行数,第二个数字y代表列数,第三个数字z表示取第z个小区域(先取第一行,从左到右)
  • 但是撇开位置不讲,两个图形没有图像上的区别

plt.

fig=plt.figure(num=1,figsize=(6,4))# 创建一个图形底板
plt.plot([1,2,3,4],[1,2,3,4])
# plt也可以直接划分区域
# plt.subplot(111)
plt.show()

在这里插入图片描述

ax.

fig=plt.figure(num=1,figsize=(4,4))
#  add_subplot(xyz)第一个数字x代表行数,第二个数字y代表列数,第三个数字z表示取第z个小区域(先取第一行,从左到右)
ax=fig.add_subplot(231)
plt.plot([1,2,3,4],[1,2,3,4])
plt.show()

在这里插入图片描述


ax. 用法

PS:以下使用ax.,使用plt.可跳下面

子图创建-展示不同的分区区域

  • 在画图之前,一般在画布上选定一个区域然后创建子图,如:
fig=plt.figure(num=1,figsize=(4,4))
ax1=fig.add_subplot(221)###可从图中看到,我们的画布是分为2x2的区域
ax1.plot([1,2,3,4],[1,2,3,4])
ax2=fig.add_subplot(222)
ax2.plot([1,2,3,4],[2,2,3,4])
ax3=fig.add_subplot(223)
ax3.plot([1,2,3,4],[1,2,2,4])
ax4=fig.add_subplot(224)
ax4.plot([1,2,3,4],[1,2,3,3])

plt.show()

在这里插入图片描述

设置刻度范围:

ax.set_xlim(1,7.1)#x轴从1到7.1
ax.set_ylim(40,100)#y轴从40到100

显示刻度

#设置显示的刻度
ax.set_xticks(np.linspace(1,7,7))#np.linspace()函数为等差数列,1至7的7个数组成的等差数列1,2,3,4,5,6,7,
ax.set_yticks(np.linspace(50,100,6))#关于等差数列,想了解的可以参看numpy的用法

设置刻度标签

#设置刻度标签
ax.set_xticklabels(["星期一","星期二","星期三","星期四","星期五","星期六","星期日"],fontproperties="SimHei"\
,fontsize=12)
#这里用到了属性fontproperties可以单独设置x轴标签的字体,也可以用fontsize设置字体大小,还可以用color
 设置字的颜色

ax.set_yticklebels(["50kg","60kg","70kg","80kg","90kg","100kg"],fontsize=12)

在这里插入图片描述

tick_params()函数

  • axis: 可选"x",“y”,“both”,默认"both",分别代表,对x轴操作,对y轴操作,对两个轴都操作。
  • direction: 可选 “in”,“out”,"inout"代表,刻度线显示在坐标轴里面,坐标轴外边,双边

添加轴坐标标签,表头,图例

ax.set_xlabel("星期")#添加x轴坐标标签,后面看来没必要会删除它,这里只是为了演示一下。
ax.set_ylabel("销售量",fontsize=16)#添加y轴标签,设置字体大小为16,这里也可以设字体样式与颜色

ax.set_title("某某水果店一周水果销售量统计图",fontsize=18,backgroundcolor='#3c7f99'\
fontweight='bold',color='white',verticalalignment="baseline")#标题(表头)


plt.用法

PS:以下使用plt.

普通折线图

  • 只指定一个数组元素时,表示为纵坐标的值,横坐标默认是数组下标
  • 也可以直接都指定横坐标和纵坐标
# 纵坐标折线图
fig=plt.figure(num=1,figsize=(6,4))# 创建一个图形底板
plt.plot([3,1,4,5,2])# 只指定一个数组元素,表示为中坐标的值,横坐标默认是数组下标
plt.ylabel("Grade")
plt.savefig("test1",dpi=600)# dpi 修改输出质量,表示每一英寸内像素点的值
plt.show()
# 横坐标和纵坐标折线图
plt.ylabel("Grade")
plt.plot([0,2,4,6,8],[3,1,4,5,2])# 指定横坐标和纵坐标
plt.axis([0,10,0,6])# 表示横坐标的尺度为[0,10],纵坐标为[0,6]
plt.show()

plt.plot(x,y,format_string,**kwargs)函数说明:

  • x:x轴的数据,列表或者数组,可选
  • y:y轴数据,列表或者数组
  • format_string:控制曲线的格式字符串,可选,,可选由颜色字符、风格字符和标记字符组成。
  • kwargs:第二组或者更多(x,y,format_string)
颜色字符说明
‘b’蓝色
‘g’绿色
‘r’红色
‘c’青绿色 cyan
‘m’洋红色 magenta
‘y’黄色
‘k’黑色
‘w’白色
‘0.8’灰度值字符串
风格字符说明
‘-’实线
‘–’破折线
‘-.’点划线
‘:’虚线
‘’ ’ ’无线条
标记字符说明
‘.’点标记
‘o’实心圈标记
‘^’上三角标记
'*'星形标记
‘+’十字标记
‘x’x标记
# 展示不同的函数画图
a=np.arange(10)
plt.plot(a,a*1.5,'go-',a,a*2.5,'rx',a,a*3.5,'*',a,a*4.5,'b-.')
plt.show()

在这里插入图片描述

中文显示plt.rcParams["font.family"]="SimHei"

  • 加入以上代码,中文就可以正常显示
    属性
    在这里插入图片描述
  • 字体选择
    在这里插入图片描述
matplotlib.rcParams['font.family']='STSong'
matplotlib.rcParams['font.size']=20# 字体大小
a=np.arange(0.0,5.0,0.02)
plt.xlabel("横轴:时间")
plt.ylabel("纵轴:振幅")
plt.plot(a,np.cos(2*np.pi*a),'r--')
plt.show()

上面都是简单语法介绍,下面开始画甘特图,这个在python可视化中是非常重要的

matplotlib画柱状图

plt.bar()、plt.barh()参数解释

plt.bar():正常柱状图📊📊,常见的统计图;
plt.barh():横向的柱状图,可以理解为正常柱状图旋转了90°。

plt.bar()

plt.bar(x, height, width=0.8, bottom=None, *, align='center', data=None, **kwargs)
  • x:表示x坐标,数据类型为int或float类型,刻度自适应调整;也可传dataframe的object,x轴上等间距排列;
  • height:表示柱状图的高度,也就是y坐标值,数据类型为int或float类型;
  • width:表示柱状图的宽度,取值在0~1之间,默认为0.8;
  • bottom:柱状图的起始位置,也就是y轴的起始坐标;
  • align:柱状图的中心位置,默认"center"居中,可设置为"lege"边缘;
  • color:柱状图颜色;
  • edgecolor:边框颜色;
  • linewidth:边框宽度;
  • tick_label:下标标签;
  • log:柱状图y周使用科学计算方法,bool类型;
  • orientation:柱状图是竖直还是水平,竖直:“vertical”,水平条:“horizontal”;

示例代码:

import matplotlib.pyplot as plt
import numpy as np

y=[20,30,15,25,15]
N=5
index=np.arange(N)
plt.bar(x=index,height=y)
plt.show()

在这里插入图片描述

plt.barh()

plt.barh(y, width, height=0.8, left=None, *, align='center', **kwargs)
  • y:表示y坐标,数据类型为int或float类型,刻度自适应调整;也可传dataframe的object,y轴上等间距排列;
  • width:表示柱状图的长度,也就是x坐标值,数据类型为int或float类型;
  • height:表示柱状图的高度,取值在0~1之间,默认为0.8;
  • 其他参数与plt.bar()类似。
import matplotlib.pyplot as plt
import numpy as np

y=[20,30,15,25,15]
N=5
index=np.arange(N)
# plt.bar(x=index,height=y)
# plt.show()

plt.barh(y=index,width=y)
plt.show()

在这里插入图片描述

plt.bar()综合应用

import matplotlib as mpl
import matplotlib.pyplot as plt
from matplotlib.pyplot import MultipleLocator
from matplotlib import ticker
%matplotlib inline


# 第一个坐标轴和图
fig = plt.figure(figsize=(8,5), dpi=80)
ax = fig.add_subplot(1,1,1)
plt.subplot(1, 1, 1)

# 画多个图,传递多个不同的x轴刻度
x = [i for i in range(25)]  # x轴标准刻度
x1 = [i-0.2 for i in range(25)]  # 第一个图x轴左偏移0.2
x2 = [i+0.2 for i in range(25)]  # 第二个图x周右偏移0.2,防止重叠
xx = data3['sku_pri'].to_list()  # x周的刻度显示

ax.set_ylabel('y轴1的名称')
ax.set_xlabel('x周名字')
plt.bar(x1, data3['num_sales']/10000, width=0.4, label='第一张图')
plt.ylim(0,4000)
plt.xticks(x,xx)  # x周刻度显示
plt.title('plt.plot()综合应用')
ax.legend(loc='upper left')

# 第二个坐标轴和图
ax2 = ax.twinx()
ax2.spines['right'].set_position(('axes', 1.0))
ax2.set_ylabel('y轴2的名称')
plt.bar(x2, data3['lk_num']/10000, width=0.4, color='orange', label='第二张图')
plt.ylim(0,200)
plt.xticks(x,xx)
ax2.legend(loc='upper center')

# 第三个坐标和图
ax3 = ax.twinx()
ax3.spines['right'].set_position(('axes', 1.1))  # 1.1向右便宜避免重叠
ax3.set_ylabel('y轴3的名称')
plt.plot(x, data3['lk_ra'], marker='*',color='purple', label='第三张图')
plt.ylim(0,0.12)

# y轴3设置刻度未百分比
ax3.yaxis.set_major_locator(MultipleLocator(0.02))
ax3.yaxis.set_major_formatter(ticker.PercentFormatter(xmax=1, decimals=0))
plt.xticks(x,xx)

ax3.legend(loc='upper right')

# plt.savefig('保存图片名称'+'.png')
plt.show()

在这里插入图片描述

plt.barh()画甘特图

数据如下:
python读取excel需要了解的知识点这里!!!

在这里插入图片描述
在这里插入图片描述

代码:
ps:注释掉的colors的那个配色更好看

import pandas as pd
import matplotlib.pyplot as plt
import matplotlib.patches as mpatches
from colour import Color
# import xlrd 引擎


# 正常显示中文和符号
plt.rcParams['font.sans-serif']=['SimHei']
plt.rcParams['axes.unicode_minus']=False

# 读取数据表,获取工位加工时长和各个工位开始加工时间
df1=pd.read_excel('test.xls',sheet_name='continue_time',index_col='YM')
df2=pd.read_excel('test.xls',sheet_name='start_time',index_col='YM')
# print(df1.head())
# print(df2.head())

CJS=['CJ1','CJ2','CJ3','CJ4']
YMS=['YM4','YM5','YM2','YM7','YM10','YM1','YM8','YM6','YM3','YM9']

# continue_time:各个工位加工时长,start_time:各个工位开始加工时间
continue_time=[]
start_time=[]

for cj in CJS:
    continue_time.append([ym for ym in df1[cj][YMS]])
    start_time.append([ym for ym in df2[cj][YMS]])

print("continue_time:",continue_time)
# print("start_time:",start_time)

# 获取数组大小,用于之后的循环
m=range(len(continue_time)) # 4 个机器
n=range(len(continue_time[0])) # 10 个工件

# print("m=%s,n=%s" %(m,n))

# 绘图
# 指定每一个水平柱子颜色
# red=Color('red')
# colors=list(red.range_to(Color('purple'),14))
# colors=[color.rgb for color in colors]
# print("colors:",colors)

colors = ['r', 'pink', 'orange', 'y', 'g', 'b', 'deeppink', 'purple', 'brown', 'black']

# 设置画布大小和分辨率
plt.figure(figsize=(20,8),dpi=200)

# barh:水平柱状图,设置循环迭代以绘制层叠效果
for i in m:
    for j in n:
        plt.barh(m[i] + 1, continue_time[i][j], left=start_time[i][j], color=colors[j])
        # print("机器=%s,工件=%s---------------------------" %(i,j))
        # print("m[i] + 1=%s, continue_time[i][j]=%s, left=start_time[i][j]=%s" % ( m[i] + 1, continue_time[i][j], start_time[i][j]))

plt.title('疫苗生产甘特图',fontsize=17)

# 命名
labels=['']*len(continue_time[0]);
for f in n:
    labels[f]='YM%d'%(f+1)
print(labels)

# 添加图例
patches=[mpatches.Patch(color=colors[i],label="{:s}".format(labels[i])) for i in range(len(continue_time[0]))]
plt.legend(handles=patches,loc=4)

# XY标签
plt.xlabel('加工时间/分钟',fontsize=15)
plt.ylabel('各工位加工流程',fontsize=15)

# XY轴刻度
plt.yticks([1,2,3,4],['CJ1','CJ2','CJ3','CJ4'])

# 网格线
# plt.grid(linestyle='--',alpha=0.5)

plt.savefig('gatte.jpg')
plt.show()

结果展示:

在这里插入图片描述

激光雷达与相机融合(四)----基于激光雷达与相机的碰撞检测 在这一部分,基于前面的各个部分内容,将利用激光雷达和相机实现目标的检测分类及单目标跟踪,并对车辆前方的车辆目标计算相应的碰撞时间TTC。计算方法分别利用相机和雷达实现。 1.系统的总体架构: 2.TTC计算 简单介绍一下通过激光雷达和相机计算碰撞时间的原理: 利用激光雷达点计算碰撞时间:首先根据检测框聚类出前车目标的点,并过滤掉这些点中的离群点,然后找出这些点中相对于本车最近的点,基于前后两帧以及数据采集频率就可以求解出相对速度,然后用当前帧的距离除以速度得出当前的TTC。但该方法对最近点的选取稳定性不是 阅读详情

相关推荐

Windows 10/11下Drive Composer Pro 2.9.0完整安装与连接ACS880变频器实战教程

本文详细介绍了在Windows 10/11系统上安装Drive Composer Pro 2.9.0并连接ACS880变频器的完整教程。从系统环境准备、软件安装到许可证配置,再到USB、蓝牙和以太网三种连接方式的实战操作,帮助工业自动化工程师快速掌握ABB变频器的调试技巧。

weixin_32956805的博客 549

5种方法,用python安装matplotlib库!

在数据可视化的世界里,matplotlib 是一个非常重要的工具库。它提供了一整套绘图功能,帮助我们将数据可视化为图表。无论你是数据科学家、工程师,还是只是在数据处理领域有所涉猎,掌握 matplotlib 的安装方法都能让你的工作更加高效。本文将详细介绍几种在Python中安装 matplotlib 的方法。

m0_75067629的博客 3万+

深信服PT1-AF实验考试

深信服PT1-AF实验考试实验练习可以去深信服的在线实验平台(链接如下):深信服在线实验平台 (sangfor.com.cn)实验考试其实就是把所有的每一部分实验综合了起来以下内容仅做参考,不确保一样。

m0_72019240的博客 7177

数据科学库(HM)(Day1)——matplotlib库加载以及pycharm中绘图

数据科学库(HM)(Day1)——matplotlib库加载以及pycharm中绘图

weixin_38551226的博客 705

全网最全医学图像数据汇总

本仓库汇总了多个领域的医学图像开源数据集,涵盖CT、MRI、超声、内窥镜、病理、多模态、PET、OCT以及皮肤镜等多种成像技术。每个数据集均详细列出了任务类型、部位、格式、数量及下载链接,旨在为医学图像研究者提供便捷的资源导航。⚠️:这些数据集仅适用于学术研究用途。

2401_83173765的博客 3325

Keil5 安装与卸载全攻略:从零开始到完美避坑

本文提供了Keil5集成开发环境的完整安装与卸载指南。针对嵌入式开发新手,详细解析了安装前的关键准备、MDK核心与C51双环境的安装激活步骤、常见问题排查,并重点介绍了如何彻底卸载软件以避免残留问题,帮助用户从零开始搭建稳定高效的开发环境。

weixin_29172963的博客 639

关于使用Python安装matplotlib后,加载库时出错的解决方式

一、在win10系统下使用pip命令安装matplotlib库:pip installmatplotlib 1、第一次使用的Python3.8版本,当时Python3.8安装在F盘,在cmd窗口输入pip installmatplotlib后,显示matplotlib安装成功,当我在py文件中加载matplotlib库时,出现以下报错: 2、第二次,使用Python3.9版本安装显示同样的报错。 二、错误原因 经查阅,大致原因是:使用pip命令安装的matplotlib库不匹配Pyth...

weixin_44232639的博客 4032

YOLO11改进 - 卷积Conv | StripBlockStripBlock大条带卷积块,通过顺序条带卷积捕获方向性长程依赖,强化高长宽比目标特征提取 | AAAI 2026

本文介绍了面向高纵横比目标检测的条带卷积模块——StripBlock,适用于遥感、船只、车道等细长结构目标的特征增强。该方法先通过 `5×5` 深度卷积提取局部空间信息,再利用 `1×19` 与 `19×1` 的正交长条卷积分别建模横向和纵向长程依赖,最后通过 `1×1` 卷积生成空间注意力权重,并以逐元素门控方式重标定输入特征。我们将 StripBlock 成功集成进 YOLO11,在检测头的多尺度特征层中引入条带式空间建模能力,从而增强模型对细长目标和复杂遥感场景的定位与识别效果。

魔改工程师的博客 239

加载 matplotlib 包中文无法显示问题

问题描述 在使用 matplotlib 绘图的时候,运行中警告 “RuntimeWarning: Glyph 39064 missing from current font. font.set_text(s, 0, flags=flags)” , 结果为中文无法显示。 问题分析 该原因是因为对应字体无法显示中文的问题,需要加载对应正确的字体包。 解决问题 网上一般建议使用 import matplotlib.pyplot as plt plt.rcParams['font.sans-serif']=[

他说他是个木偶的博客 879

QT实现计算器(C/C++)

digitClicked()槽函数用于处理数字按钮的点击事件,operatorClicked()槽函数用于处理运算符按钮的点击事件,equalsClicked()槽函数用于处理等号按钮的点击事件。在operatorClicked()槽函数中,我们获取被点击按钮的文本作为当前运算符,并将文本框中的内容转换为双精度浮点数,存储为操作数1。在上述代码中,我们添加了一个私有成员变量m_operand1,用于存储第一个操作数的值,以及一个私有成员变量m_currentOperator,用于存储当前运算符的值。

CyberNova的博客 386

提高RFID检测距离以及检测速度的方法总结

摘要:提高RFID检测距离需优化阅读器功率、标签灵敏度、天线设计及频段选择,同时减少环境干扰;提升检测速度则需改进防碰撞算法、增强并行处理能力、精简数据传输。实际应用需平衡两者关系,如物流仓储采用UHF频段、高增益天线和动态Q算法实现远距离高速读取,ETC系统则通过微波频段和高速调制实现超远距离快速识别。不同场景需针对性优化硬件配置和系统参数。

start_up_go的博客 295

pyqt5加载matplotlib图形

从渲染器的画布figure中,然后就可以进行子布局,渲染器为:self.static_canvas ,画布为:self.static_canvas.figure。然后单个创建的方法为(eg:创建2行列):ax1=self.self.static_canvas.figure.add_subplot(211),FigureCanvasQTAgg是一个渲染器,它的工作就是不停的drawing,从而将物体显示在屏幕上。为将matplotlib中的figure对象变为一个Qt widgets.有些可能还理解不到位。

weixin_49577420的博客 1405

CAPL诊断功能实现

UDS(Unified Diagnostic Services)是一种用于汽车电子系统诊断的标准协议。它定义了一系列诊断服务,用于读取和写入车辆电子控制单元(ECU)中的数据,以及处理诊断故障码(DTC)。UDS协议通常运行在CAN总线上,使用ISO 15765-2(ISO-TP)协议进行数据传输。通过本文的学习,读者应该对CAPL诊断功能实现有了初步的了解,并能够编写复杂的CAPL脚本。在实际项目中,CAPL的应用非常广泛,希望读者能够通过不断的学习和实践,掌握更多的CAPL技巧,提高自己的开发能力。

闲人编程的博客 1519

【Python】matplotlib库的安装和简单使用

本文主要介绍matplotlib库的安装和简单使用。针对新手,首先从升级pip工具开始,然后使用pip工具从国内镜像快速下载安装matplotlib库,同时附带简单完整的python代码,用于演示绘制正弦曲线图形。

huanqing2010的专栏 41万+

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

Matplotlib的简单使用

matplotlib的简单使用

ungoing的博客 928

最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版

Part-E1-SDIO-Specification-Ver4.00-Final-120220.pdf:最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版,包括SDIO 接口的外设,SDIO 接口官方协议等。

Matplotlib基本使用

是一款用于数据可视化的 Python 软件包,支持跨平台运行,它能够根据 NumPy ndarray 数组来绘制 2D 图像。Matplotlib 图形组成::指整个图形,可以把它理解成一张画布,它包括了所有的元素,比如标题、轴线等:绘制 2D 图像的实际区域,也称为轴域区,或者绘图区:指坐标系中的垂直轴与水平轴,包含轴的长度大小(图中轴长为 7)、轴标签(指 x 轴,y轴)和刻度标签。

Clocky7 1127

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

Matplotlib 的基本使用

文章目录一、简介1. 什么是Matplotlib2. 为什么要学习Matplotlib3. 实现一个简单的Matplotlib画图 — 以折线图为例3.1 matplotlib.pyplot模块3.2 图形绘制流程3.3 折线图绘制与显示4. 认识Matplotlib图像结构(了解)二、基础绘图功能 — 以折线图为例1. 完善原始折线图 — 给图形添加辅助功能1.1 准备数据并画出初始折线图1.2 添加自定义x,y刻度1.3 中文显示问题解决1.4 添加网格显示1.5 添加描述信息1.6 图像保存2. 在一

mengxianglong123的博客 4496

【Matplotlib基本使用】

x:要显示的刻度值y:要显示的刻度值# 增加以下两行代码# 构造x轴刻度标签x_ticks_label = ["11点{}分".format(i) for i in x]# 构造y轴刻度# 修改x,y轴坐标的刻度显示。

weixin_55448492的博客 2585

wxpython使用matplotlib_matplotlib - matplotlib 教程

Pyplot 教程关于pylot接口的介绍。matplotlib 教程这个图库包含了使用Matplotlib可以做的许多事情的示例。可以点击任何图像,以查看完整的图像和源代码。有关更短的示例,请参见示例页。你还可以在我们的用户指南中找到外部资源和常见问题解答。matplotlib 入门这些教程介绍了使用Matplotlib创建可视化效果的基础知识,以及有效使用该包的一些最佳实践。使用指南本教程介绍...

weixin_39994627的博客 839

matplotlib的基础使用

plt.subplot2grid((3, 3), (1, 0), colspan = 2) //(3,3)表示分为3行3列,(1,0)表示选中第1行,第0列的区域进行绘图,colspan=2表示在选中区域的延伸。样式: '-','--','-.',':','.',',',,o,^,v,,s,+,x,D,d,1,2,3,4,h,H,p,| ,_颜色: b(蓝色),g(绿色),r(红色),c(青色),m(品红),y(黄色),k(黑色),w(白色)风格字符:‘-’实线;颜色字符:‘b’蓝色;

yuange1666的博客 1021

Matplotlib的基本使用

文章目录1. 什么是Matplotlib2. 安装和基本使用3.点线缩写和颜色的选择4. 设置图的信息4.1 设置线条样式的方法4. 2 设置轴和标题4.2.1 设置轴名称4.2.2 设置标题4.2.3 设置 x 轴和 y 轴的刻度4.2.4 复仇者联盟电影票房案例小结5. 设置文本注释和marker5.1 设置marker5.2 设置注释文本小结6. 设置图形样式6.1 调整图片的大小和像素6.2 显示图片的网格6.3 绘制多个图6.3.1 绘制多根折线6.3.2 绘制多个子图小结6.4 风格设置7. 条

自成背后的博客 5594

Matplotlib官方使用文档下载

Matplotlib官方使用文档下载 【下载地址】Matplotlib官方使用文档下载 Matplotlib官方使用文档PDF资源,助你快速掌握Python绘图利器。Matplotlib作为Python中功能强大的可视化库,广泛应用于数据分析和科学计算领域。该文档涵盖了从安装配置到高级应用的全面指南,包含丰富实例与最佳实...

gitblog_06763的博客 494

Matplotlib基础使用

Matplotlib 的使用 matplotlib更多的图形样式 图形样式 一、基础绘图01 from matplotlib import pyplot as plt x = range(2, 26, 2) y = [15, 13, 14.5, 17, 20, 25, 26, 26, 24, 22, 18, 15] # 设置图片大小 fig = plt.figure(figsize=(15, 8), dpi=80) # 绘图 plt.plot(x, y, linewidth = 5) # linew

Sunstar 272

Matplotlib 全面使用指南 -- Matplotlib 中的字体 Fonts in Matplotlib

Matplotlib 是一个综合库,用于在 Python 中创建静态、动画和交互式可视化。

船长Q的博客 1395

Matplotlib 全面使用指南 -- Matplotlib 中的文本 Text in Matplotlib

Matplotlib 是一个综合库,用于在 Python 中创建静态、动画和交互式可视化。

船长Q的博客 1383

在pyqt中使用matplotlib

基本思路 FigureCanvas→MyFigureCanvas FigureCanvas→MyFigureCanvas→QGraphicScene→QGraphicView 以下有展示三个例子,其中第二个仅供对比参考。 前两个例子不同之处是:第二个例子是吧FigureCanvas放到QGraphicScene中,再把QGraphicScene放到QGraphicView中,所做的...

4124
上一篇: Pandas.read_excel详解
下一篇: 使用vscode写UML图
@@老胡
博客等级 码龄7年 291粉丝 185原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值