I am a bit confused, I have the same gnuplot script that works under
Version 4.6 patchlevel 4 Build System: Linux x86_64
but not under
Version 4.6 patchlevel 5 Build System: MS-Windows 32 bit
the script file is
clear
set terminal epslatex size 20cm,14cm
set output 'mwe.tex'
set style data points
set style line 101 lc rgb "black" lw 2 pt 1 ps 2
set grid
set xlabel 'xlabel'
set ylabel 'ylabel'
xmin= -0.2
xmax= 0.7
set xrange [xmin:xmax]
set key below
plot "<echo '0.408 270.7'" with points ls 101 notitle,\
Does the command "<echo somehow not work under Windows?
The error I get with Windows is 'skipping unreadable file "
The < pipes the following command through a shell (see help special-filenames). The command itself is mostly system-dependent and not part of gnuplot (in this case the echo).
If you want a portable way to specify a single point, you can set an empty label and use the point option:
set style line 101 lc rgb "black" lw 2 pt 1 ps 2
set label at 0.408, 270.7 "" point ls 101
Note, that this works only if you also plot other stuff, since the label is set only if the plot command is invoked.
echo (lower case) is a unix command. In windows you will need to use "<ECHO in uppercase.
Related
I am using gracebat integrated into my bash script to make simple XY graph from 2D numerical data
gracebat input.xvg -hdevice PNG -fixed 800 600 -world 0 0.02 610 0.5 -printfile output.png -hardcopy
This simple execution without GUI produces the XY graph totally in black color!
would it be possible to quickly change to color of the line (I guess should be s0 color in the batch file) without using batch file for gracebat: e.g. via some option of gracebat or alternatively via editing of the input.xvg (via sed or any shell utility) specifying color or the line:
# s0 line color 2
Alternatively, if the grace has not good possibilities for graph customization, I would be grateful for simple example of the gnuplot batch execution.
What does xmgrace -help say? Please check the corresponding manuals and homepages and do a search on SO and the web before asking such questions. I don't now xmgrace and its documentation.
But a gnuplot command line would be using the command line option -e: (check help command line options).
gnuplot -e "set term pngcairo size 800,600; set output 'myFile.png'; plot 'myFile.dat' u 1:2 w l lc 'red' "
I've got this code in an Emacs orgmode file:
#+begin_src gnuplot :exports results :file images/sinecosine.png
reset
set terminal png size 360, 360 enhanced
# Line styles
set border linewidth 1
set style line 1 linecolor rgb '#0060ad' linetype 1 linewidth 1 # blue
set style line 2 linecolor rgb '#dd181f' linetype 1 linewidth 1 # red
# Legend
set key at 6.1,1.3
# Axes label
set xlabel 'x'
set ylabel 'y'
set xzeroaxis linetype 2 linewidth 1
set yzeroaxis linetype 2 linewidth 1
# Axis ranges
set xrange[-2*pi:2*pi]
set yrange[-1.5:1.5]
# Axis labels
set xtics ("-2{/Symbol P}" -2*pi, "-{/Symbol P}" -pi, 0, "{/Symbol P}" pi, "2{/Symbol P}" 2*pi)
set ytics 1
set tics scale 0.75
# Functions to plot
a = 0.9
f(x) = a * sin(x)
g(x) = a * cos(x)
# Plot
plot f(x) title 'sin(x)' with lines ls 1, \
g(x) notitle with lines ls 2
#+end_src
and it gives a gnuplot (3.7) without the proper pi symbol -- just like in this and this post. Yes, I can get the eps version of this to work, but not this png (or svg) version, which is needed for HTML export. Any new ideas?
Update
Here is the stand-alone code I've tried -- successfully:
reset
set encoding utf8
set terminal svg enhanced fname 'Times New Roman' rounded dashed standalone
set output "gp-test4-output.svg"
# Line styles
set border linewidth 1
set style line 1 linecolor rgb '#0060ad' linetype 1 linewidth 1 # blue
set style line 2 linecolor rgb '#dd181f' linetype 1 linewidth 1 # red
# Legend
set key at 6.1,1.3
# Axes label
set xlabel 'x'
set ylabel 'y'
set xzeroaxis linetype 2 linewidth 1
set yzeroaxis linetype 2 linewidth 1
# Axis ranges
set xrange[-2*pi:2*pi]
set yrange[-1.5:1.5]
# Axis labels
set xtics ("-2Π" -2*pi, "-Π" -pi, 0, "Π" pi, "2Π" 2*pi)
set ytics 1
set tics scale 0.75
# Functions to plot
a = 0.9
f(x) = a * sin(x)
g(x) = a * cos(x)
# Plot
plot f(x) title 'sin(x)' with lines ls 1, \
g(x) notitle with lines ls 2
I've swapped out the {/Symbol P} for Π. From a terminal command line I've gotten it to work and produce just fine. The Ubuntu repo did install the latest-greatest gnuplot (gnuplot 5.2 patchlevel 6). So doing the experiment again, when I C-c C-c in the org-mode codeblock I get
gnuplot-mode 0.7-beta (gnuplot 3.7) -- report bugs with "C-c C-u"
and the same error: junk instead of Π. (Not sure what the gnuplot 3.7 is about.) Running the codeblock above, BTW, starts a gnuplot REPL, and it says it's latest-greatest gnuplot. But when the stand-alone code above in Emacs (with gnuplot-mode) is called a la "send buffer to gnuplot" (the Emacs gnuplot REPL) it gives the error, BUT when I "send file to gnuplot", it produces the Π error-free. Totally bizarre, IMHO.
Here's my subscriptions:
(setq package-archives '(("ELPA" . "http://tromey.com/elpa/")
("gnu" . "http://elpa.gnu.org/packages/")
("melpa" . "https://melpa.org/packages/")
("org" . "https://orgmode.org/elpa/")))
which gives two offerings for gnuplot modes:
gnuplot 20141231.2137 available melpa drive gnuplot from within emacs
and then this:
gnuplot-mode 20171013.1616 installed Major mode for editing gnuplot scripts
So then I uninstalled Emacs gnuplot (20141231.2137), then installed gnuplot-mode(20171013.1616). This solved the gnuplot-run-buffer problem, but the org-mode codeblock now gives this error:
executing Gnuplot code block...
org-babel-execute:gnuplot: Cannot open load file: No such file or directory, gnuplot
Searching customize I only find four variables associated with gnuplot, one being Gnuplot Program, which I have as /usr/bin/gnuplot. I'm on latest-greatest Emacs and org-mode in Ubuntu 19.04. How do I better tell org-babel where to find Gnuplot? I suspect this newer mode is not the intended partner for Emacs org-mode; however the older mode is not doing greek letters properly in org-mode.
Retrieving the character "pi" from the Adobe Symbol font is something from the PostScript world, where separate fonts with special encodings were used to work around the 256-character limit inherent in PostScript font encodings.
SVG, on the other hand, is an XML variant. It uses unicode entry points and (usually) UTF-8 encoding to access them. "pi" in an SVG file is either the byte sequence 0xCF 0x80 (UTF-8 encoding) or the XML predefined entity π .
gnuplot's "enhanced text" mode is not relevant here. I do not remember what limitations there might have been in gnuplot 3.7 that would affect passing either of these as normal text to the svg terminal. There are no such limitations in current gnuplot.
For the format of x-axis, current I am using the following command in pngcairo terminal:
set format x "%.sK"
Which recognizes numbers from 100K to 900K but when it gets to 1 million it prints "1K" instead of "1000K".
what is the command to automatically set the label to "xK" before 1 million and to "xM" after 1 million?
These kind of labels are controlled by gnuplot's own format specifiers (see doc for gprintf):
set format x '%.s%c'
When I try to write a shell script such as
gnuplot
cd '/home/cagirici/test'
plot "case1.test" with linespoints
and run it in sudo, the script stops after running gnuplot.
In each .test file, I have 12 columns. I won't plot them all at once but choose what to plot. For instance, if I choose to plot the success percentage, it should plot 1:2 and 1:8. But if I choose error percentage, it should plot 1:4 and 1:10 (it is basically i:(i+6).)
I need to write a scripts that takes two inputs: i) file name ii) what to plot.
Notice that I also want to choose the line type, point type and output shell. (if there is a configuration to set specific line and point types as default values, please tell me this as well)
Can I write this script in Ubuntu? Or should I use a different method.
My script would look something like
case "$2" in
("success percentage") plot "$1" using 1:2, plot "$1" using 1:8
("error percentage") plot "$1" using 1:4, plot "$1" using 1:10
You can make this work by creating a Gnuplot script with variables and then passing values to these variables at run time from command line or your bash script.
Lets call the Gnuplot script Myscript.gp:
set terminal pngcairo
set output 'graph.png'
plot file u x:y w linespoints
Here file and x:y can be varried when you invoke Gnuplot from your bash script. A possible call to Myscript.gp is as follows:
gnuplot -e "x=1;y=2;file = \"mydata.dat\"" Myscript.gp
In the snippet of your bash script that you provide this may look like:
case "$2" in
("success percentage") gnuplot -e "x=1; y=2; file = \"$1\"" Myscript.gp
Below I'm also providing a dummy mydata.dat file which you can use to try things.
1.54 23.66 43.66
1.75 26.25 46.25
1.92 30.20 40.20
2.08 34.46 44.46
2.44 42.08 42.08
2.78 46.81 46.81
3.03 51.10 41.10
3.70 52.99 42.99
4.17 56.15 46.15
4.76 59.34 49.34
If you are calculating the column numbers (x and y) in your bash script then you can also use variables inside the plot command.
gnuplot -e "x=$x;y=$y;file = \"mydata.dat\"" Myscript.gp
Below I show the output once using:
gnuplot -e "x=1;y=2;file = \"mydata.dat\"" Myscript.gp
and once
gnuplot -e "x=1;y=3;file = \"mydata.dat\"" Myscript.gp
I had faced similar problem 2 years back, then my senior team members decided to write a tool for plotting graphs using a simple csv and plotting specifications and tool will plot graphs for you,
Initially it was designed for sar data on linux so named RSAR but in general it is a csv plotter.)
if required you can contact me nachiket.kate90#gmail.com
I'm trying to plot the 1st and 3rd columns of multiple files, where each file is supposed to be plotted to an own output.png.
My files have the following names:
VIB2--135--398.6241
VIB2--136--408.3192
VIB2--137--411.3725
...
The first number in the file name is an integer, which ranges from 135-162. The second number is just a decimal number and there is no regular spacing between the values.
Basically I want to do something like this
plot for [a=135:162] 'VIB2--'.a.'--*' u 1:3 w l
although this doesn't work, of course, since the ' * ' is just the placeholder I know from bash and I don't know, if there is something similar in gnuplot.
Furthermore, each of the files should be, as already said above, plotted to its own output.png, where the two numbers should be in the output name, e.g. VIB2--135--398.6241.png.
I tried to come up with a bash script for this, like (edited):
#!/bin/bash
for file in *
do
gnuplot < $file
set xtics 1
set xtics rotate
set terminal png size 1920,1080 enhanced
set output $file.png
plot "$file" u 1:3 w l
done
but I still get
gnuplot> 1 14 -0.05
^
line 0: invalid command
gnuplot> 2 14 0.01
^
line 0: invalid command
...
which are actually the numbers from my input file. So gnuplot thinks, that the numbers I want to plot are commands... ?? Also, when the end of the file is reached, I get the following error message
#PLOT 1
plot: an unrecognized command `0x20' was encountered in the input
plot: the input file `VIB2--162--496.0271' could not be parsed
I've seen a few questions similar to mine, but the solutions didn't really work for me and I cannot add a comment, since I do not have the reputation.
Please help me with this.
gnuplot < $file starts gnuplot and feeds it the content of $file as input. That means gnuplot will now try to execute the commands in the data file which doesn't work.
What you want is a "here document":
gnuplot <<EOF
set xtics 1
set xtics rotate
set terminal png size 1920,1080 enhanced
set output $file.png
plot "$file" u 1:3 w l
EOF
What this does is: The shell reads the text up to the line with solemn EOF, replaces all variables, puts that into a temporary file and then starts gnuplot feeding it the temporary file as input.
Be careful that the file names don't contain spaces, or set output $file.png will not work. To be safe, you should probably use set output "$file.png" but my gnuplot is a bit rusty.