I am using the following script to generate a simple eps image:
set terminal epslatex 8
set output 'sample1.tex'
set size 0.75,0.75
set xrange [-pi:pi]
set yrange [0:1.2]
set xlabel "$x$"
set ylabel "$y$"
plot sin(x)*sin(x) title "$\\sin^2(x)$"
However, when I run it in gnuplot
gnuplot> load "sample.gpi"
I got a blank image, just the grids without numbers are shown.
Any suggestion what I'm doing wrong?
You are probably viewing the sample1-inc.eps file. But you must compile the output LaTeX-file first. For this it is very convenient to use the standalone option and compile from within the script itself:
set terminal epslatex 8 standalone
set output 'sample1.tex'
set size 0.75,0.75
set xrange [-pi:pi]
set yrange [0:1.2]
set xlabel "$x$"
set ylabel "$y$"
plot sin(x)*sin(x) title "$\\sin^2(x)$"
set output # finish the current output file
system('latex sample1.tex && dvips sample1.dvi && ps2pdf sample1.ps')
Now you can load 'sample1.gpi' and view the complete output as sample1.ps or sample1.pdf. If you are on Windows you may need to compile with three separate system calls (just guessing):
system('latex sample1.tex')
system('dvips sample1.dvi')
system('ps2pdf sample1.ps')
Related
I use gnuplot 5.4.5 for processing the following script:
set key enhanced font "Monospaced,13"
set grid
set style line 1 \
linecolor rgb '#a82828' \
linetype 1 linewidth 3 \
pointtype 5 pointsize 1.0
set xlabel "Entropy"
set xrange [-0.05:1.05]
set ylabel "Amortized work"
set terminal png enhanced font "Monospaced,13" size 500,350
set output 'EntropyToAmortizedWork.png'
plot 'EntropyToAmortizedWork.dat' with linespoints linestyle 1 notitle
replot
exit
The file EntropyToAmortizedWork.dat lives here.
All in all, I get:
Clearly, we have a typesetting artifact. How could I deal with it?
I can reproduce this on Win10 with gnuplot 5.4.5 and terminal png, but not with gnuplot 5.4.4.
Even terminal pngcairo seems to have a problem with 5.4.5, check the missing horizontal lines on some xticlabels.
So, suggested solution would be to go back to gnuplot 5.4.4 or earlier versions.
This would be a minimal script (no need for data).
Script:
### wrong ylabel with 5.4.5 and png terminal
reset session
set ylabel "This is the y-label"
set term png size 640,384
set output "SO74179232_png.png"
plot x
set term pngcairo size 640,384
set output "SO74179232_pngcairo.png"
plot x
set output
### end of script
Results:
gnuplot 5.4.5, terminal png
gnuplot 5.4.5, terminal pngcairo
gnuplot 5.4.4, terminal png
gnuplot 5.4.4, terminal pngcairo
I am working on a Windows 7 machine using gnuplot 5 Patch level 1.
I am preparing an animation of the sequence of interatomic distances along a trajectory from a molecular dynamics calculation.
The following script works fine:
set termopt enhanced # turn on enhanced text mode
# --- GRAPH a
set yrange [0.0:25.0]
set xlabel 't (fs)'
set ylabel "R_{ij} (A)"
set key box opaque
stats 'NeH2+_125K_TRAY171.DAT'
do for [i=1:STATS_records:2001] {
plot 'NeH2+_125K_TRAY171.DAT' using ($1/10):2 every ::1::i with lines title 'R_{NeH_{1}}', \
'NeH2+_125K_TRAY171.DAT' using ($1/10):3 every ::1::i with lines title 'R_{H_{1}H_{2}}',\
'NeH2+_125K_TRAY171.DAT' using ($1/10):4 every ::1::i with lines title 'R_{NeH_{2}}',
}
end of script
However the x-range is updated during the simulation and can be quite distracting since the data file is quite long.
To avoid updating the x-axis, I tried using the set xrange command
set xrange[0.0:7.0]
set yrange [0.0:25.0]
set xlabel 't (fs)'
...
When the animation starts, it works correctly but after plotting a few thousand data, it stops. Furthermore, there are no error messages in the console window of the aplication.
I have tested both scripts on a second windows 7 computer with gnuplot 5.2 and did observe the same behaviours.
Apparently the scripts are correct. Can anybody identify the problem?.
Thanks in advance.
Note, that the set yrange also applies to the stats call (yes, the yrange, because you don't specify any column).
So in any case you might have less plot iterations than you expect. Try
reset
f = 'NeH2+_125K_TRAY171.DAT'
stats f
set xrange [0.0:7.0]
set yrange [0.0:25.0]
do for [i=1:STATS_records:2001] {
plot f using ($1/10):2 every ::1::i title 'R_{NeH_{1}}', \
'' using ($1/10):3 every ::1::i title 'R_{H_{1}H_{2}}',\
'' using ($1/10):4 every ::1::i title 'R_{NeH_{2}}'
}
I need to write one of my axis label as $\langle\alpha\rangle$. I don't know how to get this Dirac notation in gnuplot. Can someone help.
One solution might be to use Gnuplot as a "pre-processing" tool in order to generate a template which is then compiled with LaTeX. To this end, consider for example following Gnuplot script:
set terminal lua tikz size 8cm,6cm clip background rgb '#ffffff'
set output 'frame.tex'
set xr [0:10]
set yr [0:10]
set xtics out nomirror
set ytics out nomirror
set key bottom right reverse spacing 2 width 2
set xlabel '$\langle\alpha\rangle$'
set ylabel '$f(\langle\alpha\rangle)$'
plot x t '$f(\langle\alpha\rangle)$'
When supplied to Gnuplot, it produces a file frame.tex. However, this is not a standalone LaTeX document, just the plot itself rendered with the famous TikZ package. Nevertheless, it is rather straightforward to embed it in a document as:
\documentclass[aip,jcp,reprint,amsmath,12pt]{revtex4-1}
\usepackage[utf8]{inputenc}
\usepackage[margin=0pt,papersize={8cm,6cm},headheight=0pt]{geometry}
\usepackage{graphicx}
\usepackage{tikz, fp, scalefnt, ifthen}
\usepackage{gnuplot-lua-tikz}
\usepgflibrary{fixedpointarithmetic}
\pagestyle{empty}
\setlength{\fboxsep}{0pt}
\setlength{\parskip}{0pt}
\setlength{\parindent}{0pt}
\begin{document}
\begin{widetext}
\input{frame.tex}%
\end{widetext}
\end{document}
If this file is called for example figure.tex, then pdflatex figure.tex produces:
Using a flow where I do a 'scratch' plot first to then gather the 'GPVAL_DATA_Y_MIN / MAX' variables for framing the plot size. I then send the actual plot into PNG file. Still the 'scratch' plot command flashes up on screen which I want to avoid. I was doing a 'help set terminal' to see the available terminals (in my gnuplot session) and was looking for something like 'blind' or 'null' but couldn't find any like that. Is there such a terminal? And what is it's name? (Using gnuplot 4.6 patchlevel 7)
Thanks,
Gert
Since I don't know exactly, how you actually use those values, here are some different possibilities:
Gnuplot's "blind" terminal is called unknown:
set terminal unknown
plot "data.dat"
set terminal pngcairo
set output "output.png"
set yrange[GPVAL_DATA_Y_MIN:GPVAL_DATA_Y_MAX]
replot
Variants of this would be to wrap the set terminal unknown call in set terminal push and set terminal pop to go back to the previous terminal.
Use the stats command:
f = "data.dat"
stats f using 2 nooutput
set yrange [STATS_min:STATS_max]
plot f
If you don't need the values for computations, but only to fit the yrange to your actual data range, then use
set autoscale yfix
or
set autoscale yfixmax
possibly combined with set offsets.
Try to send the output to the null device:
On Linux:
set terminal png
set output "/dev/null"
plot sin(x)
set output "real_output.png"
...
On Windows:
terminal png
set output "nul"
plot sin(x)
set output "real_output.png"
...
Read this SO question or this Wikipedia entry, especially for Windows details.
im running gnuplot 4.6.5 on top of ubuntu 12.04 and use the x11 terminal. I use the script as follows but the ylabel is not visible (xlabel is fine). What i have to do to fix it? offset?
thanks for help
plot "512bytesCBR3000client4server1numofnodes.txt" using 1:2 title 'NativeOF' with linespoints lw 2 ps 3 pt 6 lt 3
set grid
set ylabel "End to end delay"
set xlabel "number of nodes"
Normally, you have to do all the settings (set xlabel, set ylabel, set grid) before you call plot if you want them them to show up in the plot. I am not sure why set xlabel is working for you unless you set it in a previous plot or while trying commands from the gnuplot command line.
Try moving the plot command to the end of the file.
Sometimes, this might be related to the margins of the canvas. Therefore, might be wise to play with the margin settings, for example:
# other grid settings
set lmargin 10
set rmargin 10
set tmargin 5
set bmargin 5
# plot command