kdensity plot not filled with filledcurves y=0

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

kdensity plot not filled with filledcurves y=0

Grothausmann, Roman Dr.
Dear mailing list members,


When plotting data with kernel-densities with filled-curves I can't find a way
to make the filling reach down to y=0 (using gnuplot-5.0.3). This is especially
visible if the x-range "crops" the kdensity plot before it gets close to y=0.
However plotting x**2-2 has no problems to "pull down" the filling to any y=a.
For example the script below does not fill the plot. When removing "=0" it gets
filled but for a kdensity plot looks odd as the filling does not go down to y=0.
Even with any other y=a for a>0 there is no filling, e.g. y=0.01:

if (GPVAL_VERSION < 5.0) {print "This script needs gnuplot-5.x\n"; exit;}

bin=17
sigma=3
col=1

set samples 1000
set boxwidth bin
bin (x,s)= s* int(x/s)

STATS_records=7
plot [0:180][-0.01:0.1] "-" u col:(1. / STATS_records) smooth kdensity bandwidth
sigma with filledcurves y=0
10
11
30
35
180
180
180
e


Any help or hints are very much appreciated
Roman

------------------------------------------------------------------------------
Attend Shape: An AT&T Tech Expo July 15-16. Meet us at AT&T Park in San
Francisco, CA to explore cutting-edge tech and listen to tech luminaries
present their vision of the future. This family event has something for
everyone, including kids. Get more information and register today.
http://sdm.link/attshape
_______________________________________________
gnuplot-info mailing list
[hidden email]
Membership management via: https://lists.sourceforge.net/lists/listinfo/gnuplot-info
Reply | Threaded
Open this post in threaded view
|

Re: kdensity plot not filled with filledcurves y=0

Ethan A Merritt-2
On Friday, July 01, 2016 10:21:29 AM Grothausmann, Roman Dr. wrote:

> Dear mailing list members,
>
>
> When plotting data with kernel-densities with filled-curves I can't find a
> way to make the filling reach down to y=0 (using gnuplot-5.0.3). This is
> especially visible if the x-range "crops" the kdensity plot before it gets
> close to y=0. However plotting x**2-2 has no problems to "pull down" the
> filling to any y=a. For example the script below does not fill the plot.
> When removing "=0" it gets filled but for a kdensity plot looks odd as the
> filling does not go down to y=0. Even with any other y=a for a>0 there is
> no filling, e.g. y=0.01:
>
> if (GPVAL_VERSION < 5.0) {print "This script needs gnuplot-5.x\n"; exit;}
>
> bin=17
> sigma=3
> col=1
>
> set samples 1000
> set boxwidth bin
> bin (x,s)= s* int(x/s)
>
> STATS_records=7
> plot [0:180][-0.01:0.1] "-" u col:(1. / STATS_records) smooth kdensity
> bandwidth sigma with filledcurves y=0
> 10
> 11
> 30
> 35
> 180
> 180
> 180
> e
>
>
> Any help or hints are very much appreciated
> Roman

I do not know why the filledcurves style is failing in conjunction with
smoothing, but a work-around is to plot  first to a datablock and then plot
the smoothed curve in a separate step:

set table $SMOOTHED
plot $original_data using col:(weight) smooth kdensity bandwidth sigma
unset table
plot $SMOOTHED using 1:2 with filledcurves y=0

    Ethan

------------------------------------------------------------------------------
Attend Shape: An AT&T Tech Expo July 15-16. Meet us at AT&T Park in San
Francisco, CA to explore cutting-edge tech and listen to tech luminaries
present their vision of the future. This family event has something for
everyone, including kids. Get more information and register today.
http://sdm.link/attshape
_______________________________________________
gnuplot-info mailing list
[hidden email]
Membership management via: https://lists.sourceforge.net/lists/listinfo/gnuplot-info
Reply | Threaded
Open this post in threaded view
|

Re: kdensity plot not filled with filledcurves y=0

