Skip to content

Commit

Permalink
filledcurves with above/below threshold and fillcolor implemented.
Browse files Browse the repository at this point in the history
example added
  • Loading branch information
vikasnkumar authored and mohawk2 committed Nov 21, 2024
1 parent 364ca46 commit a246661
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 3 deletions.
9 changes: 8 additions & 1 deletion examples/demo.pl
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ sub prompt {

$w=gpwin(x11);


$w->plot($x**2);
prompt("A simple parabola");

Expand Down Expand Up @@ -85,6 +84,14 @@ sub prompt {
$x, $x/2, (10-abs($x))/2);
prompt("Variable pointsize");

## filled curve
$w->plot(
{ with => 'filledcurves', fc => 'red', below => 'y=0' },
-$x, (-$x)**3,
{ with => 'filledcurves', fillcolor => 'green', above => 'y=0' },
$x, ($x)**3
);
prompt("Area curve with filled colors");

################################
# some 3d stuff
Expand Down
39 changes: 37 additions & 2 deletions lib/PDL/Graphics/Gnuplot.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1709,6 +1709,31 @@ C<linespoints>).
Selects a fractional size for point glyphs, relative to the default size
on your terminal, for plots that render points as small glyphs.
=item fillcolor (abbrev 'fc')
Fills an area plot like C<filledcurves> with a color.
It has the same format as C<linecolor>. This will fill the whole plot with
the same color. To fill above a threshold or below a threshold, you need to
use C<above> and C<below> options.
An example to plot data in a single function call is below:
plot({ with => 'filledcurves', fillcolor => 'green', above => 'y=0' },
x, y,
{ with => 'filledcurves', fillcolor => 'red', below => 'y=0' },
x, y);
=item below
This is used for C<filledcurves> to set a C<fillcolor> below a threshold.
You can set the value like "y=0" if you want to color below the Y-axis value of 0.
=item above
This is used for C<filledcurves> to set a C<fillcolor> above a threshold.
You can set the value like "y=0" if you want to color above the Y-axis value of 0.
=item fillstyle (abbrev 'fs')
Specify the way that filled regions should be colored, in plots that
Expand Down Expand Up @@ -3479,7 +3504,7 @@ EOF
# The search over @$with will disappear with the deprecated compound-with form;
# the real one is the second line that scans through curve options.
my $ExtraColumns = grep /(palette|variable)/, @$with;
for my $k (qw/linecolor textcolor fillstyle pointsize linewidth/ ) {
for my $k (qw/linecolor textcolor fillstyle pointsize linewidth fillcolor/ ) {
my $v = $chunk{options}{$k};
next unless defined($v);
my $s = ref $v eq 'ARRAY' ? join(" ",@$v) : $v;
Expand Down Expand Up @@ -5234,6 +5259,15 @@ our $cOptionsTable = {
'linewidth'=> ['s', 'css', undef, 12],
'linecolor'=> ['l', 'ccolor', undef, 13],
'textcolor'=> ['l', 'ccolor', undef, 14],
'below' => [ 'l', sub {
return "$_[0] $_[1][0]" if (defined $_[1] and defined $_[1][0]);
return "";
}, undef, 9.2],
'above' => [ 'l', sub {
return "$_[0] $_[1][0]" if (defined $_[1] and defined $_[1][0]);
return "";
}, undef, 9.3],
'fillcolor'=> ['l', 'ccolor', ['above', 'below'], 14.5],
'pointtype'=> ['s', 'cs', undef, 15],
'pointsize'=> ['s', 'css', undef, 16],
'fillstyle'=> ['l', 'cl', undef, 17],
Expand Down Expand Up @@ -5266,7 +5300,8 @@ our $cOptionsAbbrevs = _gen_abbrev_list(keys %$cOptionsTable);
lc => ["linecolor"],
pt => ["pointtype"],
ps => ["pointsize"],
fs => ["fillstyle"]
fs => ["fillstyle"],
fc => ["fillcolor"],
};
for my $k(%$officialAbbrevs){
$cOptionsAbbrevs->{$k} = $officialAbbrevs->{$k};
Expand Down

0 comments on commit a246661

Please sign in to comment.