Gnuplot line types - gnuplot

How do I draw different types of lines on gnuplot? I got to draw different colors. My script joins several files and I think it is why the lines are not dash. Only two of four are dashed.
Thanks
Felipe
#!/usr/bin/gnuplot
set grid
set title 'Estado dos arquivos no BTRIM com peers de comportamento condicionado'
set xlabel 'Tempo discreto'
set ylabel 'Quantidade de arquivos'
set style line 1 lc rgb '#0060ad' lt 1 lw 2 pi -1 ps 1.0
set style line 2 lc rgb '#dd181f' lt 9 lw 2 pi -1 ps 1.0
set style line 3 lc rgb '#29c524' lt 6 lw 2 pi -1 ps 1.0
set style line 4 lc rgb '#7D72F9' lt 7 lw 2 pi -1 ps 1.0
set style line 5 lc rgb '#000000' lt 8 lw 2 pi -1 ps 1.0
set termoption dashed
#set pointintervalbox 0
#set boxwidth 0.1
#set style fill solid
plot '<paste ../00/StatisticNormal.txt ../01/StatisticNormal.txt ../02/StatisticNormal.txt ../03/StatisticNormal.txt ../04/StatisticNormal.txt ../05/StatisticNormal.txt ../06/StatisticNormal.txt ../07/StatisticNormal.txt ../08/StatisticNormal.txt ../09/StatisticNormal.txt' smooth unique with line ls 1 title 'Normais', \
'<paste ../00/StatisticVogue.txt ../01/StatisticVogue.txt ../02/StatisticVogue.txt ../03/StatisticVogue.txt ../04/StatisticVogue.txt ../05/StatisticVogue.txt ../06/StatisticVogue.txt ../07/StatisticVogue.txt ../08/StatisticVogue.txt ../09/StatisticVogue.txt' smooth unique with line ls 2 title 'na Moda', \
'<paste ../00/StatisticPopular.txt ../01/StatisticPopular.txt ../02/StatisticPopular.txt ../03/StatisticPopular.txt ../04/StatisticPopular.txt ../05/StatisticPopular.txt ../06/StatisticPopular.txt ../07/StatisticPopular.txt ../08/StatisticPopular.txt ../09/StatisticPopular.txt' smooth unique with line ls 3 title 'Populares', \
'<paste ../00/StatisticRarity.txt ../01/StatisticRarity.txt ../02/StatisticRarity.txt ../03/StatisticRarity.txt ../04/StatisticRarity.txt ../05/StatisticRarity.txt ../06/StatisticRarity.txt ../07/StatisticRarity.txt ../08/StatisticRarity.txt ../09/StatisticRarity.txt' smooth unique with line ls 4 title 'Raros'
pause -1

Until version 4.6
The dash type of a linestyle is given by the linetype, which does also select the line color unless you explicitely set an other one with linecolor.
However, the support for dashed lines depends on the selected terminal:
Some terminals don't support dashed lines, like png (uses libgd)
Other terminals, like pngcairo, support dashed lines, but it is disables by default. To enable it, use set termoption dashed, or set terminal pngcairo dashed ....
The exact dash patterns differ between terminals. To see the defined linetype, use the test command:
Running
set terminal pngcairo dashed
set output 'test.png'
test
set output
gives:
whereas, the postscript terminal shows different dash patterns:
set terminal postscript eps color colortext
set output 'test.eps'
test
set output
Version 5.0
Starting with version 5.0 the following changes related to linetypes, dash patterns and line colors are introduced:
A new dashtype parameter was introduced:
To get the predefined dash patterns, use e.g.
plot x dashtype 2
You can also specify custom dash patterns like
plot x dashtype (3,5,10,5),\
2*x dashtype '.-_'
The terminal options dashed and solid are ignored. By default all lines are solid. To change them to dashed, use e.g.
set for [i=1:8] linetype i dashtype i
The default set of line colors was changed. You can select between three different color sets with set colorsequence default|podo|classic:

Related

Gnuplot - How to make multiple plots and save each one to different files with cairolatex

