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_()) ####才接触,项目急没有细研究,有错误的改正的地方,望大家不吝指出
python pyqt绘制直方图的更多相关文章
- Python使用Plotly绘图工具,绘制直方图
今天我们再来讲解一下Python使用Plotly绘图工具如何绘制直方图 使用plotly绘制直方图需要用到graph_objs包中的Histogram函数 我们将数据赋值给函数中的x变量,x = da ...
- Python:matplotlib绘制直方图
使用hist方法来绘制直方图: 绘制直方图,最主要的是一个数据集data和需要划分的区间数量bins,另外你也可以设置一些颜色.类型参数: plt.hist(np.random.randn(1 ...
- NumPy使用 Matplotlib 绘制直方图
NumPy - 使用 Matplotlib 绘制直方图 NumPy 有一个numpy.histogram()函数,它是数据的频率分布的图形表示. 水平尺寸相等的矩形对应于类间隔,称为bin,变量hei ...
- matplotlib绘制直方图【柱状图】
代码: def drawBar(): xticks = ['A', 'B', 'C', 'D', 'E']#每个柱的下标说明 gradeGroup = {'A':200,'B':250,'C':330 ...
- Python实现图像直方图均衡化算法
title: "Python实现图像直方图均衡化算法" date: 2018-06-12T17:10:48+08:00 tags: [""] categorie ...
- 关于matplotlib绘制直方图偏移的问题
在使用pyplot绘制直方图的时候我发现了一个问题,在给函数.hist()传参的时候,如果传入的组数不是刚刚好(就是说这个组数如果是使用(最大值-最小值)/组距计算出来,而这个数字不是整除得来而是取整 ...
- 使用Python统计函数绘制简单图形matplotlib
1.bar() -- 绘制柱状图 plt.bar(x,y,align="center",color="b",tick_label=["a", ...
- Python turtle绘制阴阳太极图代码解析
本文详细分析如何使用Python turtle绘制阴阳太极图,先来分解这个图形,图片中有四种颜色,每条曲线上的箭头表示乌龟移动的方向,首先从中心画一个半圆(红线),以红线所示圆的直径作半径画一个校园, ...
- MFC绘制直方图和饼图
转载原文: Normal 0 7.8 磅 0 2 false false false EN-US ZH-CN X-NONE /* Style Definitions */ table.MsoNorma ...
随机推荐
- 测试客户端连接12c ASM实例
环境:Oracle 12.2.0.1 RAC 背景:用户反映12c ASM创建的用户具备sysasm权限,但无法在客户端连接到ASM实例,且没有报错. 1.ASM实例创建用户赋予sysasm权限 2. ...
- matlab——之class类(详细总结)
https://blog.csdn.net/qinze5857/article/details/80545885 开篇:搜了一下网上介绍matlab的class类,信息不全,且总结不全面,于是单独he ...
- windows 中的类似于sudo的命令(在cmd中以另一个用户的身份运行命令)
linux中我们习惯用sudo命令来临时用另一个用户的身份执行命令. windows中,通常我们需要用管理员权限执行命令的时候通常是 右键->run as administrator. 用着键盘 ...
- [python 练习] 计算个税
题目:利用python计算个税 说明:python有序字典的使用 代码: # -*- coding: utf-8 -*- from collections import OrderedDict # 税 ...
- Unity3d中角色模型和角色名字保持相对位置
3D游戏中,经常遇到这样的情况.角色模型上需要显示角色名字或者血条等信息. 如果用一个摄像机会有可能出现名字或血条显示不正常等问题,所以我采用两个摄像机.一个渲染名字或血条等UI,另一个渲染角色模型. ...
- uva 10123 - No Tipping dp 记忆化搜索
这题的题意是 在双脚天平上有N块东西,依次从上面取走一些,最后使得这个天平保持平衡! 解题: 逆着来依次放入,如果可行那就可以,记得得有木板自身的重量. /********************** ...
- ng2
angularjs2的环境问题解决了好久. 百度到的答案也是各种各样还解决不了我的问题. 好在这几天经过不断的测试终于给解决了. ERROR in AppModule is not an NgModu ...
- CCF CSP 201503-2 数字排序 (map+自定义排序)
题目链接:http://118.190.20.162/view.page?gpid=T26 返回试题列表 问题描述 试题编号: 201503-2 试题名称: 数字排序 时间限制: 1.0s 内存限制: ...
- ss命令详解
ss是Socket Statistics的缩写.顾名思义,ss命令可以用来获取socket统计信息,它可以显示和netstat类似的内容.ss的优势在于它能够显示更多更详细的有关TCP和连接状态的信息 ...
- 顶尖 API 文档管理工具 (Yapi)
原文地址:https://www.jianshu.com/p/a97d2efb23c5