Too small values to be displayed by gnuplot - gnuplot

I'm encountering a problem using gnuplot to display some distribution data (in the form of bar charts).
Because of the very high values in my data, the smallest ones cannot be displayed.
For example with these values:
10 1
20 4
21 24
22 77
23 177
24 636
25 1700
26 3433
27 5160
28 7462
29 7883
30 6652
31 4155
32 1989
33 797
34 170
Gnuplot do not display the bars corresponding to 10 and 20 because they are way too small comparatively to the maximum.
Is there a way to display them, just a little bit, other than using a logarithmic scale ?
I was especially thinking to a kind of glowing effect at the top of the bars whose values are not null, can it be done using gnuplot ?
Here are the few lines I use to display my data
set style data boxes
set style fill solid 0.1
plot 'distribution.dat'
And here is what I get for the moment:
distribution bar chart
Thanks in advance

Maybe use the "zeroaxis" representation rather than a plot border, and increase the linewidth used to draw boxes.
set style data boxes
set style fill solid 0.1
set xrange [0:*]
set yrange [-100:*]
set xzeroaxis
set yzeroaxis
set tics nomirror
unset key
unset border
plot $DATA linewidth 1.5

Related

Redrawing Excel figures on gnuplot

I was working on excel and drew two histograms shown below, I have been told to redraw them using gnuplot on windows which is very new to me.
The original graph that I want to redraw is this.
Area 1 Area 2
Case 1 Case 2 Case 1 Case 2
Parameter 1 36 66 31 72
Parameter 2 57 91 44 85
Parameter 3 62 90 50 85
My file is a text file and I wrote the above table as follows as I am not sure how to group the different columns together.
Area Area1 Area1 Area2 Area2
Case Case1 Case2 Case1 Case2
Parameter_1 36 66 31 72
Parameter_2 57 91 44 85
Parameter_3 62 90 50 85
I used the following commands and got a histogram that is grouped in the wrong way.
clear
reset
unset key
set style data histogram
set style fill solid border
set style histogram clustered
plot for [COL=2:5] 'date_mins.tsv' using COL:xticlabels(1) title columnheader
Kindly guide me on how to group columns together and also how to add the numbers on top of the bars. {The graph should be same as the one excel generated one.}
To be honest I'm regularly puzzled with histograms in gnuplot, apparently I'm not the only one. In gnuplot console, check help histograms.
Although, there are a few histogram examples on the gnuplot homepage, but of course not all possible variations can be covered.
Apparently, this plotting style is a bit confusing to understand.
This would maybe explain that there are more than 800 questions on SO on histograms with gnuplot.
I'm not sure if or how you can get your desired histogram efficiently, maybe there is an easy way.
I would do it "manually" with the plotting style with boxes.
Check the example below as a starting point. There are a few strange workarounds included, e.g. getting the titles into an array in an earlier plot for later use.
Code:
### special histogram
reset session
$Data <<EOD
Area Area1 Area1 Area2 Area2
Case Case1 Case2 Case1 Case2
"Parameter 1" 36 66 31 72
"Parameter 2" 57 91 44 85
"Parameter 3" 62 90 50 85
EOD
set style fill solid noborder
set boxwidth 0.8
set key noautotitle out center bottom horizontal reverse Left samplen 1 width 2
A=2 # Areas
C=2 # Cases
P=3 # Parameters
g=1 # gap
PosX(a,c,p) = ((a-1)*C*(P+g)) + (c-1)*(P+g) + p
PosY(a,c) = column((a-1)*C+c+1)
PosXArea(a) = (PosX(a,C,P)+PosX(a-1,C,P))*0.5
PosXCase(a,c) = (PosX(a,c,P)+PosX(a,c-1,P))*0.5
myColor(p) = int(word("0x5b9bd5 0xed7d31 0xa5a5a5",int(p)))
myValue(a,c) = strcol((a-1)*C+c+1)
set grid y
set xlabel "\n\n\n" # get empty space below the plot
set format x "" # no xtic labels
set yrange[0:]
array Titles[P] # array for titles
plot for [a=1:A] for [c=1:C] $Data u (PosX(a,c,$0)):(PosY(a,c)):(myColor($0+1)) skip 2 w boxes lc rgb var , \
for [a=1:A] for [c=1:C] '' u (PosX(a,c,$0)):(PosY(a,c)):(Titles[int($0+1)]=strcol(1), myValue(a,c)) skip 2 w labels offset 0,0.7, \
for [a=1:A] for [c=1:C] '' u (PosXCase(a,c)):(0):(myValue(a,c)) every ::1::1 w labels offset 0,-1, \
for [a=1:A] '' u (PosXArea(a)):(0):('\n\n'.myValue(a,1)) every ::0::0 w labels offset 0,-1, \
for [p=1:P] keyentry w boxes lc rgb myColor(p) ti Titles[p]
### end of code
Result:

