python pyqt绘制直方图

# -*- coding: utf-8 -*-
"""
In this example we draw two different kinds of histogram.
"""

from qtpy import QtWidgets, QtGui, QtCore
from qtpy.QtWidgets import QApplication, QWidget
import datetime as dt
from vnpy.trader import *
from vnpy.trader.uiKLine  import *
from vnpy.trader.widget.crosshairTool import  CrosshairTool
import pyqtgraph as pg
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.mlab as mlab
import sys
class HistogramLUTWidget(QWidget):
    def __init__(self, data, parent=None):
        self.parent = parent
        self.data = data
        super(HistogramLUTWidget, self).__init__(parent)  # 继承
    # 界面布局
        self.pw=pg.PlotWidget()

        self.lay_KL = pg.GraphicsLayout(border=(100, 100, 100))
        self.lay_KL.setContentsMargins(10, 10, 10, 10)
        self.lay_KL.setSpacing(0)
        self.lay_KL.setBorder(color=(255, 255, 255, 255), width=0.8)
        self.lay_KL.setZValue(0)
        self.pw.setCentralItem(self.lay_KL)
    #     # 设置横坐标
    #     xdict = dict(enumerate(self.data["timeList"]))
    #     self.axisTime = MyStringAxis(xdict, orientation=‘bottom‘)
    #     # 初始化子图
        self.initplotpnl()
        # # 注册十字光标
        x=[]
        viwe = self.plt
        self.crosshair = CrosshairTool(self.pw, x, viwe, self)
        # 设置界面
        self.vb = QtWidgets.QVBoxLayout()
        self.vb.addWidget(self.pw)
        self.setLayout(self.vb)
    # ----------------------------------------------------------------------

    def initplotpnl(self, xmin=0, xmax=-1):
        vals = np.hstack(self.data)
        xMin = min(self.data)
        xMax = max(self.data)
        #histogram
        #y, x = np.histogram(vals, bins=np.linspace(xMin,xMax, 100),normed=False,density=True)
        # #hist
        nx, xbins, ptchs = plt.hist(self.data, bins=50, normed=True, facecolor=‘black‘, edgecolor=‘black‘,alpha=1,histtype = ‘bar‘)
        histo = plt.hist(self.data, 50)
        vb = CustomViewBox()
        # self.plt=pg.PlotItem(viewBox=vb,  axisItems={‘bottom‘: self.axisTime})#设置x轴
        self.plt = pg.PlotItem(viewBox=vb)
        leng_ = len(self.data)
        self.plt.setRange(xRange=(0, leng_), yRange=(xMin, xMax))
        # #histogram
        # self.plt.plot(x, y, stepMode=True, fillLevel=0, brush=(0, 0, 255, 50),size=0.4)#绘制统计所得到的概率密度,直方图,没有边界分割线
        ##hist  bar
        width = xbins[1] - xbins[0]  # Width of each bin.
        #self.plt.plot(x,y,width=width)# 绘制统计所得到的概率密度,线形图
        self.pi=pg.BarGraphItem(x=histo[1][0:50],height=histo[0],width=width, color=‘y‘,)# 绘制统计所得到的概率密度,bar图
        self.plt.addItem(self.pi)
        self.lay_KL.addItem(self.plt)

    def refresh(self):
        """
        刷新子图的现实范围
        """
        leng_ = len(self.data)
        xMin = min(self.data)
        xMax = max(self.data)
        self.plt.setRange(xRange=(0, leng_), yRange=(xMin, xMax))

if __name__ == ‘__main__‘:
    app = QApplication(sys.argv)
    ex = HistogramLUTWidget()
    sys.exit(app.exec_())

####才接触,项目急没有细研究,有错误的改正的地方,望大家不吝指出
时间: 2024-08-07 12:05:17

python pyqt绘制直方图的相关文章

用Python绘制直方图

计算频数: 给定一个序列t: hist = {} for x in t: hist[x] = hist.get(x,0)+1 得到的结果是一个将值映射到其频数的字典.将其除以n即可把频数转换成频率,这称为归一化: n = float(len(t)) pmf = {} for x, freq in hist.items(): pmf[x] = freq/n 绘制直方图: Vals, freqs = hist.Render() rectangles = pyplot.bar(vals, freqs)

