是否有在ruby

时间:2018-03-16 20:40:52

标签: ruby matplotlib jupyter-notebook

正在尝试在jupyter笔记本中使用Ruby。使用Python我可以做到这一点

import matplotlib.image as mpimg

有没有人知道Ruby的等价物,我无法在任何iRuby或sciruby文档中找到它?

为了澄清一点,在我的gemfile中我有这个

gem 'iruby'
gem 'cztop'
gem 'matplotlib'

但似乎无法访问我在python中使用的image matplotlib部分。

我试图找到Ruby的版本,在Python中,我会像这样写

#importing some useful packages
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
...

%matplotlib inline

#reading in an image
image = mpimg.imread('test_images/solidWhiteRight.jpg')

#printing out some stats and plotting
print('This image is:', type(image), 'with dimesions:', image.shape)
plt.imshow(image)  #call as plt.imshow(gray, cmap='gray') to show a grayscaled image

非常感谢任何建议

1 个答案:

答案 0 :(得分:6)

这是我可以在MacOSX的jupyter笔记本上工作的程度:

require 'matplotlib/pyplot'
plt = Matplotlib::Pyplot

image = plt.imread 'test.png'

puts "This image's dimensions: #{image.shape}"

plt.imshow(image)
plt.show()

我使用你的Gemfile和额外的gem rbczmq来避免内核死亡(提示找到here):

gem 'iruby'
gem 'cztop'
gem 'matplotlib'
gem 'rbczmq'

请注意,我使用的是.png,因为matplotlib只能在没有安装PIL的情况下本地读取PNG。

结果如下:

enter image description here

在python版本中显示结果内联

enter image description here

似乎不可能。