I have attempted to demonstrate a LaTeX formula with Gnuplot 5.0.
But I found that some LaTeX commands are unavailable.
This is my Gnuplot Code:
set termoption enhanced
set title "Title test^a \alpha $\alpha$" font "CMU-Serif, 18"
set xlabel "Month"
set ylabel "Precipitation (mm)"
set xrange [0.5: 12.5]
set xtics 1,1,12
set key
set pointintervalbox 2
plot "08_Data.dat" using 1:2 with linespoints \
linecolor "#FF7800" linewidth 2 pointtype 7 pointsize 0.75 pointinterval -1 \
title "Beijing",\
"08_Data.dat" using 1:3 with linespoints \
linecolor "#00A0DC" linewidth 2 pointtype 7 pointsize 0.75 pointinterval -1 \
title "Shanghai",
set output
pause (-1)
As a result, the LaTeX command test^a works well but the LaTeX \alpha and $\alpha$ don't work:
This is the file: 08_Data.dat :
1 2.5 38.1
2 5.1 58.4
3 10.2 81.3
4 25.4 101.6
5 27.9 114.3
6 71.1 152.4
7 175.3 129.5
8 182.9 132.1
9 48.3 154.9
10 17.8 61.0
11 5.1 50.8
12 2.5 35.6
set term tikz standalone size 7cm, 3cm fontscale 0.6
set ylabel '{\LaTeX\ -- $ \gamma $}'
set xlabel '{\LaTeX\ -- $ x $}'
set output 'example.tex'
plot [0:1] gamma(x) title '$ \gamma(x) $'
unset output
!pdflatex example
Have you tried to directly type in the alpha character in the gnuplot code? I guess gnuplot understands UTF-8.
set title "test^a α α" font "CMU-Serif, 18"
plot x
Result:
There are a few instructions to get vertical lines in gnuplot when plotting functions. Like using the set arrow function. I need this functionality for a histogram and it turns out the histogram has different position of 0.0 on X axis. In my case the X axis markers are just strings from the data file.
When plotting the histogram it would be so nice to have the mean, +-3sigma and maybe the X=0 point marked by vertical lines from top to bottom of the plot in fat colored solid lines.
My histogram code:
set boxwidth 1.0 absolute
set style line 1 lc rgb 'skyblue'
set style fill solid border lt -1
set style data histogram
set style histogram clustered gap 0.0
set xtics in rotate by 90 offset first +0.5,0 right
set xlabel
set ylabel 'Count'
set terminal unknown
plot 'histo.raw' using 3
set title 'data'
set yrange [0:GPVAL_DATA_Y_MAX*1.2]
set term X11
plot 'histo.raw' using 3:xtic(2) ls 1 title columnheader(1)
set arrow 1 from 0.0,0.0 to 0.0,GPVAL_DATA_Y_MAX*1.2 nohead
My data:
"data"
0 "-INF -> -5.0" 0 0.00
1 " -5.0 -> -4.5" 0 0.00
2 " -4.5 -> -4.0" 2 0.03
3 " -4.0 -> -3.5" 4 0.06
4 " -3.5 -> -3.0" 3 0.05
5 " -3.0 -> -2.5" 5 0.08
6 " -2.5 -> -2.0" 19 0.30
7 " -2.0 -> -1.5" 49 0.78
8 " -1.5 -> -1.0" 193 3.07
9 " -1.0 -> -0.5" 527 8.39
10 " -0.5 -> +0.0" 1289 20.53
11 " +0.0 -> +0.5" 1878 29.90
12 " +0.5 -> +1.0" 1411 22.47
13 " +1.0 -> +1.5" 636 10.13
14 " +1.5 -> +2.0" 178 2.83
15 " +2.0 -> +2.5" 56 0.89
16 " +2.5 -> +3.0" 17 0.27
17 " +3.0 -> +3.5" 9 0.14
18 " +3.5 -> +4.0" 4 0.06
19 " +4.0 -> +4.5" 0 0.00
20 " +4.5 -> +5.0" 0 0.00
21 " +5.0 -> +INF" 0 0.00
The set arrow function puts the line in the wrong spot.
set arrow 1 from 0.0,0.0 to 0.0,GPVAL_DATA_Y_MAX*1.2 nohead
In this data
mean= 0.2743
sigma= 0.7491
Thanks for your ideas.
Gert
I found that the histogram bars are defining their own X coordinates counting left to right. As I have 22 data rows for 22 histogram bars adding 11.0 to the line position does the job.
set boxwidth 1.0 absolute
set style line 1 lc rgb 'skyblue'
set style fill solid border lt -1
set style data histogram
set style histogram clustered gap 0.0
set xtics in rotate by 90 offset first +0.5,0 right
set xlabel
set ylabel 'Count'
set terminal unknown
plot 'histo.raw' using 3
set title 'data'
set yrange [0:GPVAL_DATA_Y_MAX*1.2]
set terminal png size 1200,800
set output 'histo.png'
mean= +0.2743
sdev= +0.7491
lboffs= 0.2
set arrow from 11.0 + mean,0.0 to 11.0 + mean ,GPVAL_DATA_Y_MAX*1.2 nohead lw 2 lc rgb "dark-green"
set arrow from 11.0 + mean - 3 * sdev,0.0 to 11.0 + mean - 3 * sdev ,GPVAL_DATA_Y_MAX*1.2 nohead lw 2 lc rgb "red"
set arrow from 11.0 + mean + 3 * sdev,0.0 to 11.0 + mean + 3 * sdev ,GPVAL_DATA_Y_MAX*1.2 nohead lw 2 lc rgb "red"
set arrow from 11.0,0.0 to 11.0,GPVAL_DATA_Y_MAX*1.2 nohead lw 2 lc rgb "blue"
set label "Mean" at 11.0 + mean + lboffs,GPVAL_DATA_Y_MAX*1.1 tc rgb "dark-green"
set label "+3%" at 11.0 + mean + 3 * sdev + lboffs,GPVAL_DATA_Y_MAX*1.1 tc rgb "red"
set label "-3%" at 11.0 + mean - 3 * sdev + lboffs,GPVAL_DATA_Y_MAX*1.1 tc rgb "red"
plot 'histo.raw' using 3:xtic(2) ls 1 title columnheader(1)
set output
set term X11
Given dataset:
0 t1 0.52
1 t2 0.66
2 t3 0.58
3 t4 0.57
4 t5 0.68
5 t6 0.61
6 t7 0.55
7 t8 0.52
8 t9 0.58
9 t10 0.50
10 t11 0.59
I cannot manage to get the colors of the bars to change. What I'm trying below is to color green the highest score which happens on line 4. Please have a look over the below:
set terminal postscript eps enhanced 20
set output "edscore2_joint.eps"
set style line 1 lc rgb "#5F9EA0"
set style line 2 lc rgb "#DC143C"
set style line 3 lc rgb "green"
set yrange [0:1]
set ylabel "ed_{score}"
set xlabel "Technique"
set style fill solid
set boxwidth 0.5
set xtics rotate by -45
plot "edscore2_joint.dat" using 1:3:xtic(2) with boxes ls 1 fillstyle pattern 1 notitle ,\
"edscore2_joint.dat" every ::4::4 using 1:3:xtic(2) with boxes ls 3 fillstyle pattern 2 notitle ,\
"edscore2_joint.dat" using 1:($3+0.05):3 with labels notitle
The terminal postscript is monochrome by default. Use either the option color, or, if you have a recent enough gnuplot version, use the terminal epscairo.
I have data:
0 315
0.159 284
0.321 246
0.47 202
0.631 164
0.786 136
0.958 102
1.104 74
1.307 42
1.461 17
1.524 10.9
1.6 4. 6
1.728 0
I have a code :
set xlabel "Zaporna napetost [V]"
set ylabel "Tok [pA]"
set yrange [-25:350]
set xrange [-0.1:1.8]
set xtics 0.3
set mytics 2
set mxtics 2
f(x)=k*x**2+n
fit f(x) 'D:\Petra\sola\praktikum\fotoefekt\365.txt' using 1:2 via k,n
plot 'D:\Petra\sola\praktikum\fotoefekt\365.txt' using 1:2 lc rgb 'black' t"UV" , \
f(x) lc rgb 'black' t""
And the fit i get is totaly of. Can anyone help.
Looks like you have experimental data. As you stated in your comments, you expect the have a linear dependency. You cannot change your physics and change the fitting function, just because it might look better.
In your case you could e.g. skip the points above 1.4, if you have a good reason (e.g. systematic errors), but use a linear fit:
f(x) = a*x + b
fit [0:1.4] f(x) '365.txt' via a,b
plot '365.txt' title 'experimental data', f(x) title sprintf('fit with %.2f·x + %.2f', a, b)
I have those data:
Length A B C D E F A_err B_err C_err D_err E_err F_err
17 0,51 1,4 0 0 0 0,07 0,11 0,33 0 0 0 0,08
18 1,33 2,49 1,88 0,51 1,21 0,2 0,18 0,43 1,05 0,5 0,5 0,14
19 2,56 3,83 3,75 0,76 4,22 0,81 0,25 0,53 1,47 0,61 0,92 0,28
20 8,28 7,22 3,44 5,46 5,16 9,19 0,44 0,72 1,41 1,59 1,02 0,89
21 29,96 20 15,78 16,65 13,66 62,58 0,74 1,11 2,82 2,6 1,58 1,49
22 34,16 42,3 56,25 31,51 37,14 16 0,76 1,37 3,84 3,25 2,22 1,13
23 14,23 16,59 17,03 29,86 21,28 1,55 0,56 1,03 2,91 3,2 1,88 0,38
24 6,98 4,39 1,72 12,58 9,6 9,54 0,41 0,57 1,01 2,32 1,35 0,9
25 1,23 1,02 0,16 1,65 4,55 0,05 0,18 0,28 0,31 0,89 0,96 0,07
26 0,45 0,44 0 0,89 1,76 0 0,11 0,18 0 0,66 0,6 0
27 0,18 0,1 0 0 1,04 0 0,07 0,09 0 0 0,47 0
With this code, I obtain a nice histogram with error bars:
set terminal pngcairo enhanced font "arial,15" fontscale 2.0 size 1600,900
set output 'length.png'
set style fill solid 0.7 border lt -1
set key inside right top vertical Right noreverse noenhanced autotitles columnhead nobox
set grid ytics
set nokey
set style histogram errorbars linewidth 1 gap 3 title offset character 0, 0, 0
set datafile missing '-'
set style data histograms
set xtics border in scale 1,0.5 nomirror offset character 0, 0, 0 autojustify
set xtics norangelimit font ",12"
set xtics ()
set xlabel "n"
set ylabel "Percentage (%)"
set title "length"
set bars 0.3 front
set datafile separator "\t"
set yrange [ 0 : * ] noreverse nowriteback
plot 'length.dat' using 2:8:xtic(1), '' u 3:9:xtic(1), '' u 4:10:xtic(1), '' u 5:11:xtic(1), '' u 6:12:xtic(1), '' u 7:13:xtic(1)
The obtained image is here: http://i.stack.imgur.com/s88QJ.png
But, some error bars just not appear. I notice that is because the error value is below 1. But why ? I'd like all error bars appearing. Is there a problem in the code that forbid errors below 1 to appear ?
Thanks for your help
To me, it looks like your problem is that you're using , as a decimal point character in your file instead of . that gnuplot understands natively. There are two possible solutions. The first I found from googling, but can't test:
set locale
or
set locale "ja_JP.UTF-8" #gnuplot complains this isn't available for me ...
or perhaps set decimalsign local "..."
The second solution is a little less elegant, but it involves converting all of your , to . in your datafile. That's a trivial thing to do using sed:
sed -e 's/,/\./g' length.dat > length2.dat
Now you can just plot using length2.dat and it should work OK (it did for me). As an aside, I think that's quite a nicely colorful plot. The pngcairo terminal does a good job with it.