Skip to content

Commit 0bf5d2f

Browse files
committed
Rewrite IRuby integration
1 parent 6cb256e commit 0bf5d2f

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

lib/matplotlib/iruby.rb

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
require 'pycall'
1+
require 'matplotlib'
22

33
module Matplotlib
44
module IRuby
@@ -85,17 +85,18 @@ def execute_request(msg)
8585
}.freeze
8686

8787
module Helper
88+
BytesIO = PyCall.import_module('io').BytesIO
89+
8890
def register_formats
89-
bytes_io = PyCall.import_module('io').BytesIO
9091
type { Figure }
9192
AGG_FORMATS.each do |mime, format|
9293
format mime do |fig|
93-
unless fig.canvas.get_supported_filetypes.().has_key?(format)
94+
unless fig.canvas.get_supported_filetypes.has_key?(format)
9495
raise Error, "Unable to display a figure in #{format} format"
9596
end
96-
io = bytes_io.()
97-
fig.canvas.print_figure.(io, format: format, bbox_inches: 'tight')
98-
io.getvalue.()
97+
io = BytesIO.new
98+
fig.canvas.print_figure(io, format: format, bbox_inches: 'tight')
99+
io.getvalue
99100
end
100101
end
101102
end
@@ -237,17 +238,17 @@ def flush_figures
237238
# @param [true, false] close If true, a `plt.close('all')` call is automatically issued after sending all the figures.
238239
def show_figures(close=false)
239240
_pylab_helpers = PyCall.import_module('matplotlib._pylab_helpers')
240-
gcf = PyCall.getattr(_pylab_helpers, :Gcf)
241+
gcf = _pylab_helpers.Gcf
241242
kernel = ::IRuby::Kernel.instance
242-
gcf.get_all_fig_managers.().each do |fig_manager|
243+
gcf.get_all_fig_managers.each do |fig_manager|
243244
data = ::IRuby::Display.display(fig_manager.canvas.figure)
244245
kernel.session.send(:publish, :execute_result,
245246
data: data,
246247
metadata: {},
247248
execution_count: kernel.instance_variable_get(:@execution_count))
248249
end
249250
ensure
250-
unless gcf.get_all_fig_managers.().none?
251+
unless gcf.get_all_fig_managers.nil?
251252
Matplotlib::Pyplot.close('all')
252253
end
253254
end

0 commit comments

Comments
 (0)