• Filtering and summation of data

    From thomas.lehmann.private@googlemail.c@21:1/5 to All on Thu May 19 11:15:08 2022
    Hi,

    considering data in a table where value are categorized.
    I would like to be able a) to filter data for a plot by category
    and b) I would like to sum up all values with same category
    being able to display it in a plot with box.

    Important: the solution should be platform independent;
    as an example "awk" or "sed" is not available on all platforms.
    Yes python would be possible but I really would prefer the
    pure Gnuplot solution if possible.

    Kind Regards,
    Thomas

    Appendix:

    What I. have sofar:

    <code>
    set terminal pngcairo size 1400,1000 enhanced font ",20"
    set output "DemoSum.png"

    $DemoData << EOD
    Timestamp, Category, Value
    2022-05-19 05:55:00, test1, 5
    2022-05-19 09:16:00, test2, 15
    2022-05-19 13:56:00, test3, 10
    2022-05-20 05:15:00, test1, 20
    2022-05-20 10:58:00, test2, 5
    2022-05-20 17:20:00, test3, 25
    EOD

    set datafile separator ","
    set key autotitle columnhead

    # a very simple plot functionality
    set multiplot layout 2, 1 title "Timestamps And Sums"

    # define line style(s)
    set style line 1 lc rgb 'grey30' ps 0 lt 1 lw 2
    set style line 2 lc rgb 'grey70' lt 1 lw 2
    set style fill solid 1.0 border rgb 'grey30'

    set timefmt "%Y-%m-%d %H:%M:%S"
    set xdata time
    set grid

    set title "Data based on date and time"
    plot $DemoData using 1:3 with linespoint linestyle 1

    unset xdata
    set title "Data based on categories"
    plot $DemoData using 3:xtic(2) with boxes linestyle 1
    </code>

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From =?UTF-8?Q?J=c3=b6rg_Buchholz?=@21:1/5 to thomas.lehm...@googlemail.com on Mon May 23 07:22:47 2022
    On 19.05.2022 20:15, thomas.lehm...@googlemail.com wrote:
    Hi,

    considering data in a table where value are categorized.
    I would like to be able a) to filter data for a plot by category
    and b) I would like to sum up all values with same category
    being able to display it in a plot with box.

    Important: the solution should be platform independent;
    as an example "awk" or "sed" is not available on all platforms.
    Yes python would be possible but I really would prefer the
    pure Gnuplot solution if possible.

    Kind Regards,
    Thomas

    Appendix:

    What I. have sofar:

    <code>
    set terminal pngcairo size 1400,1000 enhanced font ",20"
    set output "DemoSum.png"

    $DemoData << EOD
    Timestamp, Category, Value
    2022-05-19 05:55:00, test1, 5
    2022-05-19 09:16:00, test2, 15
    2022-05-19 13:56:00, test3, 10
    2022-05-20 05:15:00, test1, 20
    2022-05-20 10:58:00, test2, 5
    2022-05-20 17:20:00, test3, 25
    EOD

    set datafile separator ","
    set key autotitle columnhead

    # a very simple plot functionality
    set multiplot layout 2, 1 title "Timestamps And Sums"

    # define line style(s)
    set style line 1 lc rgb 'grey30' ps 0 lt 1 lw 2
    set style line 2 lc rgb 'grey70' lt 1 lw 2
    set style fill solid 1.0 border rgb 'grey30'

    set timefmt "%Y-%m-%d %H:%M:%S"
    set xdata time
    set grid

    set title "Data based on date and time"
    plot $DemoData using 1:3 with linespoint linestyle 1

    unset xdata
    set title "Data based on categories"
    plot $DemoData using 3:xtic(2) with boxes linestyle 1
    </code>

    stats $DemoData u(strcol(2) eq "test1" ? $3:1/0)
    sum_test1 = STATS_sum
    print sum_test1

    this is one way to get information for one category inside gnuplot.

    Jörg

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From =?UTF-8?Q?J=c3=b6rg_Buchholz?=@21:1/5 to thomas.lehm...@googlemail.com on Mon May 23 13:36:23 2022
    On 19.05.2022 20:15, thomas.lehm...@googlemail.com wrote:
    Hi,

    considering data in a table where value are categorized.
    I would like to be able a) to filter data for a plot by category
    and b) I would like to sum up all values with same category
    being able to display it in a plot with box.

    Important: the solution should be platform independent;
    as an example "awk" or "sed" is not available on all platforms.
    Yes python would be possible but I really would prefer the
    pure Gnuplot solution if possible.

    Kind Regards,
    Thomas

    Appendix:

    What I. have sofar:

    <code>
    set terminal pngcairo size 1400,1000 enhanced font ",20"
    set output "DemoSum.png"

    $DemoData << EOD
    Timestamp, Category, Value
    2022-05-19 05:55:00, test1, 5
    2022-05-19 09:16:00, test2, 15
    2022-05-19 13:56:00, test3, 10
    2022-05-20 05:15:00, test1, 20
    2022-05-20 10:58:00, test2, 5
    2022-05-20 17:20:00, test3, 25
    EOD

    set datafile separator ","
    set key autotitle columnhead

    # a very simple plot functionality
    set multiplot layout 2, 1 title "Timestamps And Sums"

    # define line style(s)
    set style line 1 lc rgb 'grey30' ps 0 lt 1 lw 2
    set style line 2 lc rgb 'grey70' lt 1 lw 2
    set style fill solid 1.0 border rgb 'grey30'

    set timefmt "%Y-%m-%d %H:%M:%S"
    set xdata time
    set grid

    set title "Data based on date and time"
    plot $DemoData using 1:3 with linespoint linestyle 1

    unset xdata
    set title "Data based on categories"
    plot $DemoData using 3:xtic(2) with boxes linestyle 1
    </code>

    Do you mean the second graph like this?

    <code>
    set terminal pngcairo size 1400,1000 enhanced font ",20"
    set output "DemoSum.png"

    $DemoData << EOD
    Timestamp, Category, Value
    2022-05-19 05:55:00, test1, 5
    2022-05-19 09:16:00, test2, 15
    2022-05-19 13:56:00, test3, 10
    2022-05-20 05:15:00, test1, 20
    2022-05-20 10:58:00, test2, 5
    2022-05-20 17:20:00, test3, 25
    EOD

    set datafile separator ","
    set key autotitle columnhead

    # a very simple plot functionality
    set multiplot layout 2, 1 title "Timestamps And Sums"

    # define line style(s)
    set style line 1 lc rgb 'grey30' ps 0 lt 1 lw 2
    set style line 2 lc rgb 'grey70' lt 1 lw 2
    set style fill solid 1.0 border rgb 'grey30'

    set timefmt "%Y-%m-%d %H:%M:%S"
    set xdata time
    set grid

    set title "Data based on date and time"
    plot $DemoData using 1:3 with linespoint linestyle 1

    unset xdata
    set title "Data based on categories"

    stats $DemoData u(strcol(2) eq "test1" ? $3:1/0)
    sum_test1 = STATS_sum
    stats $DemoData u(strcol(2) eq "test2" ? $3:1/0)
    sum_test2 = STATS_sum
    stats $DemoData u(strcol(2) eq "test3" ? $3:1/0)
    sum_test3 = STATS_sum

    set xtics in ('test1' 1, 'test2' 2, 'test3' 3)

    set boxwidth 1 absolute
    set yrange [0:*]
    set xrange [0:4]
    plot '+' u (1):(sum_test1) w boxes, '+' u (2):(sum_test2) w boxes, '+'
    u (3):(sum_test3) w boxes
    unset multiplot
    set out
    reset
    </code>

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)