Adding transparency to the points in gnuplot - plot

I am trying to visualize a block of two different color particles and I want to add transparency to the points. I write a file (cubo.d) with this data (example):
1 1 1 ar
1 1 2 ar
1 2 1 ar
1 2 2 ar
2 1 1 ab
2 1 2 ab
2 2 1 ab
2 2 2 ab
And then I read it with this code in gnuplot:
set border 0
unset tics
unset key
set view equal xyz
set style fill transparent solid 0.2 noborder
spin(name) = name[1:2] eq "ar" ? 0xcdca00 : name [1:2] eq "ab" ? 0x000000 : 0x888888
splot 'cubo.d' using 1:2:3:(spin(strcol(4))) w p pt 5 ps 2
But the points doesn't have transparency.
I tried adding fs solid 0.2 and also lc rgb 0x888888 after w p pt 5 ps 2 but those doesn't work either.
The four yellow particles are hidding part of the black particles behind

The scheme for transparent colors is
lc rgb 0xaarrggbb
Check help colorspec.

Related

gnuplot: How to add a new colored curve every nth row while removing intermediate headers?

I've got a file which has this structure:
Header 1
Header 2
config X Y
0.0 -5 -2
0.0 0 1
0.0 5 4
Header2
Config X Y
1.0 -5 -1
1.0 0 0
1.0 5 5
Header2
Config X Y
2.0 -5 0
2.0 0 1
2.0 5 6
Using gnuplot, I would like to plot columns 2:3 (Y as a function of X) with a few conditions:
Get rid of the headers and any line that's not filled with numbers
On the same graph, plot a new function (with a new label and a new color) each time the config changes. In the aforementioned case, you'd end up with three plots (one for config=0.0, one for config=1.0 and one for config=2.0)
Is there a one-liner for this in Gnuplot?
I tried to use the "every" keyword
p 'filename.txt' every ::3 u 2:3 w p
but to no avail
Thank you
If you have a strict data structure and you insist on a one-liner you could do the following with every, check help every.
However, then you need to know in advance that N=5 (here: 2 header lines and 3 data lines) and you have 3 blocks. You also skip the first 3 lines (check help skip).
You could use stats find out N automatically.
Personally, I would prefer a solution with more than one line, which would robust against little changes in data, just in case.
Script:
### separate data into subblocks with different colors
reset session
$Data <<EOD
Header 1
Header 2
config X Y
0.0 -5 -2
0.0 0 1
0.0 5 4
Header2
Config X Y
1.0 -5 -1
1.0 0 0
1.0 5 5
Header2
Config X Y
2.0 -5 0
2.0 0 1
2.0 5 6
EOD
plot for [i=0:2] N=5 $Data u 2:3 every ::i*N::(i+1)*N-1 skip 3 w lp pt 7 lc i ti sprintf("Config%d",i)
### end of script
Result:
Addition:
Here is a more general (but maybe not too obvious) solution:
you don't need to know in advance how many blocks you have and how many datalines you have
you can have different number of data lines
What the script does:
during plotting, the script checks if the column 1 contains a valid number, valid(1) will return 1 if it is a valid number and 0 otherwise (check help valid).
the variable c1 is initialized to 0. During plotting line by line c0 is assigned the value of c1 and c1 gets the value of valid(1).
so, everytime column 1 changes from text to numbers (i.e. c1>c0) increment b by 1 and use it for setting the color (check help lc variable)
plot keyentries in a loop with the corresponding title.
So, it is a two-liner which also could be put into a single line.
Script:
### separate data into subblocks with different colors (more flexibility)
reset session
$Data <<EOD
Header 1
Header 2
Header 3
config X Y
0.0 -5 -2
0.0 0 1
0.0 5 4 # could be followed e.g. by an empty line
Header2
Config X Y
1.0 -5 -1
1.0 0 0
1.0 5 5
1.0 6 6 # 4 data entries
Header2
Config X Y
Some other text line added
2.0 -5 0
2.0 0 1
2.0 5 6
2.0 6 7
2.0 7 6.5 # 5 data entries
EOD
set key top left noautotitle
plot c1=b=0 $Data u (c0=c1,c1=valid(1),$2):($3):(c1>c0?b=b+1:b-1) w lp pt 7 lc var, \
for [i=0:b-1] keyentry w lp pt 7 lc i ti sprintf("Config%d",i)
### end of script
Result:

