lib/matplotlib/iruby.rb in matplotlib-0.1.0.alpha.20170426 vs lib/matplotlib/iruby.rb in matplotlib-1.0.0

- old
+ new

@@ -1,6 +1,6 @@ -require 'pycall' +require 'matplotlib' module Matplotlib module IRuby module HookExtension def self.extended(obj) @@ -83,21 +83,22 @@ "application/postscript" => "ps", "image/svg+xml" => "svg" }.freeze module Helper + BytesIO = PyCall.import_module('io').BytesIO + def register_formats - bytes_io = PyCall.import_module('io').BytesIO type { Figure } AGG_FORMATS.each do |mime, format| format mime do |fig| - unless fig.canvas.get_supported_filetypes.().has_key?(format) + unless fig.canvas.get_supported_filetypes.has_key?(format) raise Error, "Unable to display a figure in #{format} format" end - io = bytes_io.() - fig.canvas.print_figure.(io, format: format, bbox_inches: 'tight') - io.getvalue.() + io = BytesIO.new + fig.canvas.print_figure(io, format: format, bbox_inches: 'tight') + io.getvalue end end end end @@ -235,20 +236,20 @@ # This method is based on ipykernel.pylab.backend_inline.show function. # # @param [true, false] close If true, a `plt.close('all')` call is automatically issued after sending all the figures. def show_figures(close=false) _pylab_helpers = PyCall.import_module('matplotlib._pylab_helpers') - gcf = PyCall.getattr(_pylab_helpers, :Gcf) + gcf = _pylab_helpers.Gcf kernel = ::IRuby::Kernel.instance - gcf.get_all_fig_managers.().each do |fig_manager| + gcf.get_all_fig_managers.each do |fig_manager| data = ::IRuby::Display.display(fig_manager.canvas.figure) kernel.session.send(:publish, :execute_result, data: data, metadata: {}, execution_count: kernel.instance_variable_get(:@execution_count)) end ensure - unless gcf.get_all_fig_managers.().none? + unless gcf.get_all_fig_managers.nil? Matplotlib::Pyplot.close('all') end end end end