From 3ec5dffeccf3ff91a90f35f7f7619a5ade54c7af Mon Sep 17 00:00:00 2001
From: zheng-yongping <zheng-yongping@hotmail.com>
Date: Mon, 16 Sep 2019 08:45:13 +0800
Subject: [PATCH] feat: plt.show

---
 lib/matplotlib/iruby.rb | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)

diff --git a/lib/matplotlib/iruby.rb b/lib/matplotlib/iruby.rb
index 904989f..e17173f 100644
--- a/lib/matplotlib/iruby.rb
+++ b/lib/matplotlib/iruby.rb
@@ -1,4 +1,5 @@
 require 'matplotlib'
+require 'matplotlib/pyplot'
 
 module Matplotlib
   module IRuby
@@ -188,13 +189,11 @@ def find_gui_and_backend(gui=nil, gui_select=nil)
       #
       # @param [String, Symbol] backend a name of matplotlib backend
       def activate_matplotlib(backend)
-        require 'matplotlib'
         Matplotlib.interactive(true)
 
         backend = backend.to_s
         Matplotlib.rcParams['backend'] = backend
 
-        require 'matplotlib/pyplot'
         Matplotlib::Pyplot.switch_backend(backend)
 
         # TODO: should support wrapping python function
@@ -254,6 +253,21 @@ def show_figures(close=false)
       end
     end
   end
+
+  Pyplot.module_eval do
+    def self.show(close=true)
+      _pylab_helpers = PyCall.import_module('matplotlib._pylab_helpers')
+      gcf = _pylab_helpers.Gcf
+      gcf.get_all_fig_managers.each do |fig_manager|
+        ::IRuby::display(fig_manager.canvas.figure)
+      end
+      return
+    ensure
+      if close && gcf.get_all_fig_managers.length > 0
+        close('all')
+      end
+    end
+  end
 end
 
 ::IRuby::Display::Registry.module_eval do