Grothausmann, Roman Dr.
On 01/07/16 19:10, Ethan Merritt wrote:
> I do not know why the filledcurves style is failing in conjunction with
> smoothing, but a work-around is to plot  first to a datablock and then plot
> the smoothed curve in a separate step:
>
> set table $SMOOTHED
> plot $original_data using col:(weight) smooth kdensity bandwidth sigma
> unset table
> plot $SMOOTHED using 1:2 with filledcurves y=0

Many thanks Ethan for the quick reply and the work-around. I got it working
(https://github.com/romangrothausmann/gnuplot/blob/5f513bf1cf81c1709ff450e2830c8c59b76d2c80/hist-ar%2Bkd.gp)

but the resulting plot of the "filled table" is kind of "ragged" when saved to
SVG. See attached compressed SVG for the test data created with:
gnuplot -e "datafile='test.dat'; outfile='test.svg'; bin=10; sigma=3.5; xmin=0;
xmax=180; col=1; sep=','; xlabel='test'" hist-ar+kd.gp

Any idea how to avoid this raggedness?

> ------------------------------------------------------------------------------
> Attend Shape: An AT&T Tech Expo July 15-16. Meet us at AT&T Park in San
> Francisco, CA to explore cutting-edge tech and listen to tech luminaries
> present their vision of the future. This family event has something for
> everyone, including kids. Get more information and register today.
> http://sdm.link/attshape
> _______________________________________________
> gnuplot-info mailing list
> [hidden email]
> Membership management via: https://lists.sourceforge.net/lists/listinfo/gnuplot-info
>
--
Dr. Roman Grothausmann

Tomographie und Digitale Bildverarbeitung
Tomography and Digital Image Analysis

Institut für Funktionelle und Angewandte Anatomie, OE 4120
Medizinische Hochschule Hannover
Carl-Neuberg-Str. 1
D-30625 Hannover

Tel. +49 511 532-2900

------------------------------------------------------------------------------
Attend Shape: An AT&T Tech Expo July 15-16. Meet us at AT&T Park in San
Francisco, CA to explore cutting-edge tech and listen to tech luminaries
present their vision of the future. This family event has something for
everyone, including kids. Get more information and register today.
http://sdm.link/attshape
_______________________________________________
gnuplot-info mailing list
[hidden email]
Membership management via: https://lists.sourceforge.net/lists/listinfo/gnuplot-info
Reply | Threaded
Open this post in threaded view
|

Re: kdensity plot not filled with filledcurves y=0

Ethan A Merritt-2
On Monday, 04 July 2016 04:11:44 PM Grothausmann, Roman Dr. wrote:

> On 01/07/16 19:10, Ethan Merritt wrote:
> > I do not know why the filledcurves style is failing in conjunction with
> > smoothing, but a work-around is to plot  first to a datablock and then plot
> > the smoothed curve in a separate step:
> >
> > set table $SMOOTHED
> > plot $original_data using col:(weight) smooth kdensity bandwidth sigma
> > unset table
> > plot $SMOOTHED using 1:2 with filledcurves y=0
>
> Many thanks Ethan for the quick reply and the work-around. I got it working
> (https://github.com/romangrothausmann/gnuplot/blob/5f513bf1cf81c1709ff450e2830c8c59b76d2c80/hist-ar%2Bkd.gp)
>
> but the resulting plot of the "filled table" is kind of "ragged" when saved to
> SVG. See attached compressed SVG for the test data created with:
> gnuplot -e "datafile='test.dat'; outfile='test.svg'; bin=10; sigma=3.5; xmin=0;
> xmax=180; col=1; sep=','; xlabel='test'" hist-ar+kd.gp
>
> Any idea how to avoid this raggedness?

Sorry, that is in part a consequence of the work-around.

I think the issue is that you are using a partially transparent fill.
The intended behaviour (that isn't working) is to draw the entire curve
as one large semi-transparent area.  The workaround causes it to be
drawn instead as a series of adjacent semi-transparent quadrilaterals.
Whenever there is an imperfect join between two adjacent quadrilaterals
due to coordinate round-off, there can be a glitch in rendering.

This glitch is more evident when the fill area is transparent, so one
thing you could try is to make the fill style "solid" rather than
"transparent solid".
       
Ethen

------------------------------------------------------------------------------
Attend Shape: An AT&T Tech Expo July 15-16. Meet us at AT&T Park in San
Francisco, CA to explore cutting-edge tech and listen to tech luminaries
present their vision of the future. This family event has something for
everyone, including kids. Get more information and register today.
http://sdm.link/attshape
_______________________________________________
gnuplot-info mailing list
[hidden email]
Membership management via: https://lists.sourceforge.net/lists/listinfo/gnuplot-info
Reply | Threaded
Open this post in threaded view
|

Re: kdensity plot not filled with filledcurves y=0

Ethan Merritt
On Monday, 04 July 2016 11:08:52 AM Ethan A Merritt wrote:

> On Monday, 04 July 2016 04:11:44 PM Grothausmann, Roman Dr. wrote:
> > On 01/07/16 19:10, Ethan Merritt wrote:
> > > I do not know why the filledcurves style is failing in conjunction with
> > > smoothing, but a work-around is to plot  first to a datablock and then plot
> > > the smoothed curve in a separate step:
> > >
> > > set table $SMOOTHED
> > > plot $original_data using col:(weight) smooth kdensity bandwidth sigma
> > > unset table
> > > plot $SMOOTHED using 1:2 with filledcurves y=0
> >
> > Many thanks Ethan for the quick reply and the work-around. I got it working
> > (https://github.com/romangrothausmann/gnuplot/blob/5f513bf1cf81c1709ff450e2830c8c59b76d2c80/hist-ar%2Bkd.gp)
> >
> > but the resulting plot of the "filled table" is kind of "ragged" when saved to
> > SVG. See attached compressed SVG for the test data created with:
> > gnuplot -e "datafile='test.dat'; outfile='test.svg'; bin=10; sigma=3.5; xmin=0;
> > xmax=180; col=1; sep=','; xlabel='test'" hist-ar+kd.gp
> >
> > Any idea how to avoid this raggedness?
>
> Sorry, that is in part a consequence of the work-around.
>
> I think the issue is that you are using a partially transparent fill.
> The intended behaviour (that isn't working) is to draw the entire curve
> as one large semi-transparent area.  The workaround causes it to be
> drawn instead as a series of adjacent semi-transparent quadrilaterals.
> Whenever there is an imperfect join between two adjacent quadrilaterals
> due to coordinate round-off, there can be a glitch in rendering.

By the way:  the glitch is in the rendering program, not the svg file per se.
So changing the scale slightly or using a different viewing program may
reduce or exacerbate the problem.

        Ethan


>
> This glitch is more evident when the fill area is transparent, so one
> thing you could try is to make the fill style "solid" rather than
> "transparent solid".
>
> Ethen

--
mail:   Biomolecular Structure Center,  K-428 Health Sciences Bldg
        MS 357742,   University of Washington, Seattle 98195-7742

------------------------------------------------------------------------------
Attend Shape: An AT&T Tech Expo July 15-16. Meet us at AT&T Park in San
Francisco, CA to explore cutting-edge tech and listen to tech luminaries
present their vision of the future. This family event has something for
everyone, including kids. Get more information and register today.
http://sdm.link/attshape
_______________________________________________
gnuplot-info mailing list
[hidden email]
Membership management via: https://lists.sourceforge.net/lists/listinfo/gnuplot-info
Reply | Threaded
Open this post in threaded view
|

Re: kdensity plot not filled with filledcurves y=0

Grothausmann, Roman Dr.
On 04/07/16 20:17, Ethan Merritt wrote:

> On Monday, 04 July 2016 11:08:52 AM Ethan A Merritt wrote:
>> On Monday, 04 July 2016 04:11:44 PM Grothausmann, Roman Dr. wrote:
>>> Any idea how to avoid this raggedness?
>>
>> Sorry, that is in part a consequence of the work-around.
>>
>> I think the issue is that you are using a partially transparent fill.
>> The intended behaviour (that isn't working) is to draw the entire curve
>> as one large semi-transparent area.  The workaround causes it to be
>> drawn instead as a series of adjacent semi-transparent quadrilaterals.
>> Whenever there is an imperfect join between two adjacent quadrilaterals
>> due to coordinate round-off, there can be a glitch in rendering.
>
> By the way:  the glitch is in the rendering program, not the svg file per se.
> So changing the scale slightly or using a different viewing program may
> reduce or exacerbate the problem.

Thanks Ethan for the feedback.
Understanding, that the work-around is not so suitable for SVGs as it changes
the way of plotting I couldn't resist taking a look into the code to find out
what is wrong in the first place. I came as far as getting the expected
behaviour if y= is specified when applying the changes given by the patch below.
However I'm not sufficiently confident in adjusting the code appropriately for
cases I'm not familiar with. My guess it that the if statement would need an
additional check for kdensity to call need_fill_border and plot_lines.
What do You think?

--- /opt/compilation/gnuplot-5.0.3/src/graphics.c.orig 2016-07-05
09:49:40.886329514 +0200
+++ /opt/compilation/gnuplot-5.0.3/src/graphics.c 2016-07-05 09:50:22.897553791
+0200
@@ -763,16 +763,13 @@
  plot_boxes(this_plot, Y_AXIS.term_zero);
  if (bar_layer == LAYER_FRONT)
     plot_bars(this_plot);
  break;

     case FILLEDCURVES:
- if (this_plot->filledcurves_options.closeto == FILLEDCURVES_ATY1
- ||  this_plot->filledcurves_options.closeto == FILLEDCURVES_ATY2
- ||  this_plot->filledcurves_options.closeto == FILLEDCURVES_ATR
- ||  this_plot->filledcurves_options.closeto == FILLEDCURVES_BETWEEN) {
+ if (0) {
     plot_betweencurves(this_plot);
  } else {
     plot_filledcurves(this_plot);
     if (need_fill_border(&this_plot->fill_properties))
  plot_lines(this_plot);
  }


------------------------------------------------------------------------------
Attend Shape: An AT&T Tech Expo July 15-16. Meet us at AT&T Park in San
Francisco, CA to explore cutting-edge tech and listen to tech luminaries
present their vision of the future. This family event has something for
everyone, including kids. Get more information and register today.
http://sdm.link/attshape
_______________________________________________
gnuplot-info mailing list
[hidden email]
Membership management via: https://lists.sourceforge.net/lists/listinfo/gnuplot-info
Reply | Threaded
Open this post in threaded view
|

Re: kdensity plot not filled with filledcurves y=0

Grothausmann, Roman Dr.


On 05/07/16 10:03, Grothausmann, Roman Dr. wrote:
> On 04/07/16 20:17, Ethan Merritt wrote:
> Understanding, that the work-around is not so suitable for SVGs as it changes
> the way of plotting I couldn't resist taking a look into the code to find out
> what is wrong in the first place. I came as far as getting the expected
> behaviour if y= is specified when applying the changes given by the patch below.
> However I'm not sufficiently confident in adjusting the code appropriately for
> cases I'm not familiar with. My guess it that the if statement would need an
> additional check for kdensity to call need_fill_border and plot_lines.

As far as I understand: smooth_parameter = -1 by default. So possibly this could
do the trick appropriately:

--- /opt/compilation/gnuplot-5.0.3/src/graphics.c.orig 2016-07-05
09:49:40.886329514 +0200
+++ /opt/compilation/gnuplot-5.0.3/src/graphics.c 2016-07-05 11:26:14.242687554
+0200
@@ -763,13 +763,14 @@
  plot_boxes(this_plot, Y_AXIS.term_zero);
  if (bar_layer == LAYER_FRONT)
     plot_bars(this_plot);
  break;

     case FILLEDCURVES:
- if (this_plot->filledcurves_options.closeto == FILLEDCURVES_ATY1
+ if (this_plot->smooth_parameter < 0
+ &&  this_plot->filledcurves_options.closeto == FILLEDCURVES_ATY1
  ||  this_plot->filledcurves_options.closeto == FILLEDCURVES_ATY2
  ||  this_plot->filledcurves_options.closeto == FILLEDCURVES_ATR
  ||  this_plot->filledcurves_options.closeto == FILLEDCURVES_BETWEEN) {
     plot_betweencurves(this_plot);
  } else {
     plot_filledcurves(this_plot);



--
Dr. Roman Grothausmann

Tomographie und Digitale Bildverarbeitung
Tomography and Digital Image Analysis

Institut für Funktionelle und Angewandte Anatomie, OE 4120
Medizinische Hochschule Hannover
Carl-Neuberg-Str. 1
D-30625 Hannover

Tel. +49 511 532-2900

------------------------------------------------------------------------------
Attend Shape: An AT&T Tech Expo July 15-16. Meet us at AT&T Park in San
Francisco, CA to explore cutting-edge tech and listen to tech luminaries
present their vision of the future. This family event has something for
everyone, including kids. Get more information and register today.
http://sdm.link/attshape
_______________________________________________
gnuplot-info mailing list
[hidden email]
Membership management via: https://lists.sourceforge.net/lists/listinfo/gnuplot-info
Reply | Threaded
Open this post in threaded view
|

Re: kdensity plot not filled with filledcurves y=0

Ethan A Merritt-2
That is almost correct.  The test should be against
(this_plot->plot_smooth) rather than smooth_parameter.
I had a different fix in mind, but this one is better.  Thanks.

On Tue, Jul 5, 2016 at 2:31 AM, Grothausmann, Roman Dr.
<[hidden email]> wrote:

>
>
> On 05/07/16 10:03, Grothausmann, Roman Dr. wrote:
>> On 04/07/16 20:17, Ethan Merritt wrote:
>> Understanding, that the work-around is not so suitable for SVGs as it changes
>> the way of plotting I couldn't resist taking a look into the code to find out
>> what is wrong in the first place. I came as far as getting the expected
>> behaviour if y= is specified when applying the changes given by the patch below.
>> However I'm not sufficiently confident in adjusting the code appropriately for
>> cases I'm not familiar with. My guess it that the if statement would need an
>> additional check for kdensity to call need_fill_border and plot_lines.
>
> As far as I understand: smooth_parameter = -1 by default. So possibly this could
> do the trick appropriately:
>
> --- /opt/compilation/gnuplot-5.0.3/src/graphics.c.orig  2016-07-05
> 09:49:40.886329514 +0200
> +++ /opt/compilation/gnuplot-5.0.3/src/graphics.c       2016-07-05 11:26:14.242687554
> +0200
> @@ -763,13 +763,14 @@
>                 plot_boxes(this_plot, Y_AXIS.term_zero);
>                 if (bar_layer == LAYER_FRONT)
>                     plot_bars(this_plot);
>                 break;
>
>             case FILLEDCURVES:
> -               if (this_plot->filledcurves_options.closeto == FILLEDCURVES_ATY1
> +               if (this_plot->smooth_parameter < 0
> +               &&  this_plot->filledcurves_options.closeto == FILLEDCURVES_ATY1
>                 ||  this_plot->filledcurves_options.closeto == FILLEDCURVES_ATY2
>                 ||  this_plot->filledcurves_options.closeto == FILLEDCURVES_ATR
>                 ||  this_plot->filledcurves_options.closeto == FILLEDCURVES_BETWEEN) {
>                     plot_betweencurves(this_plot);
>                 } else {
>                     plot_filledcurves(this_plot);
>
>
>
> --
> Dr. Roman Grothausmann
>
> Tomographie und Digitale Bildverarbeitung
> Tomography and Digital Image Analysis
>
> Institut für Funktionelle und Angewandte Anatomie, OE 4120
> Medizinische Hochschule Hannover
> Carl-Neuberg-Str. 1
> D-30625 Hannover
>
> Tel. +49 511 532-2900
>
> ------------------------------------------------------------------------------
> Attend Shape: An AT&T Tech Expo July 15-16. Meet us at AT&T Park in San
> Francisco, CA to explore cutting-edge tech and listen to tech luminaries
> present their vision of the future. This family event has something for
> everyone, including kids. Get more information and register today.
> http://sdm.link/attshape
> _______________________________________________
> gnuplot-info mailing list
> [hidden email]
> Membership management via: https://lists.sourceforge.net/lists/listinfo/gnuplot-info

------------------------------------------------------------------------------
Attend Shape: An AT&T Tech Expo July 15-16. Meet us at AT&T Park in San
Francisco, CA to explore cutting-edge tech and listen to tech luminaries
present their vision of the future. This family event has something for
everyone, including kids. Get more information and register today.
http://sdm.link/attshape
_______________________________________________
gnuplot-info mailing list
[hidden email]
Membership management via: https://lists.sourceforge.net/lists/listinfo/gnuplot-info
Reply | Threaded
Open this post in threaded view
|

Re: kdensity plot not filled with filledcurves y=0

Grothausmann, Roman Dr.
In reply to this post by Grothausmann, Roman Dr.
Just a note, that "above"/"below" seem not to get honoured for filled kdensity.

On 05/07/16 11:31, Grothausmann, Roman Dr. wrote:

> On 05/07/16 10:03, Grothausmann, Roman Dr. wrote:
>> On 04/07/16 20:17, Ethan Merritt wrote:
>> Understanding, that the work-around is not so suitable for SVGs as it changes
>> the way of plotting I couldn't resist taking a look into the code to find out
>> what is wrong in the first place. I came as far as getting the expected
>> behaviour if y= is specified when applying the changes given by the patch below.
>> However I'm not sufficiently confident in adjusting the code appropriately for
>> cases I'm not familiar with. My guess it that the if statement would need an
>> additional check for kdensity to call need_fill_border and plot_lines.
>
> As far as I understand: smooth_parameter = -1 by default. So possibly this could
> do the trick appropriately:
>
> --- /opt/compilation/gnuplot-5.0.3/src/graphics.c.orig 2016-07-05
> 09:49:40.886329514 +0200
> +++ /opt/compilation/gnuplot-5.0.3/src/graphics.c 2016-07-05 11:26:14.242687554
> +0200
> @@ -763,13 +763,14 @@
>     plot_boxes(this_plot, Y_AXIS.term_zero);
>     if (bar_layer == LAYER_FRONT)
>        plot_bars(this_plot);
>     break;
>
>        case FILLEDCURVES:
> - if (this_plot->filledcurves_options.closeto == FILLEDCURVES_ATY1
> + if (this_plot->smooth_parameter < 0
> + &&  this_plot->filledcurves_options.closeto == FILLEDCURVES_ATY1
>     ||  this_plot->filledcurves_options.closeto == FILLEDCURVES_ATY2
>     ||  this_plot->filledcurves_options.closeto == FILLEDCURVES_ATR
>     ||  this_plot->filledcurves_options.closeto == FILLEDCURVES_BETWEEN) {
>        plot_betweencurves(this_plot);
>     } else {
>        plot_filledcurves(this_plot);
>
>
>

--
Dr. Roman Grothausmann

Tomographie und Digitale Bildverarbeitung
Tomography and Digital Image Analysis

Institut für Funktionelle und Angewandte Anatomie, OE 4120
Medizinische Hochschule Hannover
Carl-Neuberg-Str. 1
D-30625 Hannover

Tel. +49 511 532-2900

------------------------------------------------------------------------------
What NetFlow Analyzer can do for you? Monitors network bandwidth and traffic
patterns at an interface-level. Reveals which users, apps, and protocols are
consuming the most bandwidth. Provides multi-vendor support for NetFlow,
J-Flow, sFlow and other flows. Make informed decisions using capacity planning
reports.http://sdm.link/zohodev2dev
_______________________________________________
gnuplot-info mailing list
[hidden email]
Membership management via: https://lists.sourceforge.net/lists/listinfo/gnuplot-info