瀏覽代碼

Fix issue with matplotlib interactive mode window

Maxime 5 年之前
父節點
當前提交
1cdbfb181a
共有 1 個文件被更改,包括 9 次插入2 次删除
  1. 9 2
      gym_minigrid/window.py

+ 9 - 2
gym_minigrid/window.py

@@ -41,6 +41,10 @@ class Window:
         self.imshow_obj.set_data(img)
         self.fig.canvas.draw()
 
+        # Let matplotlib process UI events
+        # This is needed for interactive mode to work properly
+        plt.pause(0.001)
+
     def set_caption(self, text):
         """
         Set/update the caption text below the image
@@ -63,10 +67,13 @@ class Window:
 
         # If not blocking, trigger interactive mode
         if not block:
+            print('INTERACTIVE MODE')
             plt.ion()
 
-        # Show the plot, enter the matplotlib event loop
-        plt.show(block=block)
+        # Show the plot
+        # In non-interative mode, this enters the matplotlib event loop
+        # In interactive mode, this call does not block
+        plt.show()
 
     def close(self):
         """