当前位置: 首页 > news >正文

广东住房和城乡建设部网站网站开发需要的编程软件

广东住房和城乡建设部网站,网站开发需要的编程软件,潍坊网站建设推广报价,手机ppt免费制作软件Matplotlib画图教程#xff1a;在QT界面中嵌入三维图片 需求#xff1a; 做项目报告的时候#xff0c;有这么一个想法#xff0c;就是能通过UI随时调用matplotlib进行二维图和三维图的绘制。因此就诞生了做这么一个小模块的想法。 这里先上一下最终结果#xff1a; 思…Matplotlib画图教程在QT界面中嵌入三维图片 需求 做项目报告的时候有这么一个想法就是能通过UI随时调用matplotlib进行二维图和三维图的绘制。因此就诞生了做这么一个小模块的想法。 这里先上一下最终结果 思路 pyqt5内嵌matploblib画布。 matplotlib画布中有一个FigureCanvasQTAgg的模块可以用于UI绘制 模块设计思路 1. ui文件 ui文件是通过qtdesigner直接生成的ui源码与图表绘制相独立。 2. 图表绘制文件 该文件用于设计一个matplotlib图表绘制类存放我们需要做报告的任何图图表以及我们的一些数据导入。 3. 运行文件 运行文件继承上面两个文件运行实例。 UI模块 这个模块没什么好说的基于QTdesigner进行图形绘制图形界面已经每个组件定义如下。这个模块在教程中只是用于演示 1.1 UI图形类 类Ui_matplot_demo图形绘制类实例化方式不需要入参方法self.setupUi构建一个UI窗口 1.2 测试UI界面及其属性 绘制的界面样式 界面控件属性 1.3 代码 # -*- coding: utf-8 -*-# Form implementation generated from reading ui file ui_ut.ui # # Created by: PyQt5 UI code generator 5.15.6 # # WARNING: Any manual changes made to this file will be lost when pyuic5 is # run again. Do not edit this file unless you know what you are doing.from PyQt5 import QtCore, QtGui, QtWidgetsclass Ui_matplot_demo(object):def setupUi(self, matplot_demo):matplot_demo.setObjectName(matplot_demo)matplot_demo.resize(1133, 721)self.gridLayout QtWidgets.QGridLayout(matplot_demo)self.gridLayout.setObjectName(gridLayout)self.bt_close QtWidgets.QPushButton(matplot_demo)self.bt_close.setObjectName(bt_close)self.gridLayout.addWidget(self.bt_close, 1, 1, 1, 1)self.bt_open QtWidgets.QPushButton(matplot_demo)self.bt_open.setObjectName(bt_open)self.gridLayout.addWidget(self.bt_open, 1, 0, 1, 1)self.plt3d_module QtWidgets.QWidget(matplot_demo)self.plt3d_module.setMinimumSize(QtCore.QSize(1111, 611))self.plt3d_module.setObjectName(plt3d_module)self.gridLayout.addWidget(self.plt3d_module, 0, 0, 1, 2)self.retranslateUi(matplot_demo)QtCore.QMetaObject.connectSlotsByName(matplot_demo)def retranslateUi(self, matplot_demo):_translate QtCore.QCoreApplication.translatematplot_demo.setWindowTitle(_translate(matplot_demo, Form))self.bt_close.setText(_translate(matplot_demo, 按一下就可以关闭图片))self.bt_open.setText(_translate(matplot_demo, 按一下就可以画图)) 图表绘制模块 这个模块是核心的图表绘制模块主要结构如下 1.1 依赖包 包名含义安装方式numpy数学运算包pip install numpymatplotlilb数学绘图包pip install matplotlib 1.2 类 类MyFigure图形绘制类实例化方式入参含义width5控制画布宽度height4控制画布高度dpi100控制画布分辨率属性含义初值self.fig实例化一个matplotlib的Figure类self.axes坐标系可以是二维也可以是三维方法plot_sin画一个正弦函数plot_cos画一个余弦函数plot_3d画一个3D的图基于leetcode218 天际线 1.3 代码如下 import numpy as np import matplotlib from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas from matplotlib.figure import Figure matplotlib.use(Qt5Agg) # 声明使用QT5# 创建一个matplotlib图形绘制类 class MyFigure(FigureCanvas):def __init__(self, width5, height4, dpi100):# 第一步创建一个创建Figureself.fig Figure(figsize(width, height), dpidpi)# 第二步在父类中激活Figure窗口super(MyFigure, self).__init__(self.fig) # 此句必不可少否则不能显示图形# 第三步创建一个子图用于绘制图形用111表示子图编号如matlab的subplot(1,1,1)self.axes None# 第四步就是画图【可以在此类中画也可以在其它类中画】def plot_sin(self):self.axes self.fig.add_subplot(111)t np.arange(0.0, 3.0, 0.01)s np.sin(2 * np.pi * t)self.axes.plot(t, s)def plot_cos(self):self.axes self.fig.add_subplot(111)t np.arange(0.0, 3.0, 0.01)s np.sin(2 * np.pi * t)self.axes.plot(t, s)def plot_3d(self):self.axes self.fig.add_subplot(111, projection3d)x_edges np.array([[10, 20], [10, 20], [10, 20], [10, 20],[20, 30], [20, 30], [20, 30], [20, 30],[30, 40], [30, 40], [30, 40], [30, 40],[40, 50], [40, 50], [40, 50], [40, 50]])# 设置y轴取值y_edges np.array([[10, 20], [20, 30], [30, 40], [40, 50],[10, 20], [20, 30], [30, 40], [40, 50],[10, 20], [20, 30], [30, 40], [40, 50],[10, 20], [20, 30], [30, 40], [40, 50],[10, 20], [20, 30], [30, 40], [40, 50]])# 设置X,Y对应点的值。即原始数据。hist np.array([[3.0], [0.0], [8.0], [4.0],[2.0], [4.0], [5.0], [7.0],[9.0], [2.0], [6.0], [3.0],[0.0], [3.0], [1.0], [0.0]])color_list [skyblue, lightgreen, bisque, gold,lightgreen, bisque, gold, lightpink,bisque, gold, lightpink, plum,gold, lightpink, plum, lightgray]for i in range(len(x_edges)):# 设置作图点的坐标xpos, ypos np.meshgrid(x_edges[i][:-1] - 2.5, y_edges[i][:-1] - 2.5)xpos xpos.flatten(F)ypos ypos.flatten(F)zpos np.zeros_like(xpos)# 设置柱形图大小dx 5 * np.ones_like(zpos)dy dx.copy()dz hist[i].flatten()# 设置坐标轴标签self.axes.set_xlabel(front)self.axes.set_ylabel(side)self.axes.set_zlabel(height)self.axes.bar3d(xpos, ypos, zpos, dx, dy, dz, colorcolor_list[i], zsortaverage) 运行模块 1.1 依赖包 包名含义安装方式sys系统包-PyQt5UI包pip install pyqt5项目包ui_utUI模块leetcode218_figure图表绘制模块 1.2 类 类myWindow运行窗口类继承父类QWidgetUi_matplot_demo实例化方式入参含义不需要入参实例化属性含义初值self.F实例化一个MyFigure的图表绘制类方法open_pic在UI中画图绑定bt_open控件close_pic关闭图片绑定bt_close控件 1.3 最后再封装一个main函数调用代码如下 import sys from PyQt5.QtWidgets import * from PyQt5.QtCore import * from ui_ut import Ui_matplot_demo from leetcode218_figure import MyFigureclass myWindow(QWidget, Ui_matplot_demo):def __init__(self):super(myWindow, self).__init__()self.setupUi(self)self.setWindowTitle(显示matplotlib绘制图形)self.setMinimumSize(0, 0)# 第五步定义MyFigure类的一个实例self.F MyFigure(width10, height6, dpi100)self.F.plot_cos()# 第六步在GUI的groupBox中创建一个布局用于添加MyFigure类的实例即图形后其他部件。# 在容器中添加一个groupbox对象在groupbox对象中创建布局self.groupBox QGroupBox(self.plt3d_module)self.groupBox.setMinimumSize(QSize(1100, 610))self.groupBox.setTitle(画图demo)def connect_bind():self.bt_open.clicked.connect(self.open_pic)self.bt_close.clicked.connect(self.close_pic)connect_bind()self.glo_plt_figure QGridLayout(self.groupBox)def open_pic(self):self.F MyFigure(width10, height6, dpi100)self.F.plot_3d()self.glo_plt_figure.addWidget(self.F, 0, 0)print(here)self.show()self.glo_plt_figure.addWidget(self.F, 0, 0)def close_pic(self):self.glo_plt_figure.removeWidget(self.F)self.show()def main():app QApplication(sys.argv)win myWindow()win.show()sys.exit(app.exec_())if __name__ __main__:main()
http://www.zqtcl.cn/news/495695/

