Create dynamic updated graph with Python

前端 未结 5 1368
情歌与酒
情歌与酒 2021-02-04 19:25

I need your help to write a script in Python that will take dynamically changed data, the source of data is not matter here, and display graph on the screen.

I know how

5条回答
  •  清歌不尽
    2021-02-04 19:33

    I had the need to create a graph that updates with time. The most convenient solution I came up was to create a new graph each time. The issue was that the script won't be executed after the first graph is created, unless the window is closed manually. That issue was avoided by turning the interactive mode on as shown below

        for i in range(0,100): 
          fig1 = plt.figure(num=1,clear=True) # a figure is created with the id of 1
          createFigure(fig=fig1,id=1) # calls a function built by me which would insert data such that figure is 3d scatterplot
          plt.ion() # this turns the interactive mode on
          plt.show() # create the graph
          plt.pause(2) # pause the script for 2 seconds , the number of seconds here determine the time after that graph refreshes
    

    There are two important points to note here

    1. id of the figure - if the id of the figure is changed a new graph will be created every time, but if it is same it relevant graph would be updated.
    2. pause function - this stops the code from executing for the specified time period. If this is not applied graph will refresh almost immediately

提交回复
热议问题