2
votes

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?

1
The dots do appear in the legend, they're just minuscule.ThisSuitIsBlackNot
You could plot with the points style, pointtype 7 and a small point size. The point in the key isn't affected by the small point size.Christoph

1 Answers

2
votes

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.