I am plotting graphs in gnuplot (version 4.6 patchlevel 5) multiplot mode, which are being updated using reread.
set multiplot layout 3, 3
do for [planeIter=4:10:3] for [ringIter=0:20:10] {
plot for [quadIter=0:90:30] path/to/file \
using 1:(column(1 + planeIter + ringIter + quadIter)) notitle
}
pause 10
reread
Previously, I have outputted png files using:
set terminal pngcairo dashed enhanced
plot path/to/file using 1:2
set output 'foo.png'
But I haven't been able to find how to output a file of the latest multiplot screen. Please would you tell me how I could do this? Thank you.
As gnuplot will tell you:
you can't change the output in multiplot mode
So make sure you set it beforehand:
set terminal pngcairo dashed enhanced
set output 'foo.png'
set multiplot layout 3, 3
do for [planeIter=4:10:3] for [ringIter=0:20:10] {
plot for [quadIter=0:90:30] path/to/file \
using 1:(column(1 + planeIter + ringIter + quadIter)) notitle
}
unset multiplot
unset output
pause 10
reread
This is currently an infinite loop, so I assume that you are interrupting it manually. The unset lines will cause the output to be flushed, so your final image will be written.
Related
Such a simple question to have wasted an hour or two of my time. The Octave docs allude to setting the interpreter to tex and never say how to do it. I've looked on line and through stackoverflow and haven't found how to do this. I've also looked at the .octaverc files and have seen nothing that would indicate how to turn on the tex edit function. I am using Debian GNUOctave version 4.0.0. Please help.
Gary Roach
The interpreter property is set to "tex" per default for axes, line, text, patch and surface. So changing interpreter makes only sense if you want to switch to "none":
set (findobj (gcf, "-property", "interpreter"), "interpreter", "none")
This sets "interpreter"="none" for al children of the current figure.
If you want to have some fancy latex stuff in your plots and not only simple tex commands you can render it with latex:
close all
graphics_toolkit fltk
sombrero ();
title ("The sombrero function:")
fcn = "$z = \\frac{\\sin\\left(\\sqrt{x^2 + y^2}\\right)}{\\sqrt{x^2 + y^2}}$";
text (0.5, -10, 1.8, fcn, "fontsize", 20);
print -depslatexstandalone sombrero
## process generated files with pdflatex
system ("latex sombrero.tex");
## dvi to ps
system ("dvips sombrero.dvi");
## convert to png
system ("gs -dNOPAUSE -dBATCH -dSAFER -sDEVICE=png16m -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -r100x100 -dEPSCrop -sOutputFile=sombrero.png sombrero.ps")
which gives:
I'm using the Octave kernel in a Jupyter notebook. When I try to load a matrix from a file using the dlmread function, the whole data is printed. I tried assigning the result to a variable immediately, but no luck. This is troublesome because the matrix is quite large (~17*500) so it takes a while to print.
I just want to load my data without having all of it printed.
I guess you don't have a ; at the end of your dlmread command. See the manual:
Ending a command with a semicolon tells Octave not to print the result of the command
See this example:
>> a = 4 + 5
a = 9
>> b = 5 + 6;
>>
I am plotting graphs in gnuplot and would like to open them in full screen and a particular size.
Previously, I have been outputting graphs in multiplot mode and updating them using reread; so, when I maximise it manually, the plots fill the screen after a few iterations. Now, I also want to save the output as a file. When I open that file, it is in the same small size as the original multiplot output. However, when I maximise it, the plots don't increase in size to fill the screen. I have 2 questions:
How can I open the multiplot file in full screen?
How can I make the output file a particular size?
Here is my current gnuplot code (in a file called gnuplotCode):
set terminal pngcairo dashed enhanced
set output 'foo.png'
set multiplot layout 3, 3
plot for [iter=1:9] path/to/file using 1:(column(iter)) notitle
unset multiplot
unset output
pause 10
reread
I have tried to type the following:
gnuplot -geometry -3360-1050 gnuplotCode # where my screen size is 3360x1050
and:
resolution=$(xrandr | grep '*') && resolution=${resolution% *}
gnuplot -geometry $resolution gnuplotCode
but neither approach works. Please can you tell me how to open gnuplots in full screen and a particular size? Thank you.
You must distinguish between pixel-based terminals (pngcairo, png, canvas (...) and all interactive terminals wxt, x11, qt, windows, aqua, where the size is given in pixel. For vector-based terminals (postscript, svg, postscript etc) the size is given in inch or centimeters.
Using the -geometry flag works only for the x11 terminal:
gnuplot -geometry 800x800 -persist -e 'set terminal x11; plot x'
For all other pixel-based terminal you can use the size option to set the canvas size in pixel:
set terminal pngcairo size 800,800
Of course you can also extract the monitor resolution and use that as size. Here you have two variants:
Extract the monitor size on the shell:
monitorSize=$(xrandr | awk '/\*/{sub(/x/,",");print $1; exit}')
gnuplot -e "monitorSize='$monitorSize'; load 'gnuplotCode'"
The file gnuplotCode must then use the gnuplot variable monitorSize as follows:
set macros
set terminal pngcairo size #monitorSize
set output 'foo.png'
plot x
Note, that the content of the string variable monitorSize must be used as macro, i.e. the value is inserted before the whole line is evaluated.
If you don't want to have that additional line on the shell, you could also call the xrand stuff from within the gnuplot script via the system function. In that case the file gnuplotCode would look as follows:
monitorSize=system("xrandr | awk '/\*/{sub(/x/,\",\");print $1; exit}'")
set macros
set terminal pngcairo size #monitorSize
set output 'foobar.png'
plot x**2
which you must call only with gnuplot gnuplotCode.
Note, that the shell command as is always extracts the information of the first monitor only.
I have a csv file which has 5 entries on every row. Every entry is whether a network packet is triggered or not. The last entry in every row is the size of packet. Every row = time elapsed in ms.
e.g. row
1 , 0 , 1 , 2 , 117
How do I plot a graph for e.g. where x axis is the row number and y is the value for e.g. 1st entry in every row?
This should get you started:
set datafile separator ","
plot 'infile' using 0:1
You can also plot to a png file using gnuplot (which is free):
terminal commands
gnuplot> set title '<title>'
gnuplot> set ylabel '<yLabel>'
gnuplot> set xlabel '<xLabel>'
gnuplot> set grid
gnuplot> set term png
gnuplot> set output '<Output file name>.png'
gnuplot> plot '<fromfile.csv>'
note: you always need to give the right extension (.png here) at set output
Then it is also possible that the ouput is not lines, because your data is not continues. To fix this simply change the 'plot' line to:
plot '<Fromfile.csv>' with line lt -1 lw 2
More line editing options (dashes and line color ect.) at:
http://gnuplot.sourceforge.net/demo_canvas/dashcolor.html
gnuplot is available in most linux distros via the package manager (e.g. on an apt based distro, run apt-get install gnuplot)
gnuplot is available in windows via Cygwin
gnuplot is available on macOS via homebrew (run brew install gnuplot)
I have a CSV file and I am plotting the columns one by one in a do for[] loop. I would like to save the plot as a PNG file, with the filename coming from the columnheader. What is the best way to go about this where text.png is replaced by the ith column header?
#!/bin/bash
set datafile separator ","
set key autotitle columnhead
set xlabel "time/date"
nc = "`awk -F, 'NR == 1{ print NF; exit}' input.csv`"
set term png
do for [i = 2:5] {
set output "test.png"
plot 'HiveLongrun.csv' every::0 using i:xticlabels(1) with lines
}
As long as you're using awk, you could use it once more to get the header name from inside a gnuplot macro:
#!/usr/bin/env gnuplot
set datafile separator ","
set key autotitle columnhead
set xlabel "time/date"
nc = "`awk -F, 'NR == 1{ print NF; exit}' input.csv`"
# Define a macro which, when evaluated, assigns the ith column header
# to the variable 'head'
awkhead(i) = "head = \"\`awk -F, 'NR == 1 {print $".i."}' input.csv\`\""
set term png
do for [i = 2:5] {
eval awkhead(i) # evaluate the macro
set output head.".png" # use the 'head' variable assigned by the macro
plot 'HiveLongrun.csv' every::0 using i:xticlabels(1) with lines
}
There is almost certainly a cleaner way to do this with another awk-like utility, or even within gnuplot. Gnuplot offers a few ways to run arbitrary internal/external commands, as you can see from my mix of backtics and macro evaluation.
By the way, it is a little strange to me that you have the bash shebang (#!/bin/bash) at the start of the script if it will presumably be interpreted by gnuplot. I assume you call it as gnuplot myscript.plt. In this case the shebang is just a comment (as far as gnuplot is concerned) and doesn't do anything because gnuplot is the interpreter. In my example I use #!/usr/bin/env gnuplot and I run the script as an executable in bash, like ./myscript.plt. The shebang in this case tells bash to make gnuplot the interpreter (or whatever command you would get by typing gnuplot at the command prompt). Of course you could also set the shebang to be #!/usr/bin/gnuplot if you're not worried about the path changing.