1

Glanced gnuplot book but couldn't found like this comparison and sum example. if I think rightly not many people need it.

I have to sum comparison results among themselves(bound) and plot as a column. For example; I have to sum these 26 of comparison result plot as a column then sum 86 of comparison result as another bar pillar. I don't have following 0 or 1 value, I want to compare and add gnuplot before plotting the bar chart. We can skip this step for now cause I made another program comparison, but summation should be by gnuplot.

I have explained first step so far. Moreover, I have a thousand 26, 86, 12,... whatever. I need a loop which sum those thousands and sum next thousand till 70000. I need just look these thousands as one thing like as pillar in whole graph for comparison.

Could you help?

S_index F_index Comparison Result Bound
2 1 0 26
2 3 0 26
2 0 0 26
1 0 0 26
3 3 1 26
2 3 0 26
0 0 1 26
0 3 0 26
0 0 1 26
2 3 0 26
3 3 1 26
0 3 0 86
0 0 1 86
0 0 1 86
0 0 1 86
2 0 0 86
1 3 0 86
3 3 1 86
3 2 0 86
0 3 0 86

Added data which sample of the csv file

2,0,28
 2,1,28
 0,3,28
 2,1,28
 3,3,28
 1,3,28
 1,1,28
 1,0,28
 2,2,28
 2,3,28
 0,1,28
 1,2,28
 0,3,28
 0,0,28
2,3,88
 2,2,88
 3,2,88
 3,2,88
 1,3,88
 2,2,88
 3,0,88
 1,3,88
 3,3,88
 0,0,88
 2,0,88
 1,2,88
 0,1,88
 3,0,88
 3,0,88
1,3,110
 1,2,110
 1,3,110
 3,2,110
 2,2,110
 0,0,110
 3,3,110
 3,2,110
 2,0,110
 2,1,110
 0,1,110
 2,0,110
 0,3,110
 0,2,110
 3,2,110
 0,3,110
 1,0,110
 2,1,110
 1,3,110
 1,3,110
 2,3,110
 3,1,110
 0,0,110
 2,1,110
 1,0,110
 0,1,110
 1,1,110
 3,3,110
 0,1,110
 1,3,110
### sum up for certain conditions
reset session

set offset 0,0,0.5,0    # <left>,<right>,<top>,<bottom>
set boxwidth 0.5
set style fill solid 0.5

set table $SumUp
    plot "boundary.csv" u 3:($1==$2) smooth freq
unset table

set yrange[0:]
set grid x,y

plot $SumUp u 0:2:xtic(1) w boxes title "Sum"

### end of code

getting error

plot "boundary.csv" u 3:($1==$2) smooth freq
                                            ^
         "gnuplot.gp" line 9: x range is invalid
gnuplot -v

    G N U P L O T
    Version 5.4 patchlevel 1    last modified 2020-12-01 

    Copyright (C) 1986-1993, 1998, 2004, 2007-2020
    Thomas Williams, Colin Kelley and many others

    gnuplot home:     http://www.gnuplot.info
    faq, bugs, etc:   type "help FAQ"
    immediate help:   type "help"  (plot window: hit 'h')

Terminal type is now 'qt'
unrecognized option -v
6
  • 1
    I'm confused by your description and I don't understand what you really want to have. What I think I understood: you have 2 columns with many values (what do you mean with 1k by 1k?). If the values in col1 and col2 are equal sum them up. What do you mean with "summarize data under 100 because is 70k"? Furthermore, is your file extension really .cvs or maybe .csv? What do you actually want to plot? Please edit your question and clarify. Commented Jun 25, 2021 at 10:22
  • @theozh I fixed, hope bit clear. sorry for confusion Commented Jun 25, 2021 at 12:21
  • 1
    sorry, still not clear. So, there are 70000 values in your table and 1000 with identical values in column3 and you want to sum up the values of column1 and column2 but only if they are equal? And then plot this sum these sums versus column3? Sorry, I don't think I got it. Commented Jun 25, 2021 at 14:49
  • @theozh no problem, on the contrary my writing ability terrible and hasty, feel free please :). Actually I'm looking true matches and count them then plot them. I need to see to summary which possible 1000. Plotting third column different curve, but I need to plot over canvas just checking exact range. Column 3 counts thousands. Commented Jun 25, 2021 at 15:15
  • 1
    I'm confused more and more. Please describe what you want in your native language and use some translator webpage to English and paste it here. Maybe then we will come closer to understand what your goal should be. Or maybe make a sketch to illustrate what you want. I still don't have any idea. Commented Jun 25, 2021 at 19:23

1 Answer 1

1

I'm still not sure whether I understood what you are looking for. The following code is summing up (counting) how many times column1 is equal column2, and does this separately for each value in column3. In the gnuplot console check help smooth, help table.

Code:

### sum up for certain conditions
reset session

$Data <<EOD
1   1   26   # <-- will be summed up
0   1   26
1   1   26   # <-- will be summed up
3   3   26   # <-- will be summed up
2   1   26
1   0   26
1   1   86   # <-- will be summed up
0   0   86   # <-- will be summed up
2   1   86
1   3   86
3   1   86
1   0   86
0   1   12
3   3   12   # <-- will be summed up
3   2   12
2   2   12   # <-- will be summed up
0   0   12   # <-- will be summed up
1   1   12   # <-- will be summed up
EOD

set offset 0,0,0.5,0    # <left>, <right>, <top>, <bottom>
set boxwidth 0.8
set style fill solid 0.5

set table $SumUp
    plot $Data u 3:($1==$2) smooth freq
unset table

set yrange[0:]
set grid x,y

plot $SumUp u 0:2:xtic(1) w boxes title "Sum"

### end of code

Result:

enter image description here

Sign up to request clarification or add additional context in comments.

9 Comments

What does do plot $SumUp u 0:2:xtic(1) w boxes title "Sum" this line cause need to plot form csv file? Cause I want to call the plot form directly C code. Actually, I used help xtic but shows xticlabels and xtics.
@maxemilian how does your data actually look like? What is your column separator? I assume comma if you have a .csv file. Please show some real data formatted as code (not as table). I would assume that you have to insert the line set datafile separator comma.
@maxemilian so, still getting x range is invalid? Please edit your question and post the exact code you are using. Which gnuplot version are you running?
@maxemilian then something must be "wrong" with your data. Can you maybe somehow provide the data? What is your language setting for decimal sign, comma or point? What is the result if you type show decimal?
@maxemilian ok, now I see the problem. Because you have comma as separator, but the table $Sumup is written with whitespace as separator (not comma). So, you have insert set datafile separator comma before the table command and set datafile separator whitespace before the final plot command.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.