簡體   English   中英

動態發送數據到 plot 移動散點后,FuncAnimation 沒有響應

[英]FuncAnimation doesn't respond when after dynamically sending data to plot to move a scatter point

So I'm using FuncAnimation from matplotlib so dynamically plot some data as it arrives from a serial port (in my project is the vehicle class from dronekit, which is displayed with the green dot), what I have basically is the animation called which every循環正在接收一輛新車 class,其數據已更改,因此可以繪制,但由於某種原因,它繪制但在任務線程后幾秒鍾后(允許“刷新”它彈出的車輛數據和殺死 python (死亡之輪),這是我得到的:

在此處輸入圖像描述

我在 FuncAnimation 開始運行時調用的 function 中放置了一些跟蹤打印,如下所示:

def droneAnimation(i, vehicle, droneScatter):
     time.sleep(1)
     lat = [vehicle.location.global_relative_frame.lat]
     lon = [vehicle.location.global_relative_frame.lon]
     alt = [vehicle.location.global_relative_frame.alt]
     print("Alt received: " + str(alt))
     droneScatter._offsets3d = (lat,lon,alt)
     print("Changed pos")

如您所見,這些打印在最初的幾秒鍾內被觸發,但在幾次迭代后仍然崩潰。 FuncAnimation 是這樣調用的:

        fig,droneScatter = plotLiveSimpleFacade(vehicle,w,2)
        ani = FuncAnimation(fig,droneAnimation, fargs = (vehicle,droneScatter))
        plt.draw()
        plt.pause(0.1)
        m = threading.Thread(target=MissionStart(vehicle,hmax) , name = "MISSION")
        m.start()

供參考: fig 是一個 plt.figure(),droneScatter 只是一個散點,vehicle 是車輛 class 包含動態更新的數據,MissionStart 線程只是一個線程,使車輛 class 超時變化。

我還想提一下,無花果處於交互模式,並且軸限制設置得很好(我看到當您動態更改數據但不縮放軸時可能有問題),嘗試不同的 plt 組合.draw() 和 plt.plot(block = False) 導致我根本不繪圖,或者只是一個空白的 plot。

因為我不知道是什么原因造成的,所以我會在這個和線程上貼上dronekit標簽,看看是否有人知道!

我已經查看了 matplotlib 的線程,並且看起來使用這個所說的庫進行線程並不是最好的,因為它不是線程安全的,最好的辦法是查看 python 的多處理或以不同的方式解決問題。 您可以在這篇文章中找到更多信息

Matplotlib 當我想用

[英]Matplotlib doesn't show both datasets points on the figure when I want to create scatter plot with

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM