IRubyはじめました
表題のとおり、 IRuby をはじめてみました
インストール
インストールは簡単で gem install iruby
でいけますが、私の利用している環境では依存している czmq が古かったので手動でインストールして回避しています。
git clone https://github.com/zeromq/czmq.git
cd czmq
./autogen
./configure --prefix=${HOME}/.local
make -j4
make install
gem install iruby cztop
LD_LIBRARY_PATH=${HOME}/.local/lib iruby
でインストールと動作はできます。画像貼るのがメンドイので ipython
貼っておきます。
{
"cells": [
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
" <script>\n",
" requirejs.config({paths: { 'plotly': ['https://cdn.plot.ly/plotly-latest.min'] }})\n",
" </script>\n",
"\n",
"\n",
"<div id=\"c34db0db-dc37-4ae3-a2b3-33ab99830b89\" style=\"height: 100%; width: 100%;\"></div>\n",
"\n",
"<script>\n",
" require(['plotly'], function(Plotly) { \n",
"Plotly.newPlot(\n",
" 'c34db0db-dc37-4ae3-a2b3-33ab99830b89',\n",
" [{\"x\":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20],\"y\":[100,81,64,49,36,25,16,9,4,1,0,1,4,9,16,25,36,49,64,81,100],\"type\":null,\"mode\":\"\"}],\n",
" {\"width\":1000,\"height\":500},\n",
" {\"linkText\":\"Export to plot.ly\",\"showLink\":true}\n",
")\n",
"\n",
"window.addEventListener('resize', function() {\n",
" Plotly.Plots.resize(document.getElementById('c34db0db-dc37-4ae3-a2b3-33ab99830b89'))\n",
"})\n",
" }) \n",
"</script>"
],
"text/plain": [
"#<Plotly::Offline::HTML:0x000056356f14be00 @id=\"c34db0db-dc37-4ae3-a2b3-33ab99830b89\", @data=[{:x=>[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20], :y=>[100, 81, 64, 49, 36, 25, 16, 9, 4, 1, 0, 1, 4, 9, 16, 25, 36, 49, 64, 81, 100], :type=>nil, :mode=>\"\"}], @layout={:width=>1000, :height=>500}, @config={:linkText=>\"Export to plot.ly\", :showLink=>true}, @embedded=true>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"#<CZTop::Socket::PUB:0x56356e7f3620 last_endpoint=\"tcp://127.0.0.1:45835\">"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"require 'daru'\n",
"require 'daru/plotly'\n",
"include Daru::Plotly::Methods\n",
"\n",
"dv = Daru::Vector.new((-10..10).map{|n| n ** 2 })\n",
"plot(dv, x: \"x\", y: \"y\").show"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Ruby 2.4.2",
"language": "ruby",
"name": "ruby"
},
"language_info": {
"file_extension": ".rb",
"mimetype": "application/x-ruby",
"name": "ruby",
"version": "2.4.2"
}
},
"nbformat": 4,
"nbformat_minor": 2
}