Gnuplot bar chart with personalize interval on x-axis

I'm new using gnuplot and i would like to replicate this plot: https://images.app.goo.gl/DqygL2gfk3jZ7jsK6
I have a file.dat with continuous value between 0 and 100 and i would like to plot it, subdivided in intervals ( pident> 98, 90 < pident < 100...) Etc. And on y-axis the total occurrences.
I looked everywhere finding a way but still I cannot do it.
Thank you !
sample of the data, with the value and the counts:
33.18 5
43.296 1
33.19 1
27.168 5
71.429 11
30.698 9
47.934 1
43.299 3
30.699 3
37.092 2
24.492 2
24.493 2
24.494 7
47.938 1
24.497 1
37.097 8
37.099 2
33.824 7
51.111 15
59.025 2
62.553 2
62.554 2
57.867 2
33.826 2
62.555 1
33.827 5
62.556 2
33.828 1
59.028 1
46.429 11
51.117 1
75.158 2
27.621 1
27.623 1
27.624 2
37.5 113
37.6 2
32.313 8
27.626 3
37.7 3
32.314 1
67.797 3
27.628 2
32.316 2
37.9 1
61.044 1
43.81 5
32.317 8
32.318 2
43.82 4
32.319 2
43.83 2
37.551 3
61.048 1
48.993 6
29.43 2
This is the code tried so far (where i also calculate the mean):
#!/usr/bin/gnuplot -persist
set noytics
# Find the mean
mean= system("awk '{sum+=$1*$2; tot+=$2} END{print sum/tot}' hist.dat")
set arrow 1 from mean,0 to mean, graph 1 nohead ls 1 lc rgb "blue"
set label 1 sprintf(" Mean: %s", mean) at mean, screen 0.1
# Histogram
binwidth=10
bin(x,width)=width*floor(x/width)
plot 'hist.dat' using (bin($1,binwidth)):(1.0) smooth freq with boxes
This is the result:
The following script takes your data and sums up the second column within the defined bins.
If you have values of equal 100 in the first column, those values would be in the bin 100-<110.
With Bin(x) = floor(x/BinWidth)*BinWidth + BinWidth*0.5, the bins are shifted by half a binwidth to let the boxes on the x-axis range from the beginning of the bin to the end of the bin (and not centered at the beginning of the respective bin).
If you explicitely want to have xtics labels like in the example graph you've shown, i.e. 10-<20, 20-<30 etc. you would have to fiddle around with the xtic labels.
Edit: Forgot the mean value. There is no need for calling awk. Gnuplot can do this for you as well, check help stats.
Code:
### create histogram
reset session
$Data <<EOD
33.18 5
43.296 1
33.19 1
27.168 5
71.429 11
30.698 9
47.934 1
43.299 3
30.699 3
37.092 2
24.492 2
24.493 2
24.494 7
47.938 1
24.497 1
37.097 8
37.099 2
33.824 7
51.111 15
59.025 2
62.553 2
62.554 2
57.867 2
33.826 2
62.555 1
33.827 5
62.556 2
33.828 1
59.028 1
46.429 11
51.117 1
75.158 2
27.621 1
27.623 1
27.624 2
37.5 113
37.6 2
32.313 8
27.626 3
37.7 3
32.314 1
67.797 3
27.628 2
32.316 2
37.9 1
61.044 1
43.81 5
32.317 8
32.318 2
43.82 4
32.319 2
43.83 2
37.551 3
61.048 1
48.993 6
29.43 2
EOD
# Histogram
BinWidth = 10
Bin(x) = floor(x/BinWidth)*BinWidth + BinWidth*0.5
# Mean
stats $Data u ($1*$2):2 nooutput
mean = STATS_sum_x/STATS_sum_y
set arrow 1 from mean, graph 0 to mean, graph 1 nohead lw 2 lc rgb "red" front
set label 1 sprintf("Mean: %.1f", mean) at mean, graph 1 offset 1,-0.7
set xlabel "Identity / %"
set xrange [0:100]
set xtics 10 out
set ylabel "The number of blast hits"
set style fill solid 0.3
set boxwidth BinWidth
set key noautotitle
set grid x,y
plot $Data using (Bin($1)):2 smooth freq with boxes lc "blue"
### end of code
Result:

