加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

是否有在ruby中使用matplotlib.image的等价物

发布时间:2020-12-17 04:15:38 所属栏目:百科 来源:网络整理
导读:一直在尝试在jupyter笔记本中使用 Ruby.使用 Python我可以做到这一点 import matplotlib.image as mpimg 有没有人知道Ruby的等价物,我还没有能够在任何iRuby或sciruby文档中找到它? 为了澄清一点,在我的gemfile中我有这个 gem 'iruby'gem 'cztop'gem 'matpl
一直在尝试在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版本中显示内联结果:

似乎是不可能的.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读