I need to make a 2d plot and a 3d plot, which I want to save as .tex files, respectively labo2-mag/latex/position-x-y-over-time.tex and labo2-mag/latex/position-3d.tex. Is there anything wrong with my script ?
# General settings
set tics font ", 14"
set tmargin at screen 0.7
set key at screen 0.3, 0.8 font ",14" spacing 1.3 samplen 0.8 box opaque
# set key outside font ",14" spacing 1.3 box opaque
# Send the border to the background
set border lw 0.1 back
set xlabel '$t$ [s?]' offset 1.7;
set ylabel '$Position$ [m?]' offset -1;
# Plot once 'in the air'
# set terminal unknown
plot "labo2-mag/data/output.out" using 1:2 with points pointtype 6 lc rgb "red" title '$x(t)$', \
"" using 1:3 with points pointtype 8 lc rgb "green" title '$y(t)$', \
"" using 1:4 with points pointtype 6 lc rgb "blue" title '$z(t)$'
# pause 70
# reread
set terminal cairolatex pdf size 10cm, 10cm
set out 'labo2-mag/latex/position-x-y-over-time.tex'
MAX_Y=GPVAL_Y_MAX
MIN_Y=GPVAL_Y_MIN
MAX_X=GPVAL_X_MAX
MIN_X=GPVAL_X_MIN
set xrange [MIN_X-(MAX_X-MIN_X)*0.1:MAX_X+(MAX_X-MIN_X)*0.01]
set yrange [MIN_Y-(MAX_Y-MIN_Y)*0.05:MAX_Y+(MAX_Y-MIN_Y)*0.05]
replot
# reset terminal
splot "labo2-mag/data/output.out" using 2:3:4 with points pointtype 6 lc rgb "red" title '$pos(t)$'
set terminal cairolatex pdf size 10cm, 10cm
set out 'labo2-mag/latex/position-3d.tex'
replot
Your splot command is issued while the first terminal is still active and writing to the first output file. You need to change the terminal and output before doing a new plot. The minimum would be to issue unset output after each of your replot statements.
You might want or need to also set a new intermediate terminal type together with the unset output. I don't understand the "in the air" comment in the script. Do you mean you don't actually want to plot it? You want to view it interactively before plotting to a file? Otherwise maybe set terminal dumb? If it is relevant, please clarify.

How to make a plot of positions with palette in Gnuplot?

How can I make a plot with some values of delta_x and delta_y positions; where I need to use palette (or colorbars) for each point showing their respective epochs (My current plot, and an example of the plot that I would like to make are shown below).
My current Gnuplot code is as follows:
set fontpath '/System/Library/Fonts'
set term post color enh eps font "Helvetica" 14
#Gnuplot script file for plotting data
#Set Line style
set style line 12 lw 1 ps 1 pt 8 # empty triangle
set style line 13 lw 1 ps 0.7 pt 81 #empty circle
#Add Legend
set key top right box
# set plot
set xrange[1.2:0]
set xlabel "Relative R.A. (mas)" # set xlabel
set mxtics 4
set xtics 0, 0.1, 1.2
set yrange[0:1]
set ylabel "Relative decl. (mas)"
set mytics 4
set ytics 0, 0.1, 1
plot "MOD1.dat" using 1:2 w points ls 13 lc rgb 'black' title "Data1", "MOD2.dat" using 1:2 w points ls 12 lc rgb 'gray' title "Data2"
Where my data are as follows:
Data1:
#Year RA(mas) DEC(mas)
1993-06-26 0.36315 0.23913
1993-12-16 0.33392 0.28443
1994-01-28 0.34606 0.30810
1994-12-23 0.37139 0.32989
1995-02-12 0.34050 0.29165
1995-08-17 0.55405 0.42913
1995-12-18 0.36928 0.2777
1996-04-07 0.49601 0.31533
1996-12-13 0.43557 0.34637
1997-11-14 0.36811 0.25562
1998-06-02 0.55603 0.36268
1998-12-07 0.52873 0.23110
2000-11-12 0.45839 0.22572
ieData2:
#Year RA(mas) DEC(mas)
1993-06-26 0.63633 0.44645
1993-09-18 0.63548 0.35586
1993-12-16 0.63161 0.41704
1994-01-28 0.27266 0.47256
1994-03-14 0.75819 0.65255
1994-04-21 0.69664 0.68481
1994-06-21 0.78735 0.72865
1994-08-29 0.91143 0.78274
1994-10-30 0.55326 0.43258
1994-12-23 0.67065 0.54423
1995-02-12 0.55778 0.51656
1995-08-17 1.01458 0.50502
Thank you.
try the palette linetype, like this:
plot 'MOD1.dat' u 2:3:1 w p pt 7 ps 2 lt palette

