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:
Related
I am trying to plot two data series plotted in one graph (histogram) using gnuplot. One is Baseline data and other one is Optimized. The script looks like this currently.
n=50
max=0.07946462
min=0.0
reset
width=(max-min)/n #interval width
hist(x,width)=width*floor(x/width)+width/2.0 #function used to map a value
to the intervals
set term png #output terminal and file
set output "histogram.png"
set xrange [min:max]
set yrange [0:]
set style fill solid 0.5 #fillstyle
set termopt enhanced # turn on enhanced text mode
set xlabel "PowerDensity(mA/um2)"
set ylabel "Area(um2)"
set title 'Power Density Histogram'
plot 'power_density_oxili_sptp.txt' u (hist($2,width)):($1) smooth frequency
w boxes lc rgb"blue" title 'Baseline', 'power_density_oxili_sptp.txt' u
(hist($3,width)):($1) smooth frequency w boxes lc rgb"red" title 'Optimized'
The output of this will be as given
enter image description here
The problem here, I am not able to see baseline data (blue) completely,since it is hiding below the optimized data.Either I need to see both data or I need to plot histogram separately in the same graph.
Br
Sree
It looks like you want the two histograms to be transparent. For that you should set the transparent flag in your fillstyle (see help fillstyple):
set style fill transparent solid 0.5
In addition, you need to specify truecolor to get transparent areas from the standard png terminal (see help png):
set term png truecolor
Alternatively you can use the pngcairo terminal.
Using gnuplot, how can I plot sin(x) in the x-z plane and sin(x) in the x-y plane, both at the same time? I'm guessing I need to use the set parametric command and the splot command, but I can't seem to work out the rest! Does anyone know how to do this? I'm trying to generate a plot which demonstrates the nature of an electromagnetic wave. Thanks.
Yes, parametric mode is a possibility. For example, splot u,0,sin(u), u,sin(u),0 will plot the two (!) parametric curves u,0,sin(u) and u,sin(u),0. The variable u is the parametric dummy variable, for a simple sine function we only need one of them, even in 3d mode.
It might look a bit nicer with the following settings, but this is of course my biased opinion, far from finished, and depends on your needs:
set terminal pngcairo
set output "emfield.png"
set yrange [-2:2]
set zrange [-2:2]
set parametric
umax = 6*pi
set urange [0:umax]
unset border
unset xtics
unset ytics
unset ztics
# Set zeroaxes
set xyplane at 0
set arrow from 0,0,0 to (umax*1.1),0,0 size screen 0.020,15,60 filled
set arrow from 0,1,0 to 0,-1,0 size screen 0.020,15,60 filled
set arrow from 0,0,-1.4 to 0,0,1.4 size screen 0.020,15,60 filled
splot u,0,sin(u) lc 6, u,sin(u),0 lc 7
The result looks like this:
I'm trying to use multiplot to stack two image plots on top of one another, in a column. When I try to test this with x11 terminal, the images are produced separately, only one visible at a time. When I use the epslatex terminal, which is what I want, then the text is drawn correctly within the LaTeX document, but the EPS portion of the plot is produced as two separate pages, resulting in a figure that is missing a lower half.
Here's the multiplot section of my script:
set multiplot 2,1
set cbrange [-0.4:0.4]
set cbtics -0.4,0.2,0.4
unset xlabel
set tmargin at screen 0.95
set bmargin at screen 0.60
plot data u 1:2:3 with image notitle
set cbrange [-0.1:0.1]
set cbtics -0.1,0.05,0.1
set xlabel "$x$"
set tmargin at screen 0.50
set bmargin at screen 0.15
plot data u 1:2:3 with image notitle
unset multiplot
unset output
What results in the document is this:
I have tried enlarging the vertical size of the plotting area(per this question), but what this does is increase size of each page in the EPS file. To be clear, the product of plotting with epslatex is an EPS file containing two pages, the first with the first plot at the position that I want (near the top), and the second with the second plot at the position that I want (near the bottom).
This normally happens when you are not in multiplot mode. For me, set multiplot 2,1 gives an error message "only valid in the context of an auto-layout command". The command set multiplot layout 2,1 works with Gnuplot 5.0 and 4.6.
As a side note: This behavior can be used to produce animated gifs with set terminal gif animate, each plot command creates a new frame.
I am making a video for my simulation, where each each frame is a picture of the simulation, and a graph. I'm making the graph with gnuplot, and I first run the simulation to determine the x and y ranges to use and then hardcode the range into the plot script. It works okay, but the plot does not use up the entire surface, there is a ton of white space, and the plot is only about 1/4 of the total area. Is there a way to make the plot expand closer to the edges of the boundary, or a way to control the plot placement?
Script:
set term postscript eps color enhanced "Helvetica" 36
set output 'image.eps'
set size ratio 0.8
set logscale x
set xlabel 'Time(Arb. Units)'
set xrange [10:100000]
set yrange [0:1.6]
set y2range [0:0.5]
set ylabel 'Absorption(%)'
set y2label 'Emission'
set format x '%.0e'
set xtics 10, 100, 100000
set key noautotitles
plot 'absorption.dat' axes x1y1 w lines lt 3 lw 5, 'emission.dat' axes x1y2 w lines lt 1 lw 5
Here is what comes out:
I set a grey background so you can see what space is being wasted.
Edit: I've also tried the png terminal, but that seems to make the problem even worse. The plot is shrunk even further. I replaced the top two lines of the script with:
set term png font Helvetica 36
set output 'image.png'
Then this is what comes out:
There are several things involved in the computation of the plot size:
Different terminals have different default canvas sizes. If the defaults don't fit your needs, change the size set terminal ... size ...
The canvas has a fixed aspect ratio (given by the terminals size settings) and you impose an additional constraint with set size ratio... which affects only the plot but not the canvas size. So, if you need this size ratio you must adapt the plot canvas to it.
A third parameter are the margins. Since gnuplot don't exactly know how the labels will be rendered by the terminal, the margins cannot be exact. You can set margins manually with set bmargin ... (for the bottom margin) and equivalently for the other margins.
I would suggest to use a terminal that accept the crop flag
e.g. png, gif, jpeg but also epscairo
I have a script that closes immediately after opening. I've tried pause -1, but then I have an empty window. I've also tried set output but apparently I can't do that with multiplot
Is there a way to set output while using multiplot?
I tried setting output before setting multiplot, but the ps file was blank
Edit: The solution I found most useful was "pause mouse". I was also told I could use set output and just do "plot file1, file2, file3", but I'm having some issues with the syntax for that.
I typically set the output (and terminal) before going in multiplot mode. One thing you may be noticing is that some terminals don't draw the plots in a multiplot until you unset multiplot (see help multiplot).
The following works.
set term post enh color
set output "foo.ps"
set multiplot layout 2,1
plot sin(x)
plot cos(x)
unset multiplot
One issue with multiplot is that often you want to see the plot (e.g. using x11) and also put it in a file (e.g. postscript). The cleanest way to do this is using the load command:
#foo.gp
set multiplot layout 2,1
plot sin(x)
plot cos(x)
unset multiplot
Now you can call this:
set term x11 persist
load "foo.gp"
set term post enh color
set output 'foo.ps'
load 'foo.gp'