一直在尝试在jupyter笔记本中使用
Ruby.使用
Python我可以做到这一点
- import matplotlib.image as mpimg
有没有人知道Ruby的等价物,我还没有能够在任何iRuby或sciruby文档中找到它?
为了澄清一点,在我的gemfile中我有这个
- gem 'iruby'
- gem 'cztop'
- gem 'matplotlib'
但似乎无法访问我用于在python中使用的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
非常感谢任何建议
解决方法
这是我可以在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.
这是结果的样子:
在python版本中显示内联结果:
似乎是不可能的.