2017-10-26 32 views
0

pyQtGraphを使ってライブグラフ(株式取引の進化についてのグラフ)をプロットしようとしていて、解決できなかったいくつかの質問があります:pyQtGraphウィジェットの境界を検出してスクロールを開始

  1. 左から右にペイントを開始したいのですが(これはデフォルトで起こります)、バウンディングボックスの右側に移動して新しいデータをすべてフィットさせるのではなく、スクロールしたい新しいデータは右側から入力し、古いデータは左側から消えます。

  2. numpy配列にデータを追加すると、配列の新しいインスタンスが作成されます。私はこれを望んでいない。 pyQtGraphプロットにnumpy配列の範囲でデータを取得するように指示する方法はありますか?私は最初に10000浮動小数点数の配列をインスタンス化し、pyQtGraphに最初の100浮動小数点数をプロットするように指示できますか?

  3. 一方、私は配列の場所を変更してスクロールをシミュレートするために数値をシフトすることができます。 pyQtGraphをnumpyの配列をリングとして使用する方法はありますか?私は唯一のインデックスと、すべてのグラフの開始が割り当てなどなしで動作することを伝える必要があります。この方法で...ここで

私がこれまで持っているコード、かなりシンプル:

class Grapher(QtWidgets.QMainWindow, Ui_MainWindow): 
    def __init__(self): 
     QtWidgets.QMainWindow.__init__(self) 
     Ui_MainWindow.__init__(self) 
     self.setupUi(self) 

     self.graphicsView.setTitle('My Graph') 
     self.graphicsView.setLabel('bottom', 'X axis') 
     self.graphicsView.setLabel('left', 'Y axis') 
     self.graphicsView.setLimits(xMin=0, yMin=0) 
     self.graphicsView.showGrid(x=True, y=True) 
     self.x=np.array(); 
     self.y=np.array(); 

     self._timer=QtCore.QTimer() 
     self._timer.timeout.connect(self.update) 
     self._timer.start(1000) 
     self._timerCounter=0; 

    def update(self): 
     self.x=np.append(self.x, [self._timerCounter]); 
     self.y=np.append(self.y, [math.sin(self._timerCounter)]) 
     self.graphicsView.plot(self.x, self.y) 
     self._timerCounter+=1; 

ありがとうございます。

+0

はあなたのコードを表示します!!!! – eyllanesc

答えて

0

これは私がやる方法です。 、たとえば、あなたは1000ポイントの配列を持っていますが、唯一の200点をプロットしたい場合:

class Grapher(QtWidgets.QMainWindow, Ui_MainWindow): 

    def __init__(self): 
     QtWidgets.QMainWindow.__init__(self) 
     Ui_MainWindow.__init__(self) 
     self.setupUi(self) 

     self.graphicsView.setTitle('My Graph') 
     self.graphicsView.setLabel('bottom', 'X axis') 
     self.graphicsView.setLabel('left', 'Y axis') 
     self.graphicsView.setLimits(xMin=0, yMin=0) 
     self.graphicsView.showGrid(x=True, y=True) 
     self.plot = self.graphicsView.plot() 

     self.ptr = 0 
     self.x = np.zeros(1000) 
     self.y = np.zeros(1000) 
     self.xPlot = np.zeros(200) 
     self.yPlot = np.zeros(200) 

     self._timer = QtCore.QTimer() 
     self._timer.timeout.connect(self.update) 
     self._timer.start(1000) 
     self._timerCounter = 0 

    def update(self): 

     xNew = self._timerCounter 
     yNew = math.sin(xNew) 
     self.y[self.ptr] = math.sin(self._timerCounter) 
     self.x[self.ptr] = self._timerCounter 

     if self.ptr < 200: 
      # Normal assignment 
      self.yPlot[self.ptr] = self.y[self.ptr] 
      self.xPlot[self.ptr] = self.x[self.ptr] 
      self.plot.setData(self.xPlot[1:self.ptr + 1], 
           self.yPlot[1:self.ptr + 1]) 

     else: 
      # Shift arrays and then assign 
      self.yPlot[:-1] = self.yPlot[1:] 
      self.yPlot[-1] = self.y[self.ptr] 
      self.xPlot[:-1] = self.xPlot[1:] 
      self.xPlot[-1] = self.x[self.ptr] 
      self.plot.setData(self.xPlot, self.yPlot) 

     self.ptr += 1 
+0

ところで、self.xPlot [1:self.ptr + 1]は新しい配列のインスタンスを作成しませんか? – Notbad

+0

私は本当に知りません。私はそれがself.xplotの唯一のビューだと思うが、私はnumpyの内部動作の適切な知識が不足している – Federico

関連する問題