|
| 1 | +# GnuplotRB |
| 2 | + |
| 3 | +GnuplotRB is a plot generator for Ruby based on |
| 4 | +[Gnuplot](http://www.gnuplot.info). |
| 5 | + |
| 6 | +This software has been developed as a product in Google Summer of Code 2015 |
| 7 | +(GSoC2015). Its progress may be saw in [SciRuby mailing |
| 8 | +list](https://groups.google.com/forum/?fromgroups#!topic/sciruby-dev/lhWvb5hWc |
| 9 | +3k) or in [project's blog](http://www.evgrafov.work/gnuplotrb/). |
| 10 | + |
| 11 | +[<img src="https://badge.fury.io/rb/gnuplotrb.svg" alt="Gem Version" |
| 12 | +/>](https://rubygems.org/gems/gnuplotrb) |
| 13 | + |
| 14 | +[<img src="https://gemnasium.com/dilcom/gnuplotrb.svg" alt="Dependency Status" |
| 15 | +/>](https://gemnasium.com/dilcom/gnuplotrb) |
| 16 | + |
| 17 | +[<img src="https://travis-ci.org/SciRuby/gnuplotrb.svg" alt="Build Status" |
| 18 | +/>](https://travis-ci.org/SciRuby/gnuplotrb) |
| 19 | + |
| 20 | +[<img src="https://codeclimate.com/github/sciruby/gnuplotrb/badges/gpa.svg" |
| 21 | +alt="Code quality" />](https://codeclimate.com/github/sciruby/gnuplotrb) |
| 22 | + |
| 23 | +[<img |
| 24 | +src="https://codeclimate.com/github/sciruby/gnuplotrb/badges/coverage.svg" |
| 25 | +alt="Test coverage" />](https://codeclimate.com/github/sciruby/gnuplotrb) |
| 26 | + |
| 27 | +## Table of contents |
| 28 | +* [Installation](https://github.com/sciruby/gnuplotrb#installation) |
| 29 | +* [Getting started](https://github.com/sciruby/gnuplotrb#getting-started) |
| 30 | + * [Plottable |
| 31 | + classes](https://github.com/sciruby/gnuplotrb#plottable-classes) |
| 32 | + * [Notebooks](https://github.com/sciruby/gnuplotrb#notebooks) |
| 33 | + * [Plain examples](https://github.com/sciruby/gnuplotrb#plain-examples) |
| 34 | + |
| 35 | +* [Contributing](https://github.com/sciruby/gnuplotrb#contributing) |
| 36 | + |
| 37 | + |
| 38 | +## Installation |
| 39 | +### Dependencies |
| 40 | +* Ruby 2.0+ |
| 41 | +* It is required to install [gnuplot |
| 42 | + 5.0](http://www.gnuplot.info/download.html) to use that gem. |
| 43 | + |
| 44 | +### Gem installation |
| 45 | +#### Install latest stable version from Rubygems |
| 46 | + gem install gnuplotrb |
| 47 | + |
| 48 | +#### Install latest stable version using bundler |
| 49 | +* add |
| 50 | + gem 'gnuplotrb' |
| 51 | + |
| 52 | + to your Gemfile |
| 53 | +* run |
| 54 | + bundle install |
| 55 | + |
| 56 | + |
| 57 | +#### Install latest version from source (may be unstable) |
| 58 | + git clone https://github.com/sciruby/gnuplotrb.git |
| 59 | + cd gnuplotrb |
| 60 | + bundle install |
| 61 | + rake install |
| 62 | + |
| 63 | +## Getting started |
| 64 | + |
| 65 | +GnuplotRB gem is based on [Gnuplot](http://www.gnuplot.info/) so I would |
| 66 | +recommend to use [Gnuplot doc](http://www.gnuplot.info/docs_5.0/gnuplot.pdf) |
| 67 | +and [GnuplotRB doc at Rubydoc](https://rubygems.org/gems/gnuplotrb) in cases |
| 68 | +when docs and examples (as notebooks and plain examples) present here are not |
| 69 | +enough to explain how to plot something. |
| 70 | + |
| 71 | +### Plottable classes |
| 72 | + |
| 73 | +Each of plottable classes may be outputted to image file using ```#to_png```, |
| 74 | +```#to_svg```, ```#to_gif``` and so on methods. You can read more about it in |
| 75 | +[GnuplotRB doc](https://rubygems.org/gems/gnuplotrb) related to Plottable |
| 76 | +module or see examples in [beginners |
| 77 | +notebook](http://nbviewer.ipython.org/github/sciruby/gnuplotrb/blob/master/not |
| 78 | +ebooks/basic_usage.ipynb). |
| 79 | + |
| 80 | +#### Dataset |
| 81 | +Single dataset may be created with math formula ('sin(x)') or some data. If |
| 82 | +your data is stored in a file you can just pass a filename (e.g. |
| 83 | +'gnuplotrb.data'). Dataset may also be constructed out of data contained in |
| 84 | +Ruby classes (Array, Daru containers), see [example |
| 85 | +notebooks](https://github.com/sciruby/gnuplotrb#possible-datasources). |
| 86 | + |
| 87 | +Dataset have several possible options which are explained in [gnuplot |
| 88 | +doc](http://www.gnuplot.info/docs_5.0/gnuplot.pdf) (pp. 80-102). Options are |
| 89 | +passed to Dataset.new as hash and are tranlated into gnuplot format before |
| 90 | +plotting: |
| 91 | + Dataset.new(data, with: 'lines', using: '1:2') |
| 92 | + |
| 93 | +Examples of option translation (nested containers allowed): |
| 94 | +* Hash: |
| 95 | + { key1: "value1", key2: { nested_key1: "nested_value1" } } |
| 96 | + # => |
| 97 | + "key1 value1 key2 nested key1 nested_value1" |
| 98 | + |
| 99 | +* Hashes with underscored keys (see |
| 100 | + [#7](https://github.com/dilcom/gnuplotrb/issues/7)): |
| 101 | + { style_data: 'histograms' } |
| 102 | + #=> |
| 103 | + "style data histograms" |
| 104 | + |
| 105 | +* Range: |
| 106 | + { xrange: 0..100 } |
| 107 | + # => |
| 108 | + "xrange [0:100]" |
| 109 | + |
| 110 | +* Array (often used with nested hashes) and Array of Numeric |
| 111 | + ['png', { size: [400, 500] }] |
| 112 | + # => |
| 113 | + "png size 400,500" |
| 114 | + |
| 115 | +* Others |
| 116 | + some_object |
| 117 | + # => |
| 118 | + some_object.to_s |
| 119 | + |
| 120 | + |
| 121 | +Once Dataset created, it may be updated with new data or options. Methods |
| 122 | +related to updating are explained in [a |
| 123 | +notebook](http://nbviewer.ipython.org/github/sciruby/gnuplotrb/blob/master/not |
| 124 | +ebooks/updating_data.ipynb). |
| 125 | + |
| 126 | +Just as other Plottable object Dataset has several plotting methods which are |
| 127 | +desribed in [beginners |
| 128 | +notebook](http://nbviewer.ipython.org/github/sciruby/gnuplotrb/blob/master/not |
| 129 | +ebooks/basic_usage.ipynb). |
| 130 | + |
| 131 | +#### Plot |
| 132 | +Plot is a container for several datasets and layout options: |
| 133 | + Plot.new(ds1, ds2, ds2, xrange: 1..10) |
| 134 | + |
| 135 | +Datasets contained bu Plot are outputted on single xy plain. |
| 136 | + |
| 137 | +Plot's options are explained in [gnuplot |
| 138 | +doc](http://www.gnuplot.info/docs_5.0/gnuplot.pdf) (pp. 105-181). Plot options |
| 139 | +are translated into gnuplot format the same way as Dataset's (except adding |
| 140 | +'set' before each option). Plot's datasets and Plot itself may be updated with |
| 141 | +almost the same methods as desribed in Dataset section above. |
| 142 | + |
| 143 | +#### Splot |
| 144 | +Almost the same as Plot but for 3-D plots. See Plot section. |
| 145 | + |
| 146 | +#### Multiplot |
| 147 | + |
| 148 | +Container for several Plot or Splot objects, each of them is plotted in its |
| 149 | +own xy(z) space. So Multiplot offers single layout (image filewindow) for |
| 150 | +several plots. It's grid is tuned by :layout option, and you can also set |
| 151 | +layout's title: |
| 152 | + Multiplot.new(plot1, plot2, splot1, layout: [3, 1], title: 'Three plots on a layout') |
| 153 | + |
| 154 | +Updating methods for Multiplot are almost the same as Plot's and Dataset's and |
| 155 | +are covered in Multiplot's docs and [multiplot |
| 156 | +notebook](http://nbviewer.ipython.org/github/sciruby/gnuplotrb/blob/master/not |
| 157 | +ebooks/multiplot_layout.ipynb). See examples there. |
| 158 | + |
| 159 | +#### Animation |
| 160 | + |
| 161 | +Animation is a container for several Plot, Splot or Multiplot objects. Each of |
| 162 | +contained items is considered as frame in gif animation which is creating by |
| 163 | +```#plot``` call. Animation's frames and options may be modifyed or updated |
| 164 | +just as other classes above. Animation does not support methods like |
| 165 | +```#to_png``` and may be plotted only with ```#plot``` method. Please see |
| 166 | +[related |
| 167 | +notebook](http://nbviewer.ipython.org/github/sciruby/gnuplotrb/blob/master/not |
| 168 | +ebooks/animated_plots.ipynb) and docs at RubyDoc for examples. |
| 169 | + |
| 170 | +### Notebooks |
| 171 | + |
| 172 | +This notebooks are powered by [Ruby kernel](https://github.com/SciRuby/iruby/) |
| 173 | +for [IPython/Jupyter](https://jupyter.org/). I placed them here to show some |
| 174 | +GnuplotRB's capabilities and ways of using it together with iRuby. |
| 175 | + |
| 176 | +To use GnuplotRB gem with iRuby you need to install them both. |
| 177 | + |
| 178 | +* iRuby installation is covered in its |
| 179 | + [README](https://github.com/SciRuby/iruby/blob/master/README.md). It also |
| 180 | + covers installation of iPython and other dependecies. |
| 181 | +* GnuplotRB gem installation covered in |
| 182 | + [README](https://github.com/sciruby/gnuplotrb#installation) too. |
| 183 | + |
| 184 | + |
| 185 | +#### Embedding plots into iRuby |
| 186 | +Using GnuplotRB inside iRuby notebooks is covered in: |
| 187 | + |
| 188 | +* [Basic usage |
| 189 | + notebook](http://nbviewer.ipython.org/github/sciruby/gnuplotrb/blob/master |
| 190 | + /notebooks/basic_usage.ipynb). |
| 191 | + |
| 192 | + |
| 193 | +#### 2D and 3D plots |
| 194 | +GnuplotRB is capable to plot vast range of plots from histograms to 3D |
| 195 | +heatmaps. Gem's repository contains examples of several plot types: |
| 196 | + |
| 197 | +* [Heatmaps](http://nbviewer.ipython.org/github/sciruby/gnuplotrb/blob/maste |
| 198 | + r/notebooks/heatmaps.ipynb) |
| 199 | +* [Vector |
| 200 | + field](http://nbviewer.ipython.org/github/sciruby/gnuplotrb/blob/master/no |
| 201 | + tebooks/vector_field.ipynb) (Thanks, [Alexej](https://github.com/agisga)) |
| 202 | +* [Math |
| 203 | + equations](http://nbviewer.ipython.org/github/sciruby/gnuplotrb/blob/maste |
| 204 | + r/notebooks/math_plots.ipynb) |
| 205 | +* [3D |
| 206 | + visualizations](http://nbviewer.ipython.org/github/sciruby/gnuplotrb/blob/ |
| 207 | + master/notebooks/3d_plot.ipynb) |
| 208 | +* [Histogram](http://nbviewer.ipython.org/github/sciruby/gnuplotrb/blob/mast |
| 209 | + er/notebooks/histogram.ipynb) |
| 210 | + |
| 211 | + |
| 212 | +#### Possible datasources |
| 213 | +GnuplotRB may take data in Ruby container or in a file. Supported containers |
| 214 | +for now are Arrays, Daru::Vector and Daru::DataFrame. When data given in file, |
| 215 | +GnuplotRB pass filename to Gnuplot **without** reading the file into memory. |
| 216 | + |
| 217 | +Examples of using different datasources: |
| 218 | + |
| 219 | +* [Data given in file or Ruby |
| 220 | + Array](http://nbviewer.ipython.org/github/sciruby/gnuplotrb/blob/master/no |
| 221 | + tebooks/points_from_different_sources.ipynb) |
| 222 | +* [Data given in Daru |
| 223 | + containers](http://nbviewer.ipython.org/github/sciruby/gnuplotrb/blob/mast |
| 224 | + er/notebooks/plotting_from_daru.ipynb) |
| 225 | +* [Data given in Daru containers (with |
| 226 | + timeseries)](http://nbviewer.ipython.org/github/sciruby/gnuplotrb/blob/mas |
| 227 | + ter/notebooks/time_series_from_daru.ipynb) |
| 228 | +* [Updating plots with new |
| 229 | + data](http://nbviewer.ipython.org/github/sciruby/gnuplotrb/blob/master/not |
| 230 | + ebooks/updating_data.ipynb) |
| 231 | + |
| 232 | + |
| 233 | +#### Multiplot |
| 234 | +You can not only plot several datasets in single coordinate system but place |
| 235 | +several coordinate systems on a canvas. |
| 236 | + |
| 237 | +* [Multiplot example |
| 238 | + notebook](http://nbviewer.ipython.org/github/sciruby/gnuplotrb/blob/master |
| 239 | + /notebooks/multiplot_layout.ipynb). |
| 240 | + |
| 241 | + |
| 242 | +#### Animation |
| 243 | +It's possible to use several plots (Plot, Splot or Multiplot objects) to |
| 244 | +create gif animation. |
| 245 | + |
| 246 | +* [Animation example |
| 247 | + notebook](http://nbviewer.ipython.org/github/sciruby/gnuplotrb/blob/master |
| 248 | + /notebooks/animated_plots.ipynb). |
| 249 | + |
| 250 | + |
| 251 | +#### Fitting data with formula |
| 252 | +GnuplotRB also may be used to fit some data with given math formula. |
| 253 | + |
| 254 | +* [Fitting |
| 255 | + data](http://nbviewer.ipython.org/github/sciruby/gnuplotrb/blob/master/not |
| 256 | + ebooks/fitting_data.ipynb) |
| 257 | + |
| 258 | + |
| 259 | +### Plain examples |
| 260 | +You may find several examples in [examples |
| 261 | +directory](https://github.com/sciruby/gnuplotrb/tree/master/examples). |
| 262 | + |
| 263 | +## Contributing |
| 264 | + |
| 265 | +1. [Fork repository](https://github.com/sciruby/gnuplotrb/fork) |
| 266 | +2. Create your feature branch (`git checkout -b my-new-feature`) |
| 267 | +3. Commit your changes (`git commit -am 'Add some feature'`) |
| 268 | +4. Push to the branch (`git push origin my-new-feature`) |
| 269 | +5. Create a new Pull Request |
| 270 | + |
0 commit comments