QCustomPlot PyQt5 绘图代码示例

QCustomPlot PyQt5 绘图代码示例

from PyQt5.QtGui import QPen, QBrush, QColor
from QCustomPlot2 import *
from PyQt5.QtWidgets import QApplication
from PyQt5.QtCore import Qt
import sys
import math

app = QApplication(sys.argv)

# 创建绘图窗口
customPlot = QCustomPlot()
# 添加绘图图像
graph0 = customPlot.addGraph()
# 设置绘图颜色
graph0.setPen(QPen(Qt.blue))
# graph0.setBrush(QBrush(QColor(0, 0, 255, 20))) # brush可以填充曲线与横轴所夹的面积

graph1 = customPlot.addGraph()
graph1.setPen(QPen(Qt.red))
# 数据生成
x, y0, y1 = [], [], []
for i in range (251):
    x.append(i)
    y0.append(math.exp(-i/150.0)*math.cos(i/10.0)) # exponentially decaying cosine
    y1.append(math.exp(-i/150.0))                  # exponential envelope
# 添加数据
graph0.setData(x, y0)
graph1.setData(x, y1)
# 自动设置坐标轴范围及刻度
customPlot.rescaleAxes()
# 添加一些交互功能,拖拽图像,缩放,选择曲线
customPlot.setInteractions(QCP.Interactions(QCP.iRangeDrag | QCP.iRangeZoom | QCP.iSelectPlottables))
# 设置窗口大小
customPlot.setGeometry(400, 250, 542, 390)
# 显示图像
customPlot.show()

sys.exit(app.exec_())
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 8
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值