Gnuplot: How to plot points with pm3d?

I want to plot a data file with 16 given points using pm3d in gnuplot, but I also want all this given points to be shown on the plot. That's how my data file (xyz.dat) looks like:
# X Y Z
0 0 0.632
0 5 0.46
0 10 0.37
0 50 0.41
5 0 0.95
5 5 0.66
5 10 0.59
5 50 0.5
10 0 1.5
10 5 0.96
10 10 0.77
10 50 0.5
50 0 1.5
50 5 1.5
50 10 1.5
50 50 0.98
Here is my code so far:
set ticslevel 0
set dgrid3d 30,30
set palette defined (0 "blue", 0.75 "white", 1.4 "red")
set style lines 100 lt 5 lw 0.5
set pm3d hidden3d 100
set grid
set view 74,216
unset key
splot 'xyz.dat' using 1:2:3 with pm3d
This produces the following output:
Output
I'm really glad with this result, but I want to make this 16 given points from the data file clearly visible on this plot, but I become just something like that:
Outputs with points
I want this 16 points (and only this 16 points) to be clearly shown on the "Output"-picture, but I don't know, how to change my code for that. Thank you in advance!
The difficulty you are encountering is not because of pm3d but rather because you have enabled auto-generation of gridded surfaces via the command set dgrid3d. Any plot style that can become a surface is caught by this. You can work around this by using a non-surface plot style like with labels. Of course you don't have any actual label text, but you can still draw a point indicating the label position. Your plot command becomes
splot 'xyz.dat' using 1:2:3 with pm3d, \
'xyz.dat' using 1:2:3:("") with labels point pt 7

gnuplot: stacked newhistogram, starting with same fillstyle pattern, not appearing in shared key

I am trying to create multiple columnstacked histograms in gnuplot using the newhistogram command.
The data share the same structure so I want the boxes to share the same key like in this question, but with a pattern fillstyle (not only color).
My script looks like this:
set style data histogram
set style histogram columnstacked
set style fill pattern
set boxwidth 0.75
set xtics ("fff" 0, "ggg" 1, "hhh" 3, "iii" 4)
set grid y
set border 3 # remove top and right plot-border
set key outside title 'key' width -30
plot \
newhistogram "data A" fs pattern 2 lt 1, \
"plot_test_data.out" u 2, '' u 3, \
newhistogram "data B" fs pattern 2 lt 1, \
"plot_test_data_2.out" u 2:key(1), '' u 3
which produces the following output:
Could anybody explain why the key doesn't show the correct pattern? (I tried adding fs pattern in each using directive and removing the linetype, but nothing bears the desired output).
I am using
G N U P L O T
Version 4.6
patchlevel 3
last modified 2013-04-12
Build System: Linux x86_64
with 2 test data sets
plot_test_data.out:
0 1 3 2 2
1 1 6 4 4
2 2 5 4 5
3 1 1 3 4
4 1 2 4 5
plot_test_data_2.out:
0 1 4 3 1
1 3 6 4 2
2 2 5 6 4
3 2 5 5 3
4 1 3 4 2
thank you!

Gnuplot heatmap XYZ

Hey guys I'm trying to do a real heat map like in A true heat map in R, but in GNUPLOT.
My file is like
3 1 2
3 4 3
3 5 5
4 1 7
4 1 2
4 4 3
4 5 2
5 1 3
5 1 2
5 4 3
.
..
....
and I've tried with
plot "file" using 1:2:3 with image
splot "file" using 1:2:3 p3md
etc..
Also I follow this example http://gnuplot.sourceforge.net/demo/heatmaps.html, but nothing.
Can someone shed some light here please?
Thanks
set pm3d interpolate 2,2
splot "file"
You can adjust level of interpolation by changing the number or even set it as 0 to tell gnuplot to "guess" it. It is not well documented what interpolation method that gnuplot is using, so be careful.
set pm3d interpolate 0,0
splot "file"
Here's the result without interpolation:
Here's the result with interpolation 2,2:
Here's the result with interpolation 0,0:
Use the pm3d option:
set pm3d
splot "file"

Resources