2009-10-13 13 views

Antwort

7

Ist gnuplot eine mögliche Option ?:

require 'gnuplot.rb' 
Gnuplot.open { |gp| 
    Gnuplot::Plot.new(gp) { |plot| 
     plot.output "testgnu.pdf" 
     plot.terminal "pdf colour size 27cm,19cm" 

     plot.xrange "[-10:10]" 
     plot.title "Sin Wave Example" 
     plot.ylabel "x" 
     plot.xlabel "sin(x)" 

     plot.data << Gnuplot::DataSet.new("sin(x)") { |ds| 
      ds.with = "lines" 
      ds.linewidth = 4 
     } 
     plot.data << Gnuplot::DataSet.new("cos(x)") { |ds| 
      ds.with = "impulses" 
      ds.linewidth = 4 
     } 
    } 
} 
+0

Gnuplot ist sehr süß, aber irgendwie kann ich die Beispiele nicht ausführen. Habe gerade den Edelstein installiert. 1.8.6 unter Windows ausführen. Irgendwelche Ideen/benötigten Plugins? – gmile

+1

Sorry, wenn das nicht offensichtlich war, aber hast du gnuplot selbst installiert? Das Ruby Bit ist nur die Bindings, AFAIK –

+0

Als Antwort auf @Brent: hier ist die Seite zum Download gnuplot: http://www.gnuplot.info/download.html –

1

Das ist mein go-to ist die grafische Darstellung Bibliothek: SVG::Graph

+0

Dieser ist der einzige, der für mich arbeitete. Aber - kann ich ein kontinuierliches Funktionsdiagramm anstatt nur punktiert erzeugen? – gmile

0

Ich mag wirklich tioga. Es kann unglaublich hochwertige, veröffentlichungsreife Graphen in Latex produzieren.

+0

tioga ist nur für POSIX OS Familie :-( – gmile

+0

ah , hab das nach deinem windows update. – Peter

+0

Eigentlich arbeitet Tioga jetzt an Windows, obwohl wohl die Voraussetzungen für eine MikTeX-Installation schmerzhaft sind. –

0

Verwendung SVG::Graph::Line wie folgt aus:

require 'SVG/Graph/Line' 

    fields = %w(Jan Feb Mar); 
    data_sales_02 = [12, 45, 21] 
    data_sales_03 = [15, 30, 40] 

    graph = SVG::Graph::Line.new({ 
      :height => 500, 
      :width => 300, 
    :fields => fields, 
    }) 

    graph.add_data({ 
      :data => data_sales_02, 
    :title => 'Sales 2002', 
    }) 

    graph.add_data({ 
      :data => data_sales_03, 
    :title => 'Sales 2003', 
    }) 

    print "Content-type: image/svg+xml\r\n\r\n"; 
    print graph.burn();
4

Falls jemand stolpert über diese konnte ich den folgenden Code verwenden gnuplot mit:

require 'rubygems' 
require 'gnuplot' 

Gnuplot.open do |gp| 
    Gnuplot::Plot.new(gp) do |plot| 

    plot.xrange "[-10:10]" 
    plot.title "Sin Wave Example" 
    plot.ylabel "x" 
    plot.xlabel "sin(x)" 

    plot.data << Gnuplot::DataSet.new("sin(x)") do |ds| 
     ds.with = "lines" 
     ds.linewidth = 4 
    end 
    end 
end 

rubygems Erfordern und mit dem richtigen gem Namen für Gnuplot war der Schlüssel für mich.

Verwandte Themen