|
1 |
| -require 'pycall' |
| 1 | +require 'matplotlib' |
2 | 2 |
|
3 | 3 | module Matplotlib
|
4 | 4 | module IRuby
|
@@ -85,17 +85,18 @@ def execute_request(msg)
|
85 | 85 | }.freeze
|
86 | 86 |
|
87 | 87 | module Helper
|
| 88 | + BytesIO = PyCall.import_module('io').BytesIO |
| 89 | + |
88 | 90 | def register_formats
|
89 |
| - bytes_io = PyCall.import_module('io').BytesIO |
90 | 91 | type { Figure }
|
91 | 92 | AGG_FORMATS.each do |mime, format|
|
92 | 93 | format mime do |fig|
|
93 |
| - unless fig.canvas.get_supported_filetypes.().has_key?(format) |
| 94 | + unless fig.canvas.get_supported_filetypes.has_key?(format) |
94 | 95 | raise Error, "Unable to display a figure in #{format} format"
|
95 | 96 | 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 |
99 | 100 | end
|
100 | 101 | end
|
101 | 102 | end
|
@@ -237,17 +238,17 @@ def flush_figures
|
237 | 238 | # @param [true, false] close If true, a `plt.close('all')` call is automatically issued after sending all the figures.
|
238 | 239 | def show_figures(close=false)
|
239 | 240 | _pylab_helpers = PyCall.import_module('matplotlib._pylab_helpers')
|
240 |
| - gcf = PyCall.getattr(_pylab_helpers, :Gcf) |
| 241 | + gcf = _pylab_helpers.Gcf |
241 | 242 | kernel = ::IRuby::Kernel.instance
|
242 |
| - gcf.get_all_fig_managers.().each do |fig_manager| |
| 243 | + gcf.get_all_fig_managers.each do |fig_manager| |
243 | 244 | data = ::IRuby::Display.display(fig_manager.canvas.figure)
|
244 | 245 | kernel.session.send(:publish, :execute_result,
|
245 | 246 | data: data,
|
246 | 247 | metadata: {},
|
247 | 248 | execution_count: kernel.instance_variable_get(:@execution_count))
|
248 | 249 | end
|
249 | 250 | ensure
|
250 |
| - unless gcf.get_all_fig_managers.().none? |
| 251 | + unless gcf.get_all_fig_managers.nil? |
251 | 252 | Matplotlib::Pyplot.close('all')
|
252 | 253 | end
|
253 | 254 | end
|
|
0 commit comments