{ "metadata": { "language": "ruby", "name": "" }, "nbformat": 3, "nbformat_minor": 0, "worksheets": [ { "cells": [ { "cell_type": "code", "collapsed": false, "input": [ "require 'nyaplot'\n", "require 'nyaplot3d'" ], "language": "python", "metadata": {}, "outputs": [ { "metadata": {}, "output_type": "pyout", "prompt_number": 1, "text": [ "true" ] } ], "prompt_number": 1 }, { "cell_type": "code", "collapsed": false, "input": [ "Nyaplot.init_iruby" ], "language": "python", "metadata": {}, "outputs": [ { "html": [ "\n" ], "metadata": {}, "output_type": "pyout", "prompt_number": 9, "text": [ "\"\\n\"" ] } ], "prompt_number": 9 }, { "cell_type": "code", "collapsed": false, "input": [ "x=[];y=[];z=[]\n", "-10.step(10, 0.5) do |i|\n", " -10.step(10, 0.5) do |j|\n", " x.push(i)\n", " y.push(j)\n", " z.push(Math.sin(Math.sqrt(i*i+j*j))/Math.sqrt(i*i+j*j))\n", " end\n", "end\n", "z.map!{|val| next (val.nan? ? 0 : val)} #(0,0) will be -inf" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [] } ], "prompt_number": 11 }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Wireframe" ] }, { "cell_type": "code", "collapsed": false, "input": [ "plot = Nyaplot::Plot3D.new\n", "plot.add(:wireframe, x, y, z)\n", "plot.show" ], "language": "python", "metadata": {}, "outputs": [ { "html": [ "
\n", "\n" ], "metadata": {}, "output_type": "pyout", "prompt_number": 5, "text": [ "\"
\\n\\n\"" ] } ], "prompt_number": 5 }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Surface" ] }, { "cell_type": "code", "collapsed": false, "input": [ "plot = Nyaplot::Plot3D.new\n", "plot.add(:surface, x, y, z)\n", "plot.show" ], "language": "python", "metadata": {}, "outputs": [ { "html": [ "
\n", "\n" ], "metadata": {}, "output_type": "pyout", "prompt_number": 12, "text": [ "\"
\\n\\n\"" ] } ], "prompt_number": 12 }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Line" ] }, { "cell_type": "code", "collapsed": false, "input": [ "step_num = 10000;\n", "p = 10; r = 28; b = 8/3; dt = 0.01\n", "\n", "fx = Proc.new{|x,y,z| ((-1)*p*x + p*y)};\n", "fy = Proc.new{|x,y,z| ((-1)*x*z + r*x - y)};\n", "fz = Proc.new{|x,y,z| (x*y - b*z)};\n", "\n", "x_arr=[]; y_arr=[]; z_arr=[]\n", "x = 1; y = 1; z = 1\n", "step_num.times do |i|\n", " x += dt * fx.call(x,y,z);\n", " y += dt * fy.call(x,y,z);\n", " z += dt * fz.call(x,y,z);\n", " x_arr.push(x);\n", " y_arr.push(y);\n", " z_arr.push(z);\n", "end\n", "\n", "plot = Nyaplot::Plot3D.new\n", "plot.add(:line, x_arr, y_arr, z_arr)\n", "plot.show" ], "language": "python", "metadata": {}, "outputs": [ { "html": [ "
\n", "\n" ], "metadata": {}, "output_type": "pyout", "prompt_number": 13, "text": [ "\"
\\n\\n\"" ] } ], "prompt_number": 13 }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Scatter" ] }, { "cell_type": "code", "collapsed": false, "input": [ "plot = Nyaplot::Plot3D.new\n", "colors = ['#8dd3c7', '#ffffb3', '#bebada', '#fb8072']\n", "['circle', 'rect', 'rect', 'diamond'].each do |shape|\n", " x, y, z = [0,0,0].map{|d| next Array.new(20, rand*5).map{|v| next v+rand}}\n", " sc = plot.add(:scatter, x, y, z)\n", " sc.shape(shape)\n", " sc.fill_color(colors.pop)\n", "end\n", "plot.show" ], "language": "python", "metadata": {}, "outputs": [ { "html": [ "
\n", "\n" ], "metadata": {}, "output_type": "pyout", "prompt_number": 2, "text": [ "\"
\\n\\n\"" ] } ], "prompt_number": 2 }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Particles" ] }, { "cell_type": "code", "collapsed": false, "input": [ "plot = Nyaplot::Plot3D.new\n", "['#ff7f00','#1f78b4','#a6cee3'].each_with_index do |color, index|\n", " x=[];y=[];z=[];dz = 5*rand\n", " 0.step(1, 0.2) do |i|\n", " 0.step(1, 0.2) do |j|\n", " x.push(i+rand)\n", " y.push(j+rand)\n", " z.push(Math.sin(i)*Math.sin(j)+dz+rand)\n", " end\n", " end\n", " p = plot.add(:particles, x, y, z)\n", " p.color(color)\n", " p.name('molecules')\n", "end\n", "plot.show" ], "language": "python", "metadata": {}, "outputs": [ { "html": [ "
\n", "\n" ], "metadata": {}, "output_type": "pyout", "prompt_number": 15, "text": [ "\"
\\n\\n\"" ] } ], "prompt_number": 15 } ], "metadata": {} } ] }