【问题标题】:Python: PyQtGraph is not showing animationPython:PyQtGraph 不显示动画
【发布时间】:2018-06-12 13:36:41
【问题描述】:

我有一个包含多个节点的图表。一旦用户单击任何节点,图形应该以这样的方式双曲线化,即单击的节点应该位于图形的中心(通常是 2D 坐标系原点的位置)。当我单击时,图中没有更新,但是节点(散点)的新坐标值会在本地保存的文件中更新。下面是用于渲染和更新的函数。

# Function to render the H2 tree map embedded in Poincare disc
def render_h2_tree(positions):

    global adj
    global nodeText
    # Configuring the PyQt graphic window
    pg.setConfigOption('background', 'k')
    pg.setConfigOption('foreground', 'w')
    pg.setConfigOptions(antialias=True)

    w = pg.GraphicsWindow()                 # creating an instance of the PyQt GraphicsWindow
    w.setWindowTitle('H2 tree for Emails')  # set the title of the graphic window
    v = w.addViewBox()                      # add a view box to the graphic window
    v.setAspectLocked()
    g = Graph()                             # create an instance of the class Graph
    v.addItem(g)                            # add the created graph instance to the view box

    g.setData(pos=positions, adj=adj, size=0.01, pxMode=False, text=nodeText)  # set the node in the graphic window

    # Start Qt event loop unless running in interactive mode or using pyside.
    import sys

    if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
        QtGui.QApplication.instance().exec_()

我在这里做错了什么?谢谢。

【问题讨论】:

    标签: python graph pyqtgraph


    【解决方案1】:

    所以我能够解决这个问题。修改后的代码如下:

    w = pg.GraphicsWindow()                 # creating an instance of the PyQt GraphicsWindow
    v = w.addViewBox()                      # add a view box to the graphic window
    g = Graph()                             # create an instance of the class Graph
    
    # Function to render the H2 tree map embedded in Poincare disc
    def render_h2_tree(positions):
    
        global adj
        global nodeText
        global w
        global v
        global g
    
        # Configuring the PyQt graphic window
        pg.setConfigOption('background', 'k')
        pg.setConfigOption('foreground', 'w')
        pg.setConfigOptions(antialias=True)
    
        w.setWindowTitle('H2 tree for Emails')  # set the title of the graphic window        
        v.setAspectLocked()        
        v.addItem(g)                            # add the created graph instance to the view box
    
        g.setData(pos=positions, adj=adj, size=0.01, pxMode=False, text=nodeText)  # set the node in the graphic window
    
        # Start Qt event loop unless running in interactive mode or using pyside.
        import sys
    
        if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
            QtGui.QApplication.instance().exec_()
    

    在将图形窗口、视图框和图形声明为全局项后,我确保不会为其创建任何新实例。这样,当单击窗口中的任何节点时,所有这些项目的实例都保持不变,然后可以将节点绘制到新的 2D 位置。

    【讨论】:

      猜你喜欢
      • 2013-04-09
      • 1970-01-01
      • 2022-01-15
      • 2015-09-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-23
      • 2012-09-15
      相关资源
      最近更新 更多