相关文章:

  • 手机网站使用微信支付神级网页设计网站
  • 网站建站大约多少钱如何引流被动加好友
  • 哪些网站可以查企业信息大城县有做网站的吗
  • 上海网站建设电影联wordpress 分类title
  • 杭州网站建设招标免费seo排名优化
  • 网站建设服务费是否无形资产百度一下你就知道官网下载安装
  • 网站付款链接怎么做在线设计商标logo
  • 阿里巴巴做网站多少钱特大新闻凌晨刚刚发生
  • 网站如何做se设计师网站pintset
  • 上海网站制作机构wordpress 优酷免广告
  • 关于网站建设的名言网站开发的技术难点
  • 免费云建站廊坊seo外包
  • 个人网站建设方案书用备案的衡水市网站制作
  • 教育网站的建设品牌营销型网站作用
  • 金凤区建设交通局网站做洗衣液的企业网站
  • 南阳网站优化手机咋做网站
  • 做网站多少钱一年没有网站做cpa怎么赚钱
  • 二手房发布网站怎么做建站哪家好用兴田德润
  • 网站开发有几种深圳网站制作长沙
  • 为什么一个网站外链那么多公司团建活动
  • 公司门户网站建设策划书wordpress清空数据
  • 大兴专注高端网站建设交互设计留学
  • 想要黑掉一个网站 要怎么做网页设计师培训机构有吗
  • 做网站网站应该注意什么关于建设网站的会议纪要
  • 什么网站建设最简单做毕业设计实物的网站
  • 正规网站开发文案电商网站与企业网站区别
  • 襄阳做网站比较有实力的公司长沙出名的网站设计推广
  • 徐州网站设计师最便宜的购物平台
  • 网站域名和空间费用wordpress是是什么技术
  • 企业制作网站一般多少钱上海网站制作费用