python(pyqt)开发环境搭建

eric+pyqt 安装(python开发工具) 更多 0 Python python Eric是一个开源的.跨平台的python&ruby集成开发环境,基于python和pyqt运行.eric有以下特点 1.跨Windows/Linux/Mac等开台 2.调试器给力.支持设置断点,单步调试,查看变量值. 3.支持工程. 4.支持自动补全. 5.支持智能感知,即输入变量名和一个点,会自动提示可能的函数. 6.自动语法检查.每次保存时自动检查. 7.支持自动缩进,会自动判断if, while等语句

在图片上画矩形并高亮显示矩形区域、统计矩形区域中像素情况并绘制直方图

<学习OpenCV>中文版第4章第3题 提纲 题目要求 程序代码 结果图片 题目要求: ①允许用户在图片上选择一个矩形区域,当鼠标放开,高亮显示矩形区域 ②在另一个独立窗口中,使用绘图函数绘制一个图表,分别用蓝.绿和红色表示选中区域中各种颜色的像素在指定数值范围内的数量. 程序代码: 1 #include "stdafx.h" 2 #include <cv.h> 3 #include <highgui.h> 4 using namespace std

OpenCV2马拉松第8圈——绘制直方图

收入囊中 灰度直方图 彩色直方图 葵花宝典 直方图的理论还是非常丰富的,应用也很多,诸如: 直方图均衡化 直方图匹配(meanshift,camshift) 在这里,我先介绍基础,如何绘制图像的直方图. 拿灰度图像来说,直方图就是不同的灰度对应的个数,横轴(x)就是[0,256), 纵轴(y)就是对应的个数 如下图,分别是灰度直方图和彩色直方图 初识API C++: void calcHist(const Mat* images, int nimages, const int* channels

numpy和matplotlib绘制直方图

使用 Matplotlib Matplotlib 中有直方图绘制函数:matplotlib.pyplot.hist()它可以直接统计并绘制直方图.你应该使用函数 calcHist() 或 np.histogram()统计直方图. 1 使用pyplot.hist() 显示灰度图像直方图,代码如下: import cv2 import numpy as np from matplotlib import pyplot as plt img = cv2.imread('image/lufei.jpeg

Python + Matplotlib 绘制 Penrose 铺砌

效果是不是很漂亮呢? 代码如下: #----------------------------------------- # Python + Matplotlib 绘制 Penrose 铺砌 # by Zhao Liang [email protected] #----------------------------------------- import matplotlib.pyplot as plt import numpy as np from matplotlib.path impor

opencv学习笔记9 直方图均衡化并绘制直方图

进行直方图均衡化并将直方图绘制出来,主要需要如下几个函数: 1.CVAPI(void) cvEqualizeHist( const CvArr* src, CvArr* dst ); 这个函数用起来十分简单,只需要传入源图像以及已初始化的目标图像即可. 第一个参数:const CvArr* src:待处理的源图像: 第二个参数:CvArr* dst:目标图像: 在cvEqualizeHist()中,原始图像及目标图像必须是单通道,大小相同的8位图像.对于彩色图像,必须先利用cvSplite()将

Python + Matplotlib 绘制 Aztec Diamond 图的随机铺砌

一个 $n$ 阶的 Aztec Diamond 图,是指依次将 $2,4,\ldots,2n,2n,\ldots,4,2$ 个单位方格摞在一起得到的对称图形(于是图中一共有 $2n(n+1)$ 个单位方格).下图是 $n=5$ 时候的例子: 对一个 $n$ 阶的 Aztec Diamond 图,用 $1\times 2$ 的多米诺骨牌铺砌它,总共有 $2^{n(n+1)}$ 种不同的方法.(这里不考虑对称性,比如全部用水平的骨牌铺砌和全部用竖直的骨牌铺砌,两种方法是不同的) 一个有趣的问题是,对

Python实现图像直方图均衡化算法

title: "Python实现图像直方图均衡化算法" date: 2018-06-12T17:10:48+08:00 tags: [""] categories: ["python"] 效果图 代码 #!/usr/bin/env python3 # coding=utf-8 import matplotlib.image as mpimg from matplotlib import pyplot as plt import sys impor