Insertion of Greek letters in a graph legend using GNUplot

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.

Displaying long labels in Gnuplot

I am currently working for a company where I have to evaluate a survey. Now do I have to make a plot of the data.
They want a table with the questions in the left column and a point in the right column with a distance to the question which symbolizes the average grade[0:4]. My first attempt is using gnuplot because I have used it before and now ran into the problem that if the length of the question(I already shortened them to a max. of 50 characters) is too long gnuplot is having problem displaying the plot correctly. The whole plot gets pushed to the right and you can't read it anymore.
My dataset looks like this
Eltern können sich über unsere Schule vielfä..., 2.2
Eltern werden über wichtige Entscheidungen inf..., 2.4
Eltern wissen über Projekte der Schule Bescheid, 2.4
Eltern erfahren Planung und Durchführung von F..., 1.5
Die Schule hat einen guten Ruf, 2.8
And here is my gnuplot file
set terminal pdfcairo enhanced font "Droid Sans,9" linewidth 4 rounded fontscale 1.0
set output "template.pdf"
set style line 80 lt rgb "#808080"
set border 3 back linestyle 80 #remove top and right border
set xtics nomirror
set ytics nomirror
set datafile sep ','
set xtics 0,1,4.
set ytics font ",4"
set xlabel "Note"
set style line 1 lc rgb "#0060AD" lt 1 lw 2 pt 7 pi -1 ps 1.0
set pointintervalbox 3
set xrange [0:4]
plot 'datafiles/adler_organisation.dat' using 2:0:ytic(1) notitle w lp ls 1
The result I currently get is
Here is an image how the rest of the evaluation looks like(made in LaTeX with datatool, loongtable and LTXtable).
Basically it is enough to fix the left margin with the command set lmargin at screen 0.5. Gnuplot isn't very good at estimating the margins based on the font type and font size. The result I get with this little change is:
Gnuplot cannot wrap long line automatically. You could use the epslatex terminal an put the labels in a \parbox with fixed length to achieve this, like with
label(s) = sprintf('\parbox{4cm}{\raggedleft %s}', s)
set ytics right
plot 'datafiles/adler_organisation.dat' using 2:0:ytic(label(strcol(1))) notitle w lp ls 1
But that would possibly give you problems getting the fonts. I haven't tried using epslatex together with Droid Sans.
As an other option you can use a python script to preprocess your datafile and insert line breaks. With the python script wraplabels.py:
from __future__ import print_function
import sys
import textwrap
with open(sys.argv[1], 'r') as f:
for line in f:
l, v = line.split(',')
print('"{}",{}'.format('\\n'.join(textwrap.wrap(l.strip(), 30)), v), end='')
and the gnuplot script
set terminal pdfcairo enhanced font "Droid Sans,9" linewidth 4 rounded fontscale 1.0
set output "template.pdf"
set style line 80 lt rgb "#808080"
set border 3 back linestyle 80 #remove top and right border
set tics nomirror
set datafile sep ','
set xtics 0,1,4.
set ytics font ",4" right
set xlabel "Note"
set style line 1 lc rgb "#0060AD" lt 1 lw 2 pt 7 pi -1 ps 1.0
set pointintervalbox 3
set xrange [0:4]
set lmargin at screen 0.3
plot '< python wraplabels.py datafiles/adler_organisation.dat' using 2:0:ytic(1) notitle w lp ls 1
you get a nice result

import font in Gnuplot: strange result

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.

Resources