# -*- 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_()) ####才接触,项目急没有细研究,有错误的改正的地方,望大家不吝指出

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

  1. Python使用Plotly绘图工具,绘制直方图

    今天我们再来讲解一下Python使用Plotly绘图工具如何绘制直方图 使用plotly绘制直方图需要用到graph_objs包中的Histogram函数 我们将数据赋值给函数中的x变量,x = da ...

  2. Python:matplotlib绘制直方图

    使用hist方法来绘制直方图:     绘制直方图,最主要的是一个数据集data和需要划分的区间数量bins,另外你也可以设置一些颜色.类型参数: plt.hist(np.random.randn(1 ...

  3. NumPy使用 Matplotlib 绘制直方图

    NumPy - 使用 Matplotlib 绘制直方图 NumPy 有一个numpy.histogram()函数,它是数据的频率分布的图形表示. 水平尺寸相等的矩形对应于类间隔,称为bin,变量hei ...

  4. matplotlib绘制直方图【柱状图】

    代码: def drawBar(): xticks = ['A', 'B', 'C', 'D', 'E']#每个柱的下标说明 gradeGroup = {'A':200,'B':250,'C':330 ...

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

    title: "Python实现图像直方图均衡化算法" date: 2018-06-12T17:10:48+08:00 tags: [""] categorie ...

  6. 关于matplotlib绘制直方图偏移的问题

    在使用pyplot绘制直方图的时候我发现了一个问题,在给函数.hist()传参的时候,如果传入的组数不是刚刚好(就是说这个组数如果是使用(最大值-最小值)/组距计算出来,而这个数字不是整除得来而是取整 ...

  7. 使用Python统计函数绘制简单图形matplotlib

    1.bar() -- 绘制柱状图 plt.bar(x,y,align="center",color="b",tick_label=["a", ...

  8. Python turtle绘制阴阳太极图代码解析

    本文详细分析如何使用Python turtle绘制阴阳太极图,先来分解这个图形,图片中有四种颜色,每条曲线上的箭头表示乌龟移动的方向,首先从中心画一个半圆(红线),以红线所示圆的直径作半径画一个校园, ...

  9. MFC绘制直方图和饼图

    转载原文: Normal 0 7.8 磅 0 2 false false false EN-US ZH-CN X-NONE /* Style Definitions */ table.MsoNorma ...

随机推荐

  1. Nginx配置不当可能导致的安全问题

    Nginx配置不当可能导致的安全问题 Auther: Spark1e目前很多网站使用了nginx或者tenginx(淘宝基于Nginx研发的web服务器)来做反向代理和静态服务器,ningx的配置文件 ...

  2. rpm 包的安装:

    参考博客: https://www.cnblogs.com/lzj87980239/p/3611776.html 如果已经安装了一个 rpm 包, 然后这个安装包又重新打了, 但是安装包的名字没有修改 ...

  3. java基础语法(三大基础)

    一.标识符 标识符是用于包名.类名.变量名.方法名.对象名.数组名.集合名等的命名:   规则: (1)可以使用英文字母.阿拉伯数字.下划线_.$符号 (2)不能以数字开头 (3)不能使用Java中的 ...

  4. java.lang.IllegalAccessError: org.apache.commons.dbcp.DelegatingPreparedStatement.isClosed()Z

    做spring和mybaits整合时出现的错误,让这个问题困扰了一早上,通过查资料终于把这个问题解决了 具体问题描述: java.lang.IllegalAccessError: org.apache ...

  5. vs2017 .net core 项目调试浏览器网页闪退Bug

    from:https://blog.csdn.net/qq_36330228/article/details/82152187 vs更新2017最新版本后,项目调试浏览器莫名其妙出现闪退,每次都TMD ...

  6. 一个spinner控件使用的实例

    布局文件 <?xml version="1.0" encoding="utf-8"?><android.support.constraint. ...

  7. C#中的as关键字

    你能进到这篇文章…… 首先你可能明白类似于 double num=0;int m=(int) num; 或者你明白 int m=209;String str=m.toString();或者说你甚至见过 ...

  8. 文本框defalutValue的使用

    以下页面中的文本框的值无论怎么改变,点击“原始值”按钮始终会得到初始页面的时候的值,即“ffffffffffffff” <!DOCTYPE html> <html> <h ...

  9. laravel blog edit

    模板复制create的模板 主要修改的地方 <form action="{{ url('admin/article/'.$article->id) }}" method ...

  10. 多个for循环嵌套会影响速度

    在复现Meta-SR的过程中,发现如果嵌套多个for 循环会使速度过慢.这是下面实验得出的结论: import time t1 = time.time() a = range(3000) b = ra ...