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.
Related
I have a histogram plot where the bars are simply too high that they overlap the box at the top right that displays information about each bar (what do you call this box?)
Currently it looks like this:
I'm been tring to change the size (height) of the canvas so that it is taller with set size but I couldn't get it to work. I then used yrange but I don't want to specify more range to solve this problem. I want it so that the inner canvas is more square and not rectangular (more height) without changing the range. How do I do this?
set term png
set output 'output.png'
red = "#FF0000";
green = "#00FF00";
blue = "#0000FF";
skyblue = "#87CEEB";
purple = "#4B0082";
set ylabel "Time (s)"
set xlabel "CPU"
set style data histogram
set style histogram cluster
set style fill solid
set boxwidth 0.9
set grid ytics
set xtics rotate
set title "Compiled with gcc/g++"
plot "processor.dat" using 2:xtic(1) title "-O1" linecolor rgb red, \
'' using 3 title "-O2" linecolor rgb blue, \
'' using 4 title "-O3" linecolor rgb green, \
'' using 5 title "-Os" linecolor rgb skyblue, \
'' using 6 title "-Ofast" linecolor rgb purple
The "box" is called "key". In the gnuplot command line, help set key explains its options. You can move it to the empty left upper corner with
set key left
To increase the height of the picture I would change the overall size of the png like this:
set terminal png size 640,640
On my system, your command set term png defaults to set terminal png size 640,480.
To make the plot area an exact square, the following command is used:
set size ratio 1
This is the result with some fake data:
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))
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"
I am trying to incorporate greek symbols into my graph using following code, but keep getting similar error twice.
warning: enhanced text mode parser - ignoring spurious }
warning: enhanced text mode parser - ignoring spurious }
reset
# svg
#set terminal svg size 410,250 fname "Times New Roman" \
set terminal svg size 410,250, enhanced fname 'Times New Roman' \
fsize "12" rounded dashed
set output "data1.svg"
set tics nomirror
# color definitions
set style line 1 lc rgb "#8b1a0e" pt 1 ps 1 lt 1 lw 2 # --- red
set style line 2 lc rgb "#5e9c36" pt 2 ps 1 lt 2 lw 2 # --- green
set key bottom right
plot "abc.htm" using 1:2 title "N('\alpha', T)" w lp ls 1, \
"abc.htm" using 1:3 title "N(\beta, T)" w lp ls 5
PS: The code was running fine until I enabled enhanced mode of svg terminal, as I needed it for inserting greek letters in my graph legends. I am using version 4.6, patch level 5. Can any one help me out?
The correct way is to
use enhanced option of the terminal (you did)
wite {/Symbol a} for an alpha.
Search for symbols + gnuplot on the web, you'll find lists like http://mathewpeet.org/lists/symbols/ with codes understood by gnuplot!
Use a proper encoding (UTF-8) and insert the characters directly:
reset
set encoding utf8
set terminal svg size 410,250 enhanced fname 'Times New Roman' fsize "12" rounded dashed standalone
set output "data1.svg"
set linetype 1 lc rgb "#8b1a0e" lw 2
set linetype 2 lc rgb "#5e9c36" lw 2
set key bottom right
set style function linespoints
set samples 11
plot x title "N(α, T)", 2*x title "N(β, T)"
choose font 'Symbol'
choose corresponding English alphabet for Greek letter, eg. i have chosen 'c' for 'chi', below is the link for other characters.
http://folk.uio.no/hpl/scripting/doc/gnuplot/Kawano/label-e.html
fontsize can be changed easily.
eg...
set ylabel "c" font "Symbol,14"
will produce greek letter 'Chi'.
I have found the way to solve this problem. The Greek letters can be inserted in SVG file using following path in the Inkscape:
Go to Text drop down menu and then click on Glyphs. Next, select font family such as Times New Roman. After that select Greek from script and all from Range options, respectively. Then Greek letters could easily be inserted in the Graph.
I am using the fontfile option to import a font in gnuplot. The font I selected is similar to a computer modern font, but I obtain a very different font.
Here is my code
reset
set term postscript enhanced eps fontfile "/usr/share/texmf/fonts/type1/public/lm/lmr8.pfb" "lmr8"
set output "comparison_inside_fields.eps"
set key spacing 1.5
normTemp=2*pi*750*1E+12
set xlabel "{/lmr8=20 t} ({/lmr8=18 s})"
set ylabel "Re({/lmr8=18 E}_{/lmr8=12 1}) ({/lmr8=18 V/m})" font "lmr8,17"
set logscale y
set yrange [50:1000]
set size 0.65
set tics front
set autoscale xfixmax
plot "Analytic_EField_linear_PW1000.dat" u ($1/normTemp):($2) w l lw 3.0 lc rgb "red" title "E_{1} equa-diff", "EField_linear_PW1000.txt" u ($1):($2) w l lw 3.0 lc rgb "blue" title "E_{1} CST", "exponential_linear.dat" u ($1/normTemp):($2) w l lt 2 lw 1.0 lc rgb "black" notitle`
and here is the image:
The font name is LMRoman8, and not lmr8. Use e.g. kfontview or head -1 .../lmr8.pfb to see the font name.
So a rather minimal example taken from your script would be:
reset
set term postscript enhanced eps fontfile "/usr/share/texmf/fonts/type1/public/lm/lmr8.pfb" "LMRoman8"
set output "comparison_inside_fields.eps"
set xlabel "{/LMRoman8=20 t} ({/LMRoman8=18 s})"
set ylabel "Re({/LMRoman8=18 E}_{/LMRoman8=12 1}) ({/LMRoman8=18 V/m})" font "LMRoman8,17"
plot x title "E_{1} equa-diff"
Result with 4.6.5 is:
The result is ok, but I would recommend you to use the epslatex terminal, which provides much nicer typesetting. Here an examplary document similar to yours:
basename = 'epslatex-test'
set terminal epslatex standalone header '\usepackage{lmodern}'
set output basename.'.tex'
set xlabel '$t$ (s)'
set ylabel 'Re$(E_1)$ (V/m)' offset 1
plot x
set output
system(sprintf('latex %s.tex && dvips %s.dvi && ps2pdf %s.ps && pdfcrop --margins 1 %s.pdf %s.pdf',\
basename, basename, basename, basename, basename))
Instead of using the header option you can also write all the packages and settings you want for all image into a file gnuplot.cfg, which will be included automatically, if available.