How set point type from data in gnuplot?

How set point type from data in gnuplot?
gnuplot script:
set terminal pngcairo size 640,480
set output "points.png"
set style data points
set auto x
set autoscale x
unset colorbox
plot 'test.data' using 2:1 with points notitle
test.data
32 35 8
34 34 6
36 28 1
34 32 2
28 30 7
38 30 9
34 29 2
35 36 9
39 34 3
31 33 9
28 31 6
35 30 5
33 41 4
32 37 3
how get point type from 3 column?
plot 'gnuplot.data' using 2:1 with points pt (:3) notitle // error
abstraction example:
need:
gnuplot Version 4.6 patchlevel 4
There is no option to select the point type from the data file based on a column (equivalent to linecolor variable, pointsize variable or arrowstyle variable). Basically you have two options:
Iterate over all possible point types (which you can extract with stats if this should be variable) and for each number plot only those points which match the current point type:
stats 'test.data' using 3 nooutput
unset key
set style data points
plot for [i=STATS_min:STATS_max] 'test.data' using 2:($3 == i ? $1 : 1/0) lt 1 pt i ps 2
Use the labels plotting style and a sequence of unicode point symbols from which you select using the value from the third column as index. (use e.g. http://www.shapecatcher.com or http://decodeunicode.org/en/geometric_shapes to find suitable symbols)
unset key
set encoding utf8
symbol(z) = "•✷+△♠□♣♥♦"[int(z):int(z)]
plot 'test.data' using 2:1:(symbol($3)) with labels textcolor lt 1

Label Outliers from a boxplot in Gnuplot

I have been learning Gnuplot for about a day now and I would like to use boxplot to spot outliers from a Data Set at a Glance.
So let us say I am conducting an experiment:
On 10 subjects
I make the 10 subjects repeat a task for a 100 times,to reach 3 specific targets.
I collect how many times they reach Target1, Target2, Target3.
Those result are gathered in the file data_File_new.dat described below:
Name Target1 Target2 Target3
subject1 10 30 50
subject2 11 31 51
subject3 9 29 49
subject4 12 32 52
subject5 8 28 48
subject6 13 33 53
subject7 7 27 47
subject8 50 34 54
subject9 6 50 46
subject10 15 35 20
Now I create a boxplot from this data
file = 'data_File_new.dat'
header = system('head -1 '.file);
N=words(header)
set title 'BoxPlot Subject Success'
set ylabel 'Number Of Success'
set xtics border in scale 0,0 nomirror norotate offset character 0, 0, 0 autojustify
set xtics norangelimit
set xtics rotate -45
set xtics ('' 2)
set for [i=2:N] xtics add (word(header, i) i)
set style data boxplot
plot for [i=2:N] file using (i):i
So the result is a boxplot with outliers being plotted as solid points (I wanted to post the picture but I need 10 reputation to post the image). It tells me whether there are outliers or not.
However I want to know more I want to know who are the outliers, that is:
Subject 8 is an outlier for Target 1
Subject 9 is an outlier for Target 2
Subject 10 is an outlier for Target 3
Since Gnuplot knows these points are outliers, I expect Gnuplot to store them in some kind of list. I would like to tell Gnuplot 'plot the outliers and label them with the word of the first column (subjectx) corresponding to the line they belong to'.
Then when I open the boxplot I can identify at a glance not only there are outliers but also who they are.
Does anyone know how to do this? I looked on the forum and saw some people doing this in R but not in Gnuplot.
It's not the prettiest bit of gnuplot code but it can be done!
Gnuplot stats can be used to obtain the upper and lower quartile, which are used to produce the boxplot. You can then use some conditional code to plot the points that lie outside the range with labels. The tricky part is that the plot command is built up as string, before being evaled at the end. Like I said, not too pretty!
file = 'data_File_new.dat'
header = system('head -1 '.file)
N=words(header)
set title 'BoxPlot Subject Success'
set ylabel 'Number Of Success'
set xtics border in scale 0,0 nomirror norotate offset character 0, 0, 0 autojustify
set xtics norangelimit
set xtics rotate -45
set xtics ('' 2)
set for [i=2:N] xtics add (word(header, i) i)
r = 1.5
set style boxplot range r
unset key
cmd = "plot for [i=2:N] file using (i):i with boxplot"
do for [i=2:N] {
stats file using i every ::1 nooutput
lq = STATS_lo_quartile
uq = STATS_up_quartile
ir = uq - lq
min = lq - r * ir
max = uq + r * ir
cmd = cmd . sprintf(", file using (%d):($%d < %d || $%d > %d ? $%d : 1/0):1 every ::1 with labels offset 5,0", i, i, min, i, max, i)
}
eval cmd

histograms with shaded lines bars ( no color bars )

I have a set of data to plot using histogram bars. I want the bars to be shaded in lines but not filled with colros like red, blue or any other colors. The sample data is as below:
1 23 2 9 13
2 25 5 7 12
3 26 5 3 13
4 20 6 8 5
5 23 5 12 15
6 23 5 12 11
7 22 9 12 5
8 24 16 5 8
9 23 2 12 10
10 23 15 5 9
I have the sample code as well,
set terminal jpeg medium
set output "histo.jpeg"
set boxwidth 0.75 absolute
set style fill solid 1.00 border -1
set style histogram rowstacked
set style data histograms
set xtics 1000 nomirror
set ytics 100 nomirror
set mxtics 2
set mytics 2
set ytics 10
set yrange [0:50]
set ylabel "Total time"
set xlabel "Session number"
plot 'papa2.dat' using 3 t "Server", '' using 4 t "Client", '' using 5:xtic(1) t "Network"
But when I use this I get bars in histogram filled with colors.
Can anyone help me to on how to plot the graphs in lines instead of colors?
Many thanks in advance.
(note: I got these sample data and code from internet)
I wonder what you want is something shown in the first figure of this page: histograms.dem.
If that is the case, you can either do set style data linespoint as shown in the demo page, or plot 'papa2.dat' using 3 t "Server" with line when you use the plot command.
Note that you have a lot more demo scripts available in the gnuplot project website: Demo scripts for gnuplot 4.4

How to get a radial(polar) plot using gnu plot?

I want a radial(polar) plot using gnuplot (i.e in circular co-ordinate system(r,theta).
Here I have used the values:
Theta Max-strain
0 3400
60 5300
120 4700
180 3800
240 4100
300 3100
360 3400
How to get such a plot using gnu-plot?
I tried to recreate the plot of your question and this is what I came up with:
unset border
set polar
set angles degrees #set gnuplot on degrees instead of radians
set style line 10 lt 1 lc 0 lw 0.3 #redefine a new line style for the grid
set grid polar 60 #set the grid to be displayed every 60 degrees
set grid ls 10
set xrange [-6000:6000] #make gnuplot to go until 6000
set yrange [-6000:6000]
set xtics axis #disply the xtics on the axis instead of on the border
set ytics axis
set xtics scale 0 #"remove" the tics so that only the y tics are displayed
set xtics ("" 1000, "" 2000, "" 3000, "" 4000, "" 5000, "" 6000) #set the xtics only go from 0 to 6000 with increment of1000 but do not display anything. This has to be done otherwise the grid will not be displayed correctly.
set ytics 0, 1000, 6000 #make the ytics go from the center (0) to 6000 with incrment of 1000
set size square
set key lmargin
set_label(x, text) = sprintf("set label '%s' at (6500*cos(%f)), (6500*sin(%f)) center", text, x, x) #this places a label on the outside
#here all labels are created
eval set_label(0, "0")
eval set_label(60, "60")
eval set_label(120, "120")
eval set_label(180, "180")
eval set_label(240, "240")
eval set_label(300, "300")
set style line 11 lt 1 lw 2 pt 2 ps 2 #set the line style for the plot
#and finally the plot
plot "-" u 1:2 t "Max strain" w lp ls 11
0 3400
60 5300
120 4700
180 3800
240 4100
300 3100
360 3400
e
As you can see, the major difference is that the angle 0 is not on top but on the right (which is mathematically correct). You can change this however by modifying the using deceleration in the plot and the set_label function.
As you can see in the script not everything is really crisp and shiny. If someone finds improvements please let me know!
One last bit of "advice": It is not always reasonable to try to reproduce a plot from some tool with gnuplot. Often the strength of gnuplot is to plot data in the most simple way to be easily reproducible. Maybe you can kick some lines out of that script above and still be happy with it.
Here is a manual http://t16web.lanl.gov/Kawano/gnuplot/polar-e.html
set polar
set angles degrees
and to get circles:
set grid polar
Here is a demo: http://gnuplot.sourceforge.net/demo/polar.html

Resources