python动态仪表图_matplotlib仪表动态更新

我试图在matplotlib中创建一个这样的量规:

差不多可以了。以下是目前为止的代码:import numpy as np

import matplotlib.pyplot as plt

import matplotlib.animation as animation

from matplotlib.patches import Wedge

from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas

from matplotlib.figure import Figure

import sys,os

from PyQt4 import QtGui,QtCore

class MyMplCanvas(FigureCanvas):

"""Ultimately, this is a QWidget (as well as a FigureCanvasAgg, etc.)."""

def __init__(self, parent=None):

self.fig = Figure(facecolor='#DBE0E4')

self.axes = self.fig.add_subplot(111,axisbg='#DBE0E4')

self.axes.axis('off')

#here I create the contour of the gauge

#the two horizontal lines

x1=[-1,-0.6]

x2=[0.6,1.0]

y=[0.004,0.004]

self.axes.plot(x1,y,color='#646464')

self.axes.plot(x2,y,color='#646464')

#and the 2 circles(inner and outer)

circle1=plt.Circle((0,0),radius=1,fill=False)

circle1.set_edgecolor('#646464')

circle1.set_facecolor(None)

circle2=plt.Circle((0,0),radius=0.6,fill=False)

circle2.set_edgecolor('#646464')

circle2.set_facecolor(None)

self.axes.add_patch(circle1)

self.axes.add_patch(circle2)

#Scaling of the figure

self.axes.axis('scaled')

self.axes.set_xlim(-1.1,1.1)

self.axes.set_ylim(0,1.1)

FigureCanvas.__init__(self, self.fig)

self.setParent(parent)

FigureCanvas.updateGeometry(self)

class Gauge(MyMplCanvas):

def __init__(self,meter,parent=None):

MyMplCanvas.__init__(self)

self.patches=[]

#here I create the wedge to start

self.wedge=Wedge((0,0),0.99,1,179,width=0.38,facecolor='#FF0000')

self.patches.append(self.wedge)

self.timeClear=0

self.update_figure()

#self.Online_meter=meter

#here starts the update

timer=QtCore.QTimer(self)

timer.timeout.connect(self.update_figure)

timer.start(5000)

def update_figure(self):

#here is the update command

#every 5 sec, I call value from a measurement instrument

#here I let the program generate random values

self.timeClear=self.timeClear+1

#new_data=self.Online_meter.__call__()

self.wedge.set_theta1(180-np.random.random(1)*10/10*179)

self.axes.add_patch(self.wedge)

self.draw()

到目前为止,这是有效的。编写代码的目的是将它作为一个小部件添加到PyQt 4程序中。他们只剩下一个问题:当值更新时,量规突然改变,但我想看看量规是否更新(所以我想看看楔角的变化,移动如此缓慢),希望你们能帮我。

或者他们已经是一个很好的库,可以在pyqt4gui中插入好看的仪表?在

谢谢你提前帮了我!在

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值