Search code examples
rubygnuplot

How can I set the line color when plotting with Ruby's GnuPlot (rgplot)?


The default line color is some sickly yellow and I want to change it to black.


Solution

  • Try something like this, assuming your data set variables (x, y, z) are already defined

    ::Gnuplot.open do |gp|
      ::Gnuplot::Plot.new(gp) do |plot|
        plot.data << ::Gnuplot::DataSet.new([x, y, z]) do |ds|
          ds.with = 'errorb lt rgb "black"'
        end
      end
    end
    

    The line specifying the colour is also specifying that you want to plot with error bars (for the z variable). It can also be formatted like:

    ds.with = "errorb lt rgb \"black\""
    

    And of course you can remove the 'errorb' and just plot a two-variable (x,y) dataset.

    Incidentally, to see which colours are available, type

    show colournames
    

    in your terminal inside a gnuplot environment. Try http://gnuplot.sourceforge.net/docs_4.6/gnuplot.pdf for more documentation.