2

I'm hoping someone can help me figure out what is either wrong or possible when plotting a chart using Chart::Gnuplot module and 'dots' in Perl.

Here is what I have for my dataset:

    # RFE Chart object
   my $chart_RFE = Chart::Gnuplot->new(
       output => $out_file_RFE,
       terminal => "png",
       title => {
         text => "Step ROCOF",
         font => "arial, 12",
         },
       xlabel => $chart_xlabel, 
       ylabel => "ROCOF Error (Hz/s)",
       legend => {
         position => "outside top",
         align => "left",
       },
   );

   # RFE Dataset
   $dataSet = Chart::Gnuplot::DataSet->new(
      xdata => \@dataX,
      ydata => \@dataY,
      style => 'dots',
      color => $COLORS[3],
      title=> 'RFE',
   );

I want the dots because I have lot of data points to graph. However, the legend of the graph it produces shows no dots next to the legend names. If I change style to 'points'

style => 'points',

the different points show up in the graph's legend. Is there a way to get the dots to show? I've zoomed in on the legend area wondering if maybe they were just small but nothing shows up. I've also tried setting the width => option but that doesn't do anything (as I suspect it wouldn't since it's for lines).

Anyone know if this is even possible?

TWhite
  • 737
  • 2
  • 11
  • 33

1 Answers1

2

There's no option to change the point size in the legend (or "key," as Gnuplot calls it) so you have to use a hack to achieve the desired effect.

First, plot your dataset using the dots style, but don't assign it a title; then plot a dummy dataset using a different style and assign a title:

use strict;
use warnings;

use Chart::Gnuplot;

my @x = map { rand } 0 .. 10_000;
my @y = map { $_ + 0.1 - rand 0.2 } @x;

my $chart = Chart::Gnuplot->new(
    output  => 'gnuplot.png',
    legend  => {
        position => 'outside top',
        align    => 'left'
    }
);

my $color = '#ff0000';

my $dataset = Chart::Gnuplot::DataSet->new(
    xdata => \@x,
    ydata => \@y,
    style => 'dots',
    color => $color
);

my $dummy = Chart::Gnuplot::DataSet->new(
    ydata     => [ 'inf' ],
    style     => 'points',
    pointtype => 'fill-circle',
    pointsize => 1,
    title     => 'foo',
    color     => $color
);

$chart->plot2d($dataset, $dummy);

Output:

Scatter plot with readable legend

Note that this has been asked elsewhere for the command line version of Gnuplot, but it's actually pretty difficult to create a dummy dataset that plots nothing with Chart::Gnuplot. Using a y-value of "inf" was the only thing I could get to work that didn't require knowing the range of your axes.

Community
  • 1
  • 1
ThisSuitIsBlackNot
  • 23,492
  • 9
  • 63
  • 110
  • This worked as you explained. I do have another question on your fill-circle point. What are you doing to make it a circle? My png's are coming out as boxes with two small lines coming out the top and bottom. I cannot actually seem to graph a circle point, only boxes with lines. – TWhite May 26 '15 at 16:32
  • @TWhite That's controlled by `pointtype => 'fill-circle'` in the parameters for the dummy dataset (`pointtype => 7` should do the same thing). Anything in [this list of recognized point types](https://github.com/gitpan/Chart-Gnuplot/blob/master/doc/pointtypes.txt) should work, although I suppose it's possible that the particular driver you're using doesn't support all of them. Check the output of the `test` command as described in [this post](http://stackoverflow.com/questions/16736861/pointtype-command-for-gnuplot) to make sure. – ThisSuitIsBlackNot May 26 '15 at 16:45
  • I have been setting the type as you have said. I must not support circles. I can draw the triangles, squares, astric stars, etc. just not circles. Circles come out as squares with lines. *Sigh* Thanks for the help. – TWhite May 26 '15 at 17:03