Gnuplot gprintf() doesn't work anymore on new computer - gnuplot

I worte a script for gnuplot in my university and took the data to my computer at home.
Here is the relevant code:
set terminal postscript eps enhanced color font 'Helvetica,20';
set encoding utf8;
do for[i=2:12] for[j in "3 4 6"]{
set autoscale x;
set xr[-3:3];
set autoscale y;
set key right bottom;
set terminal postscript eps color ;
set termoption dash;
set xlabel "bla";
set ylabel "bla";
set output 'home/Plots/test-'.i.'-'.j.'.eps';
plot 'home/Daten/test-'.i.'-'.j.'.dat' with lines lw 4 title gprintf("homogen q=%.3f",(1/(j-1)-1/(10*(j-1)))/2); }
The gprintf() doesnt work..it only gives me 0.00 but at the computer in my uni it does it right...help anyone :(
edit:
I found out that gnuplot rounds...when i type in
gprintf("homogen q=%.3f",j)
it gives me q=3 for j=3.00
If i use:
gprintf("homogen q=%.3f",j/5)
it gives me q=0.00
it has to be a problem with gnuplot..because, as i said, on the other computer it worked :/

Answer
Use
... gprintf("homogen q=%.3f",(1.0/(j-1.0)-1.0/(10.0*(j-1.0)))/2.0)
The loop variables are integers by default and gnuplot is quite literal in its use of integer arithmetic, as you have already discovered...
Unrequested Advice
As a matter of style, I'd suggest to simplify the individual line's title to q = ... and use a descriptive plot title, e.g.,
Response curves for different values of the specific energy "q"

Related

gnuplot: viewing angle dependent colors with 3D circles in GIF terminal

With gnuplot 5.4 (Win7), I tried to animate circles in 3D, basically the animated version of this.
The test data $Data contains random x,y,z coordinates, random sizes and random colors from 0x0000000 to 0xffffff. When the animated GIF is created, the circles are changing the color depending on the viewing angle.
As far as I know, GIF is limited to 256 colors, so it is clear that not all colors from 0x0000000 to 0xffffff can be displayed.
I expected gnuplot to take somehow the nearest color and stick with it.
However, I didn't expect at all that the color of the circles would change depending on the angle.
Why is this? How to work around this?
Code:
### animated plot with circles in 3D (only for gnuplot >=5.4)
reset session
set term gif size 400,400 animate delay 30 optimize
set output "WithCircles3D.gif"
# create some test data
set print $Data
do for [i=1:100] {
print sprintf("%g %g %g %g %g", rand(0), rand(0), rand(0), rand(0)*0.02+0.02, int(rand(0)*0xffffff))
}
set print
set view equal xyz
set xyplane at 0
set border 4095
set xtics 0.2
set ytics 0.2
set ztics 0.2
set style fill solid 1.0
do for [a=5:360:10] {
set view 60,a,1.25
splot $Data u 1:2:3:4:5 w circles lc rgb var notitle
}
set output
### end of code
Result:
Result 2: (different random set when exporting single PNG frames with term pngcairo and put them together as animated GIF with some other software.)
I think the work-around is to not use the "optimize" option. It relies on upstream support (in libgd) that has been unreliable if not outright broken for years now. Probably we should deprecate the gnuplot option or remove it altogether.
The example you show works correctly if you remove that keyword, right?

Gnuplot interpretes locale decimal separator only in the first data line

My data file is
1,1
1,2
1,3
I try to plot it with the following script
set terminal pngcairo size 600,300 enhanced font "Calibri,18"
set output 'demo_err.png'
set xr [-1:3]
set yr [-1:+1]
#decimal separator in Russia is comma
set decimalsign locale "Russian_Russia.1251"
plot "demo_err.csv" u ($0):(0):(sprintf("%.1f", $1)) w labels,\
Gnuplot result
As you see, first label is OK, but in second and third label fraction is shown as 0. What am I doing wrong?
Gnuplot version is 5.2.6
In case you can't wait until the bug is fixed and #Ethan's stringcolumn(1) suggestion is not enough, because you "absolutely" need e.g. the format "%.3f", you can mimic sprintf("%.3f",x) with a formula. Well, with the drawback... it is not rounding the decimals.
### sprintf("%.nf",x) "replacement" with decimalsign locale ','
reset session
$Data <<EOD
1
-2,34567
123,45
5,6
7,8867
EOD
set locale "Russian_Russia.1251"
set decimalsign locale "Russian_Russia.1251"
f(s,n) = ((s).',0000000'[sgn(strstrt(s,','))+1:])[1:(strstrt(s,',')==0 ? strlen(s)+n+1 : strstrt(s,',')+n)]
set xrange[0.5:1.5]
set yrange[-0.5:5]
n = 3
plot $Data u (1):0:(f(stringcolumn(1),n)) w labels
### end of code
Result:
"set decimalsign" controls only the output, not the input.
Input is controlled by "set locale". I can't test this because I don't have your locale installed, but it should work to do
set locale "Russian_Russia.1251"
set decimalsign locale "Russian_Russia.1251"
plot "demo_err.csv" u ($0):(0):(sprintf("%.1f", $1)) w labels
[Edit] I have now reproduced the problem using a different locale. What is happening is that each time sprintf is called it sets the locale on entry and resets it to "C" on exit. If sprintf appears on a gnuplot command line this is exactly what you want to happen. But if it is called during evaluation of a 'using' specification this clobbers the state of the next data input read operation. A work-around for your simple test case is to avoid the use of sprintf in the 'using' spec:
plot "demo_err.csv" u ($0):(0):(stringcolumn(1)) w labels
I do not know if an equivalent work-around is possible for your full use case by avoiding sprintf inside the "using" clause of the plot command. Meanwhile I will file a bug report on the gnuplot issue tracker.

Saving gretl data in a .txt to plot with gnuplot causes problems due to scientific notation. How can I circumvent that? [duplicate]

I want to plot some stockpile data.
The data is located in a csv-file and I already got an almost accurate plot, so reading from file isn't the problem.
set terminal pdf
set output "gnuplot/".MATNUM."-2012.pdf"
set datafile separator ";"
stats 'Stock-2012.csv' every ::4::18 using MATNUM nooutput
set border 3
set tics nomirror
set xzeroaxis
set xrange[0:14]
set xtics 1,1,13
set xtics rotate 90
set ylabel MATUNIT
maxplot = sprintf("Amount max:\n%.2f ".MATUNIT, STATS_max)
plot 'Stock-2012.csv' every ::4::18 using ($0+1):MATNUM:xticlabels(2) with linespoints title "Amount", STATS_max with lines lc rgb 'blue' title maxplot
Where MATNUM and MATUNIT are commandline arguments, representing materialnumber (which is the columntitle in the datafile) and the unit in which the material is measured.
The x-values in my datafile are decimals, but gnuplot seems to cut off the fractional digits. For example 12,98 (commata are used as decimal separator, because it's a german stockpile) results in a datapoint at y=12.
I'm not sure but I think this happens only at the maximum and minimum y-value, as STATS_max is an integer every time.
What can I do to get my points at the right y-value?
Unfortunately you did not show any data from you file, but I guess you are using commas as decimal separators. In that case you need to set the right decimal sign for reading the input. You can use e.g.
set decimalsign locale
or use an explicit locale (this must be installed)
set decimalsign locale "de_DE.UTF-8"
Note, that setting an explicit character with set decimalsign ',' does not work because it usually affects only the output format of e.g. tics, but not the input behaviour.

gnuplot - USING string variables

I'm trying something very simple ...
#!/usr/bin/gnuplot
reset
filename = "something_or_other"
set terminal pngcairo dashed size 800,400 enhanced font 'Verdana,10'
set output filename.".png"
set title filename."\n"
set xlabel "probably time"
set ylabel "probably something else" offset graph 0.2,0.6 rotate by 0
plot filename.".dat" using 1:2 lc rgb "#00E80000" title "measurements"
!display filename.".png"
except filename stays just like that and doesn't get interpreted as a string.
How do I get this working?
The exlamation mark ! at the beginning of the line makes gnuplot send this whole line as it is to a shell. So, here you cannot use any gnuplot variables and string concatenation. For this you can use system():
system(sprintf("display %s.png", filename))

Gnuplot: how to get better symbol alpha in pdf terminal

Here is the test code:
set terminal pdf enhanced;
set output "test.pdf"
plot 1 title "{/Symbol a} {/Symbol b} {/Symbol c}";
That gives:
The alpha produced is very strange. I want a normal alpha like this:
Is there anyway I can do it?
Try copy-pasting in the unicode alpha character to your script, and adjust the font to whatever you like:
set terminal pdfcairo enhanced font "Arial,14"
set output "test.pdf"
set key font "Times,14"
plot -x title "α β γ"
The Symbol font is just another font, and the "strange" alpha is just how it looks in that font.

Resources