Skip to content

Commit 05b476e

Browse files
vikasnkumarmohawk2
authored andcommitted
filledcurves with above/below threshold and fillcolor implemented.
example added
1 parent 364ca46 commit 05b476e

File tree

2 files changed

+45
-3
lines changed

2 files changed

+45
-3
lines changed

examples/demo.pl

+8-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ sub prompt {
3737

3838
$w=gpwin(x11);
3939

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

@@ -85,6 +84,14 @@ sub prompt {
8584
$x, $x/2, (10-abs($x))/2);
8685
prompt("Variable pointsize");
8786

87+
## filled curve
88+
$w->plot(
89+
{ with => 'filledcurves', fc => 'red', below => 'y=0' },
90+
-$x, (-$x)**3,
91+
{ with => 'filledcurves', fillcolor => 'green', above => 'y=0' },
92+
$x, ($x)**3
93+
);
94+
prompt("Area curve with filled colors");
8895

8996
################################
9097
# some 3d stuff

lib/PDL/Graphics/Gnuplot.pm

+37-2
Original file line numberDiff line numberDiff line change
@@ -1709,6 +1709,31 @@ C<linespoints>).
17091709
Selects a fractional size for point glyphs, relative to the default size
17101710
on your terminal, for plots that render points as small glyphs.
17111711
1712+
=item fillcolor (abbrev 'fc')
1713+
1714+
Fills an area plot like C<filledcurves> with a color.
1715+
It has the same format as C<linecolor>. This will fill the whole plot with
1716+
the same color. To fill above a threshold or below a threshold, you need to
1717+
use C<above> and C<below> options.
1718+
1719+
An example to plot data in a single function call is below:
1720+
1721+
plot({ with => 'filledcurves', fillcolor => 'green', above => 'y=0' },
1722+
x, y,
1723+
{ with => 'filledcurves', fillcolor => 'red', below => 'y=0' },
1724+
x, y);
1725+
1726+
1727+
=item below
1728+
1729+
This is used for C<filledcurves> to set a C<fillcolor> below a threshold.
1730+
You can set the value like "y=0" if you want to color below the Y-axis value of 0.
1731+
1732+
=item above
1733+
1734+
This is used for C<filledcurves> to set a C<fillcolor> above a threshold.
1735+
You can set the value like "y=0" if you want to color above the Y-axis value of 0.
1736+
17121737
=item fillstyle (abbrev 'fs')
17131738
17141739
Specify the way that filled regions should be colored, in plots that
@@ -3479,7 +3504,7 @@ EOF
34793504
# The search over @$with will disappear with the deprecated compound-with form;
34803505
# the real one is the second line that scans through curve options.
34813506
my $ExtraColumns = grep /(palette|variable)/, @$with;
3482-
for my $k (qw/linecolor textcolor fillstyle pointsize linewidth/ ) {
3507+
for my $k (qw/linecolor textcolor fillstyle pointsize linewidth fillcolor/ ) {
34833508
my $v = $chunk{options}{$k};
34843509
next unless defined($v);
34853510
my $s = ref $v eq 'ARRAY' ? join(" ",@$v) : $v;
@@ -5234,6 +5259,15 @@ our $cOptionsTable = {
52345259
'linewidth'=> ['s', 'css', undef, 12],
52355260
'linecolor'=> ['l', 'ccolor', undef, 13],
52365261
'textcolor'=> ['l', 'ccolor', undef, 14],
5262+
'below' => [ 'l', sub {
5263+
return "$_[0] $_[1][0]" if (defined $_[1] and defined $_[1][0]);
5264+
return "";
5265+
}, undef, 9.2],
5266+
'above' => [ 'l', sub {
5267+
return "$_[0] $_[1][0]" if (defined $_[1] and defined $_[1][0]);
5268+
return "";
5269+
}, undef, 9.3],
5270+
'fillcolor'=> ['l', 'ccolor', ['above', 'below'], 14.5],
52375271
'pointtype'=> ['s', 'cs', undef, 15],
52385272
'pointsize'=> ['s', 'css', undef, 16],
52395273
'fillstyle'=> ['l', 'cl', undef, 17],
@@ -5266,7 +5300,8 @@ our $cOptionsAbbrevs = _gen_abbrev_list(keys %$cOptionsTable);
52665300
lc => ["linecolor"],
52675301
pt => ["pointtype"],
52685302
ps => ["pointsize"],
5269-
fs => ["fillstyle"]
5303+
fs => ["fillstyle"],
5304+
fc => ["fillcolor"],
52705305
};
52715306
for my $k(%$officialAbbrevs){
52725307
$cOptionsAbbrevs->{$k} = $officialAbbrevs->{$k};

0 commit comments

Comments
 (0)