Ruby: Building a Plot of Function

Ruby: building a plot of function

Is gnuplot a possible 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
}
}
}

How can I create a time-series bar graph in Ruby on Rails with a hash?

I have used highcharts. It is a javascript library but it's really easy to use. Use ruby to get your statistics and then display them with this library.

It does not matter if the data is in a hash or an array. It depends what kinda graph you want. Looking at your data you could just create a line graph. the x-axis would be the time and the y-axis would be the amount.

Then you can just loop over the hash and for each value have the key as the y-value and the value as the x-value.

You will have to create a different hash for each type of data you wanted to store.

Scientific plot with Ruby + wxWidgets

http://ruby-toolbox.com/categories/graphing.html might help you

How to create a histogram from a flat Array in Ruby

Use "histogram".

data = [0,1,2,2,2,2,2,3,3,3,3,3,3,4,4,4,4,5,5,6,6,6,7,7,7,7,7,8,9,9,10]
(bins, freqs) = data.histogram

This will create an array bins containing the bins of histogram and the array freqs containing the frequencies.
The gem also supports different binning behaviors and weights/fractions.

Hope this helps.

Customize tooltip in FLOT graph

I'm not using the flot tooltip. There is easier way to show tooltip and customize it. Check out this fiddler:

http://jsfiddle.net/Margo/yKG7X/5/

$("#placeholder").bind("plothover", function (event, pos, item) {
if (item) {

$("#tooltip").remove();

                var x = item.datapoint[0],
y = item.datapoint[1];
showTooltip(item.pageX, item.pageY, x + " / " + y );
}
});
function showTooltip(x, y, contents) {
$('<div id="tooltip">' + contents + '</div>').css({
position: 'absolute',
display: 'none',
top: y + 5,
left: x + 5,
border: '1px solid #fdd',
padding: '2px',
'background-color': '#fee',
opacity: 0.80
}).appendTo("body").fadeIn(200).fadeOut(6000);
}

Hope it helps :)



Related Topics



Leave a reply



Submit