I am working on gnuplot with bar-stacked. I tried to create an ideal size on graphs. any breaks on the left and the top of graph. I think it is not problems because my latex file can show perfect graph without any breaks. But when I tried run in other OS, it has error in latex. It can't handle the graphs. After I found the root cause of this, it is happen because I am use:
font ",40"
So, latex can't process it and break on this graph. I guess it have related with my break in my *.eps files.
This is my data:
desc is-1 is-2 is-3 is-4 is-5 is-6 is-7 is-8
A 37.01 24.80 28.39 2.65 3.70 1.10 2.20 0.14
B 58.16 22.19 9.95 3.06 3.32 3.32 0.00 0.00
C 40.46 18.72 18.49 6.45 14.27 1.04 0.33 0.24
D 30.29 31.59 22.39 9.69 1.30 2.37 1.57 0.80
E 35.41 15.88 24.71 14.67 7.18 1.52 0.32 0.32
F 29.91 30.36 18.29 9.46 8.29 1.26 1.89 0.54
Tot 37.41 22.61 21.76 7.71 7.66 1.52 0.99 0.34
This is my Gnuplot File:
set term pos eps font 20
set style data histogram
set style histogram rowstacked
set style fill solid border -1
set key reverse above Left width 3 height -2.5 font ",40" autotitle columnheader
set key outside top spacing 2.5
set boxwidth 0.7
set format y "%.0f%%"
set yrange [0:100]
set size 0.9 , 2
set ytics out nomirror
#set offset -0.3,-0.6,0,0
#label count
set label 1 "854" at 0,102 rotate by 90 font ",40"
set label 2 "274" at 1,102 rotate by 90 font ",40"
set label 3 "1564" at 2,102 rotate by 90 font ",40"
set label 4 "740" at 3,102 rotate by 90 font ",40"
set label 5 "979" at 4,102 rotate by 90 font ",40"
set label 6 "204" at 5,102 rotate by 90 font ",40"
set label 7 "4625" at 6,102 rotate by 90 font ",40"
set xtics font ",40"
set ytics font ",40"
set bmargin 3
set xtics offset 0,-1,0
set notitle
set noylabel
set noxlabel
set border 3 lw 2
set output 'output.eps'
plot 'datafile' \
using($2):xtic(1) lt -1 fs pattern 3, \
'' using($3) lt -1 fs pattern 2, \
'' using($4) lt -1 fs pattern 5, \
'' using($5) lt -1 fs pattern 9, \
'' using($6) lt -1 fs pattern 3, \
'' using($7) lt -1 fs pattern 7, \
'' using($8) lt -1 fs pattern 3, \
'' using($5) lt -1 fs pattern 4
This is my output:
I am guessing latex error because of Gnuplot Font, It will clear if the output in*.eps file show the perfect graph. Could you help me, what is wrong with my border gnuplot script? Thanks or any suggestion for my problems?
*ps: graphs looks good on Ubuntu 12.04 but break in mac os. Thanks Thanks Thanks
after I set lmargin =10:
I added the following:
set lmargin 10
set tmargin 15
These will just add a left margin and top margin to your plot so that you have enough space.
And changed this line:
set key reverse above Left width 3 height 1 font ",40" autotitle columnheader
I changed the height to a small positive number in the above
Related
I am using gnuplot combined with AWK to plot 2D bar plot from the following input data:
#Acceptor DonorH Donor Frames Frac AvgDist AvgAng
lig_608#O3 HIE_163#HE2 HIE_163#NE2 498 0.5304 2.8317 153.0580
lig_608#O GLU_166#H GLU_166#N 476 0.5069 2.8858 161.7174
lig_608#O1 HIE_41#HE2 HIE_41#NE2 450 0.4792 2.8484 158.5193
THR_26#O lig_608#H9 lig_608#N1 399 0.4249 2.8312 149.9578
lig_608#O2 THR_26#H THR_26#N 312 0.3323 2.9029 164.8033
lig_608#O1 ASN_142#HD21 ASN_142#ND2 14 0.0149 2.8445 158.4224
lig_608#O1 GLN_189#HE22 GLN_189#NE2 2 0.0021 2.8562 149.7421
lig_608#O1 GLN_189#HE21 GLN_189#NE2 1 0.0011 2.7285 158.4377
lig_608#O3 GLY_143#H GLY_143#N 1 0.0011 2.7421 147.8213
My script takes the data from the third and 5th columns considering only the lines where the value from the 5th column > 0.05, producing bar graph
cat <<EOS | gnuplot > graph.png
set term pngcairo size 800,600
set xtics noenhanced
set xlabel "Fraction, %"
set ylabel "H-bond donor, residue"
set key off
set style fill solid 0.5
set boxwidth 0.9
plot "<awk 'NR == 1 || \$5 > 0.05' $file" using 0:5:xtic(3) with boxes
EOS
!EDITED:
within my bash workflow the script looks like
for file in "${output}"/${target}*.log ; do
file_name3=$(basename "$file")
file_name2="${file_name3/.log/}"
file_name="${file_name2/${target}_/}"
echo "vizualisation with Gnuplot!"
cat <<EOS | gnuplot > ${output}/${file_name2}.png
set title "$file_name" font "Century,22" textcolor "#b8860b"
set tics font "Helvetica,12"
#set term pngcairo size 1280,960
set term pngcairo size 800,600
set yrange [0:1]
set xtics noenhanced
set xlabel "Fraction, %"
set ylabel "H-bond donor, residue"
set key off
set style fill solid 0.5
set boxwidth 0.9
plot "<awk 'NR == 1 || \$5 > 0.05' $file" using 0:5:xtic(3) with boxes
EOS
done
This is the image produced from following filtered data:
HIE_163#NE2 0.5304
GLU_166#N 0.5069
HIE_41#NE2 0.4792
lig_608#N1 0.4249
THR_26#N 0.3323
I need to modify my awk searching expression integrated in the
gnuplot that makes selection of the two columns from the whole data.
Instead of taking the index from the third column (Donor) from each
line I need to take it either from the first (#Acceptor) or form the
third (#Donor) column. The index should be taken from one of these
columns depending on the lig_* pattern. E.g. if the data in the
(#Acceptor) column starts from lig* I need to take the value from the
third column (#Donor) of the same line and visa verse (lig* pattern
presents either in the 1st column or in the 3rd but not in the both..)
Taking my example, the filtered data with the updated searching should become:
HIE_163#NE2 0.5304 # the first index from the third column
GLU_166#N 0.5069 # the first index from the third column
HIE_41#NE2 0.4792 # the first index from the third column
THR_26#O 0.4249 # !!!! the first index from the first column !!
THR_26#N 0.3323 # the first index from the third column
No need for awk, you can do it all in gnuplot (hence platform-independent).
This would be my first attempt. You will filter by plotting the unwanted data at x-value of NaN, however, this will give some warnings: warning: add_tic_user: list sort error which you can ignore.
But this can probably be avoided by some changes.
Edit: the original script would have failed when the first line had a value <0.05 in column 5. Here are two versions which don't have this problem. There will also be no warnings. Maybe these attempts can be further simplified.
For creating an output file simply add this to your script: (check help output)
set term pngcairo size 800,600
set output "myOutputFile.png"
...<your script>...
set output
Data: SO73961783.dat
#Acceptor DonorH Donor Frames Frac AvgDist AvgAng
lig_608#O3 HIE_163#HE2 HIE_163#NE2 498 0.5304 2.8317 153.0580
lig_608#O GLU_166#H GLU_166#N 476 0.5069 2.8858 161.7174
lig_608#O1 HIE_41#HE2 HIE_41#NE2 450 0.4792 2.8484 158.5193
THR_26#O lig_608#H9 lig_608#N1 399 0.4249 2.8312 149.9578
lig_608#O2 THR_26#H THR_26#N 312 0.3323 2.9029 164.8033
lig_608#O1 ASN_142#HD21 ASN_142#ND2 14 0.0149 2.8445 158.4224
lig_608#O1 GLN_189#HE22 GLN_189#NE2 2 0.0021 2.8562 149.7421
lig_608#O1 GLN_189#HE21 GLN_189#NE2 1 0.0011 2.7285 158.4377
lig_608#O3 GLY_143#H GLY_143#N 1 0.0011 2.7421 147.8213
Script 1:
Filter your data and write it into a new table. If condition >0.05 is not met, write an empty line. Probably the easiest to understand and gives the shortest final plot command.
### conditional xtic labels
reset session
set termoption noenhanced
FILE = "SO73961783.dat"
set xlabel "Fraction, %"
set ylabel "H-bond donor, residue"
set key off
set style fill solid 0.5
set boxwidth 0.9
set grid y
set xrange[-1:5]
set table $Filtered
myTic(col1,col2) = strcol(col1)[1:3] eq 'lig' ? strcol(col2) : strcol(col1)
plot FILE u ((y0=column(5))>0.05 ? sprintf("%g %s",y0,myTic(1,3)) : '') w table
unset table
plot $Filtered u 0:1:xtic(2) w boxes
### end of script
Script 2:
Without extra table, but a more complex plot command. Increase the x-position x0 if a value>0.05 is found (except for the first time) and keep the previous position and and label (i.e. overwrite it) if a value<=0.05 is found.
### conditional xtic labels
reset session
set termoption noenhanced
FILE = "SO73961783.dat"
set xlabel "Fraction, %"
set ylabel "H-bond donor, residue"
set key off
set style fill solid 0.5
set boxwidth 0.9
set grid y
set xrange[-1:5]
myTic(col1,col2) = strcol(col1)[1:3] eq 'lig' ? strcol(col2) : strcol(col1)
plot x0=c=(t0='',0) FILE u ((y0=column(5))>0.05 ? (c==0 ? (c=1,t0=myTic(1,3)) : (x0=x0+1,t0=myTic(1,3))) : (y0=NaN),x0):(y0):xtic(t0) w boxes
### end of script
Result:
As you potentially want to do more complicated processing with awk, I would
suggest an alternative way of mixing awk and gnuplot.
Gnuplot supports including inline data in its script files, so you could have awk generate the inline data while supplying the plot-configuration with bash, all done in a sub-shell. For example:
(
printf '$data << EOD\n'
awk 'NR>1 && $5>0.05 { print $1 ~ /^lig/ ? $3 : $1, $5 }' infile
cat << EOS
EOD
set term pngcairo size 1280,960 font ",20"
set output "output.png"
set xtics noenhanced
set ytics 0.02
set grid y
set key off
set style fill solid 0.5
set boxwidth 0.9
set xlabel "Fraction, %"
set ylabel "H-bond donor, residue"
plot "\$data" using 0:2:xtic(1) with boxes, "" using 0:2:2 with labels offset 0,1
EOS
)
Would produce this gnuplot script:
$data << EOD
HIE_163#NE2 0.5304
GLU_166#N 0.5069
HIE_41#NE2 0.4792
THR_26#O 0.4249
THR_26#N 0.3323
EOD
set term pngcairo size 1280,960 font ",20"
set output "output.png"
set xtics noenhanced
set ytics 0.02
set grid y
set key off
set style fill solid 0.5
set boxwidth 0.9
set xlabel "Fraction, %"
set ylabel "H-bond donor, residue"
plot "$data" using 0:2:xtic(1) with boxes, "" using 0:2:2 with labels offset 0,1
Pipe it to Gnuplot, i.e. (...) | gnuplot and get this in output.png:
Hello, I would like to plot something that is close to this but
I cannot seem to get it.
I have the data
data table2_1;
input Modified_Mortar Unmodifided_Mortar;
cards;
16.85 16.62
16.40 16.75
17.21 17.37
16.35 17.12
16.52 16.98
17.04 16.87
16.96 17.34
17.15 17.02
16.59 17.08
16.57 17.27
;
run;
And I tried
proc freq data=table2_1;
tables Modified_Mortar / plots=freqplot (type=dotplot);
tables Unmodifided_Mortar / plots=freqplot (type=dotplot);
run;
but it gave me an unnecessarily huge plot which was spaced equally and cannot compare the two distributions as I intended.
I played around a bit with sgplot and this is the closest I could come up with. It's not exact, but with a little fiddling in an image editor you can pretty much get it.
data table2_1;
input Modified_Mortar Unmodifided_Mortar;
retain mod_line 0.75 unmod_line 0;
cards;
16.85 16.62
16.40 16.75
17.21 17.37
16.35 17.12
16.52 16.98
17.04 16.87
16.96 17.34
17.15 17.02
16.59 17.08
16.57 17.27
;
run;
proc sgplot data=table2_1;
label Modified_Mortar = 'Strength (kgf/cm squared)';
scatter x = Modified_Mortar y=mod_line / markerattrs=(symbol=circlefilled color=black size=10);
scatter x = Unmodifided_Mortar y=unmod_line / markerattrs=(symbol=circlefilled color=bib size=10);
refline -0.25 / axis=y lineattrs=(color=bib thickness=2) name='mod' legendlabel='Unmodified' ;
refline 0.5 / axis=y lineattrs=(color=black thickness=2) name='unmod' legendlabel='Modified';
yaxis display=(nolabel) min=-0.25 max=15;
xaxis values=(16.24 to 17.50 by 0.14) min=16.30 max=17.40 valueattrs=(size=12) labelattrs=(size=12);
keylegend 'mod' 'unmod' / location=outside position=bottom valueattrs=(size=12);
run;
Here is a different approach that uses the data in a treatment:response categorical form. A labeled triangle marker is used to show the mean (triangle apex being the balance point)
data have;
treatment = 'Modified '; y=1.13; input response #; output;
treatment = 'Unmodified'; y=0.13; input response; output;
attrib
response label = "Strength (kgf/cm2)"
;
cards;
16.85 16.62
16.40 16.75
17.21 17.37
16.35 17.12
16.52 16.98
17.04 16.87
16.96 17.34
17.15 17.02
16.59 17.08
16.57 17.27
;
run;
proc sql;
create table plot as
select * from have
outer union corresponding
select
treatment,
case treatment
when ('Unmodified') then -0.15
when ('Modified ') then 0.85
else 0
end as y2,
mean(response) as mean format=5.2
from have
group by treatment;
quit;
ods proclabel "Concrete dot plot";
ods graphics / height=220px width=800px;
proc sgplot data=plot description="Response to treatment";
title "Concrete strength response to treatment";
scatter
x=response y=y
/ markerattrs=(symbol=circlefilled color=black size=12px)
;
scatter
x=mean y=y2
/ datalabel=mean
datalabelpos=bottom
markerattrs=(symbol=triangle color=black size=12px)
;
keylegend
/ exclude = ("y" "y2")
;
yaxis
offsetmin = 0.2
values = ( 0 1 2 )
valuesdisplay = ( "Unmodified" "Modified" " " )
display = ( noticks nolabel )
colorbands = odd
;
xaxis
grid
;
refline 0.00 ;
refline 1.00 ;
run;
title;
footnote;
I have created heatmap graphs using gnuplot.
I have data.dat:
avail reli perf
stop 181 20 121 10 34 20
jitter 18 20 17 20 13 20
limp 12 20 5 30 20 20
and gnuplot script:
set term pos eps font 20
unset key
set nocbtics
set cblabel "Score"
set cbtics scale 0
set cbrange [ 0.00000 : 110.00000 ] noreverse nowriteback
set palette defined ( 0.0 "#FFFFFF",\
1 "#FFCCCC",\
20.2 "#FF9999 ",\
30.3 "#FF6666",\
40.4 "#FF3333",\
50.5 "#FF0000",\
60.6 "#CC0000",\
70.7 "#C00000",\
80.8 "#B00000",\
90.9 "#990000",\
100.0 "#A00000")
set title "Faults"
set ylabel "Hardware Faults"
set xlabel "Aspects"
set size 1, 0.5
set output 'c11.eps'
YTICS="`awk 'BEGIN{getline}{printf "%s ",$1}' 'data2.dat'`"
XTICS="`head -1 'data2.dat'`"
set for [i=1:words(XTICS)] xtics ( word(XTICS,i) i-1 )
set for [i=1:words(YTICS)] ytics ( word(YTICS,i) i-1 )
plot "<awk '{$1=\"\"}1' 'data2.dat' | sed '1 d'" matrix w image, '' matrix using 1:2:($3==0 ? " " : sprintf("%.1d",$3)) with labels
#######^ replace the first field with nothing
################################## ^ delete first line
My output is:
Here I have range 1-20,30-39,...,100 or more)
Now I have to 2 values in every axis. e.g stop and avail have(181 and 20). the 181 is the count and 20 is percentages. I want to create graphs which have colors base on percentages and the labels on my graphs from the counts of data.
I have experienced create some graph using for and do some modulo to select the data. But here, I have not idea to create that graphs. Any suggestion for creating this? Thanks!
You can use every to skip columns.
plot ... every 2 only uses every second column, which is what you can use for the labels. For the colors, you must start with the second column (numbered with 1), and you need every 2::1.
Following are the relevant changes only to your script:
set for [i=1:words(XTICS)] xtics ( word(XTICS,i) 2*i-1 )
plot "<awk '{$1=\"\"}1' 'data2.dat' | sed '1 d'" matrix every 2::1 w image, \
'' matrix using ($1+1):2:(sprintf('%d', $3)) every 2 with labels
The result with 4.6.5 is:
I haven't answer the question after I google it.
I have data.txt like this:
a b c
sys1 3 2 0
sys2 4 4 4
sys3 5 2 4
sys4 6 4 1
I created graphs using rowstacked style with pattern, currently I select the patterns manually. I have to plotting my data.txt with sys1-sys4 and a-c. This matrix always have the same size, but I should do sorting and re generate with different order sequence.
this is my gnuplot script:
set term pos eps font 20
set style data histogram
set style histogram rowstacked
set key invert reverse right outside # above outside or left outside
set boxwidth 0.75
set ylabel "Count"
set xlabel "System"
set xtics nomirror rotate by -270
set output 'eps/a1-count.eps'
plot 'a1-count' \
using($2):xtic(1) title "data 1" lt -1 fs pattern 3, \
'' using($3) title "data 2" lt -1 fs pattern 4, \
'' using($3) title "data 3" lt -1 fs pattern 6
and this is the output:
I also found some solution here but it is for heat map. Anyone can help me?
Thanks a lot!
you can sort directly the data within gnuplot : (-nk[column]), with linux 'sort' command:
plot '<sort -nk1 data.txt' \
u 2:xtic(1) title "data 1" lt -1 fs pattern 3, \
'' u 3 title "data 2" lt -1 fs pattern 4, \
'' u 3 title "data 3" lt -1 fs pattern 6
The '' empty string file call, will keep the sorted datafile.
the title of your question is not correct, but thanks to you, i learnd the :xtic(column) feature and the correct way of doing :
set xtics nomirror rotate by -270
Regards,
my data is quite simple, just a timestamp and a number like this:
2013-01-23 08:27:55 2801
2013-01-23 08:33:13 2801
2013-01-23 08:38:31 2660
2013-01-23 08:43:49 2785
2013-01-23 08:49:07 2785
I get the data from a another system. Space between date and time, and tabulator between "date time" and the number.
The whole time window is a few hours .. a couple of days. This overall time window contains one or more interesting parts (typically few..several hours), and I would like to mark or highlight these interesting parts somehow to make it easier and faster to analyse the graphs.
Th einteresting time window would need to be specified manually, e.g. from 2014-01-23 10:00:00 to 2013-01-24 12:00:00 for 2 hour window.
Drawing a rectancle to the background of the linegraph is one possibility, and changing the line color (or something similar) is another.
How can I do that from manually/separately defined time stamps? The best I was able to find was splitting the data with empty lines, and use something like this (from http://www.gnuplotting.org/introduction/plotting-data/):
set style line 1 lc rgb '#0060ad' lt 1 lw 2 pt 7 ps 1.5 # --- blue
set style line 2 lc rgb '#dd181f' lt 1 lw 2 pt 5 ps 1.5 # --- red
plot 'plotting-data3.dat' index 0 with linespoints ls 1, '' index 1 with linespoints ls 2
But splitting the data is a bit arduous (?); I'm looking for elegant gnuplot means to achive the goal. Robust splitting could be possible as well, if thats really the best alternative.
Below is the plotting function, works well but I'd like to mark/highlight selected parts of the graph.
-Paavo
function my_gnuplot {
if [ $# -ne 3 -o -z "$1" -o -z "$2" -o -z "$3" ]
then
echo $0 $FUNCNAME Invalid parameters, exiting
exit 3
fi
sid="$1" ; shift
stime="$1" ; shift
etime="$1" ; shift
if [ $sid -gt 0 -a $sid -lt 10 ]
then
title=0$sid
else
title=$sid
fi
gnuplot <<- EOF
reset
set terminal png size 1800,900 enhanced font myfont.ttf 10
set xdata time
set timefmt "%Y-%m-%d %H:%M:%S"
set format x "%Y-%m-%d %H:%M"
set title "SID=$title from $stime to $etime"
set grid
set xrange [ "$stime" : "$etime" ]
set yrange [ -2000 : 6000 ]
set style data linespoints
plot "sid_data_$sid.txt" using 1:9 notitle
EOF
}
You can use rectangles to fill the space pretty easily:
set xdata time
set timefmt '%Y-%m-%d %H:%M:%S'
set object 1 rectangle from "2013-01-23 08:33:13",graph 0 to "2013-01-23 08:43:49",graph 1 fs solid fc rgb "red" behind
plot 'test.dat' u 1:3 w lines ls -1