ruby-numo / numo-gnuplot Goto Github PK
View Code? Open in Web Editor NEWGnuplot wrapper for Ruby/Numo
License: BSD 3-Clause "New" or "Revised" License
Gnuplot wrapper for Ruby/Numo
License: BSD 3-Clause "New" or "Revised" License
.gem/ruby/2.7.0/gems/numo-gnuplot-0.2.4/lib/numo/gnuplot.rb:307:in `run': (Numo::GnuplotError)
line 0: Gridding of the color column is not implemented
2d example
how produce 2d image from array[][]
x = 3
y = 4
tab = Array.new(x) { Array.new(y,(rand(5)+1).to_s)}
いつもnumo-gnuplotで大変お世話になっております。日本語で失礼します。
numo-gnuplotで時系列の折れ線グラフを書きたいのですがうまく描けません。
require 'numo/gnuplot'
x = ['2017-01-01', '2017-01-02']
y = [1, 2]
Numo.gnuplot do
set xdata: 'time'
set timefmt: '%Y-%m-%d'
plot x, y, u: [1, 2], w: :lines
end
# line 3: warning: Skipping data file with no valid points
#
# gnuplot> plot '-' u 1:2 w lines
# ^
# line 3: x range is invalid
Gemファイルの_plot_splotメソッド
# gnuplot.rb 90行〜96行
def _plot_splot(cmd,contents)
r = contents.shift.map{|x| "#{x} "}.join
c = contents.map{|x| x.cmd_str}.join(", ")
d = contents.map{|x| x.data_str}.join
p d
run "#{cmd} #{r}#{c}", d
nil
end
のなかで p d すると
# "\"2017-01-01\" 1\n\"2017-01-02\" 2\ne"
となり、e回避の?ダブルクオテーションが邪魔をしているように思われます。
うまく回避する方法はありませんか?
Ubuntu 4.4.0 ruby 2.4.1 gnuplot 5.0.6
お忙しいところ申し訳ございません. 大変暑い日が続いていますが日本語で失礼します.
棒グラフを表示したいのですが、下記のように書くと
require 'numo/gnuplot'
a = Array.new(10) { |i| i }
b = Array.new(10) { |i| 2 * i }
c = Array.new(10) { |i| 3 * i }
d = Array.new(10) { |i| 4 * i }
data = [a, b, c, d]
Numo.gnuplot do
debug_on
set style: [histogram: :clustered]
set style: [fill: :solid]
plot [*data, using: 1, w: :histogram, t: 'A'],
[*data, using: 2, w: :histogram, t: 'B'],
[*data, using: 3, w: :histogram, t: 'C'],
[*data, using: 4, w: :histogram, t: 'D']
end
アウトプットはこんな感じでした
set style histogram clustered set style fill solid set term png set output "output.png" plot '-' using 1 w histogram t "A", '-' using 2 w histogram t "B", '-' using 3 w histogram t "C", '-' using 4 w histogram t "D" 0 0 0 0 1 2 3 4 ... 9 18 27 36 e
'B' 'C' 'D' の一番最後が表示されていません。、きちんと表示するにはどうすればよいでしょうか?
これはnumo-gnuplotの問題ではない気もしますが念のため報告します。
I want to write a dashed vertical line on the plot, then
Numo.gnuplot do
set arrow: "from 10.0 ,0.0 to 10.0,140.0 nohead dashtype (10, 5)", lc_rgb:"red"
plot xx, yy, w: :l
end
But I only got a plain red line. How do I set the dashtype appropriately from numo/gnuplot?
I do not know whether Numo should support Sciruby classes such as Daru::Vector, Daru::DataFrame.
But I'm glad if Numo-gnuplot plot supports Daru::Vector.
df = Daru::DataFrame.from_csv "hoge.csv"
N.noteplot do
plot df.x, df.y
# I do not want to convert it to RubyArray
# plot df.x.to_a, df.y.to_a
end
$ gem install numo-gnuplot
よりインストールしたのですが、NotePlotが無いと怒られました。
実際git cloneしたものとgnuplot.rbを比較すると
12,16d11
< def noteplot(&block)
< Gnuplot::NotePlot.new(&block)
< end
< module_function :noteplot
<
29,51d23
< class NotePlot
< def initialize(&block)
< if block.nil?
< raise ArgumentError,"block is needed"
< end
< @block = block
< end
<
< def to_iruby
< require 'tempfile'
< tempfile_svg = Tempfile.open('plot')
< # output SVG to tmpfile
< gp = Gnuplot.default
< gp.reset
< gp.set terminal:'svg', output:tempfile_svg.path
< gp.instance_eval(&@block)
< gp.unset 'output'
< svg = File.read(tempfile_svg.path)
< tempfile_svg.close
< ["image/svg+xml",svg]
< end
< end
<
585c557
< else
---
> elsif / / =~ s
のようになりました。 gnuplot.rbを置き換えただけで正常に動作したので大して困ってませんが、gemの方の更新が遅れているのでしょうか。
一応報告申し上げておきます。
環境は
Xubuntu 16.04
ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-linux]
rbenv 1.0.0-21-g9fdce5d
gem 2.5.1
です
Hello there Masahiro Tanaka,
This is not an "issue request" but a "thank you" note.
I have been needing a ruby-wrapper towards gnuplot for a longer while. I just discovered your gem here and I am currently exploring it. You added quite many examples already so I hope I can learn from them, especially with a pretty ruby-like API.
It works fine so far:
http://shevegen.square7.ch/GNUPLOT_AND_RUBY.png
I hope to eventually use the ruby wrapper in order to auto-generate some GNUPLOT datasets, in particular for some statistical dataset.
Feel free to close the issue here, I just wanted to write a comment of appreciation - hopefully you can add even more examples in the future over the next years; examples help me a lot.
Thanks.
If you try to display a scatter plot of data that contains a large number of samples, the browser may freeze.
Numo.noteplot
plot SomeBigData
end
In this case, he PNG format may be more appropriate than the SVG format.
Of course, the SVG format is good for displaying small sized data.
So there is no best format for every situation.
One solution is to be able to specify the format.
Numo.noteplot
set :term, :png
plot SomeBigData
end
Numo.noteplot(format: :png)
plot SomeBigData
end
Numo::Noteplot.set_format :png
etc...
But I do not know if this is really good.
The gem on rubygems is outdated.
Please update it.
Guys when I tried to run a script:
require 'numo/gnuplot'
require 'numo/narray'
n = 60
x = (Numo::DFloat.new(1,n).seq/n-0.5)*30
y = (Numo::DFloat.new(n,1).seq/n-0.5)*30
r = Numo::NMath.sqrt(x**2+y**2) + 1e-10
z = Numo::NMath.sin(r)/r
Numo.gnuplot do
set title:'2D data plot'
set dgrid3d:[60,60]
splot z, w:'pm3d', t:'sin(r)/r'
end
This error occurred:
/usr/local/bundle/gems/numo-gnuplot-0.1.1/lib/numo/gnuplot.rb:244:in `write': Broken pipe (Errno::EPIPE)
from /usr/local/bundle/gems/numo-gnuplot-0.1.1/lib/numo/gnuplot.rb:244:in `puts'
from /usr/local/bundle/gems/numo-gnuplot-0.1.1/lib/numo/gnuplot.rb:244:in `send_cmd'
from /usr/local/bundle/gems/numo-gnuplot-0.1.1/lib/numo/gnuplot.rb:229:in `run'
from /usr/local/bundle/gems/numo-gnuplot-0.1.1/lib/numo/gnuplot.rb:80:in `block (2 levels) in _set_unset'
from /usr/local/bundle/gems/numo-gnuplot-0.1.1/lib/numo/gnuplot.rb:79:in `each'
from /usr/local/bundle/gems/numo-gnuplot-0.1.1/lib/numo/gnuplot.rb:79:in `block in _set_unset'
from /usr/local/bundle/gems/numo-gnuplot-0.1.1/lib/numo/gnuplot.rb:76:in `each'
from /usr/local/bundle/gems/numo-gnuplot-0.1.1/lib/numo/gnuplot.rb:76:in `_set_unset'
from /usr/local/bundle/gems/numo-gnuplot-0.1.1/lib/numo/gnuplot.rb:65:in `set'
from plot.rb:11:in `block in <main>'
from /usr/local/bundle/gems/numo-gnuplot-0.1.1/lib/numo/gnuplot.rb:5:in `instance_eval'
from /usr/local/bundle/gems/numo-gnuplot-0.1.1/lib/numo/gnuplot.rb:5:in `gnuplot'
from plot.rb:10:in `<main>'
What's happening?
Thanks for maintaining great gem.👍
Unfortunately on my new mac m1(BigSur), numo-gnuplot doesn' t work.
The error tells,
Traceback (most recent call last):
3: from test.rb:5:in `<main>'
2: from /Users/bob/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/numo-gnuplot-0.2.4/lib/numo/gnuplot.rb:79:in `plot'
1: from /Users/bob/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/numo-gnuplot-0.2.4/lib/numo/gnuplot.rb:94:in `_plot_splot'
/Users/bob/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/numo-gnuplot-0.2.4/lib/numo/gnuplot.rb:307:in `run': (Numo::GnuplotError)
qt.qpa.fonts: Populating font family aliases took 408 ms. Replace uses of missing font family "Monospace 12" with one that exists to avoid this cost.
The code is
require "numo/gnuplot"
gp = Numo::Gnuplot.new
gp.set title:"Example Plot"
gp.plot "sin(x)",w:"lines"
and the gnuplot is
G N U P L O T
Version 5.4 patchlevel 1 last modified 2020-12-01
Copyright (C) 1986-1993, 1998, 2004, 2007-2020
Thomas Williams, Colin Kelley and many others
gnuplot home: http://www.gnuplot.info
faq, bugs, etc: type "help FAQ"
immediate help: type "help" (plot window: hit 'h')
Terminal type is now 'qt'
I've search around the error related issues, but can't fix them.
require "numo/gnuplot"
=> true
irb(main):006:0> Numo.gnuplot do
irb(main):007:1* set title:"Example Plot"
irb(main):008:1> plot "sin(x)",w:"lines"
irb(main):009:1> end
Errno::ENOENT: No such file or directory - gnuplot
from /home/user/.gem/ruby/gems/numo-gnuplot-0.2.4/lib/numo/gnuplot.rb:59:in `popen'
....
With this code
Numo.gnuplot do
debug_on
set :title, 'Letzte Stunde'
set :term, 'pngcairo' # size 1024,576' # 16:9
set :output, 'hourly.png'
set :xdata, 'time'
set :timefmt, TFMT
pp [x[0], y1[0]]
pp [x[1], y1[1]]
pp [x[2], y1[2]]
plot x, y1
end
I'm getting this output
<set title "Letzte Stunde"
<set term pngcairo
<set output "hourly.png"
<set xdata time
<set timefmt '%F %T'
["2020-10-31 18:00:25", 0.3148651123046875]
["2020-10-31 18:00:26", 0.310211181640625]
["2020-10-31 18:00:27", 0.28819020589192706]
<plot '-'
<"2020-10-31 18:00:25"
<"2020-10-31 18:00:26"
<...
<2.654648
<e
and then running it a second time, the last two lines change to
<3.702583
<e
and I'm having trouble using that info to get to the bottom of why gnuplot hangs indefinitely. Is there a way that instead of the three dots I could make numo-gnuplot show what would actually have been there?
Tanaka-san,
I have a question regarding the usage of set command. What is the proper way to use "set format"? I got the error in the code below with the debug mode enabled.
Numo.gnuplot do
...
set format: {x: "%Y-%m-%d"}
...
end
>gnuplot> set
> ^
> line 0: unrecognized option - see 'help set'.
It seems to be OK with the code below.
...
set datafile: {separator: "','"}
set xtics: "rotate by -45"
...
I found the keyword "format_x" in the library. It is, however, not the valid command for gnuplot so I got another error like this.
>gnuplot> set format_x "%Y-%m-%d"
> ^
> line 0: unrecognized option - see 'help set'.
I'd appreciate it if you have any advice.
Thanks.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.