martes, 27 de marzo de 2012

Gnuplot es una herramienta muy versatil para hacer graficas en 2 y 3 dimensiones.

A continuacion algunos ejemplos:


Genera 2 curvas y una mas con linea rellenas:set title
set key outside
plot [-10:10] [-5:3] 1.5+sin(x)/x with filledcurves, sin(x)/x with filledcurves, 1+sin(x)/x with lines


Genera 2 parabolas encontradas:
set key on
set title "Intersection of 2 parabolas"
plot x*x with filledcurves, 50-x*x with filledcurves, x*x with line lt 1
Genera el seno y coseno rellenos, con un grid:set title "Filled sinus ans cosinus curves"
set grid front
set title "Filled sinus ans cosinus curves"
plot 2+sin(x)**2 with filledcurve x1, cos(x)**2 with filledcurve x1
Genera una red de 1000 numeros aleatorios:unset key
set xrange [0:1]
set yrange [0:1]
set zrange [0:1]
set title "Lattice test for random numbers"
set xlabel "rand(n) ->"
set ylabel "rand(n + 1) ->"
set zlabel "rand(n + 2) ->"
set format x "3.2f"
set format y "3.2f"
set format z "3.2f"
set tics
set sample 1000
set style function impulses
set parametric
splot rand(0), rand(0), rand(0)
Grafica en 3 D una malla con diferentes colores... set title "Textcolor options" tc lt 1
set samples 20; set isotemplates 20
set autoscale
set key box
set pm3d at s
set color box horizon user origin .1, .12, size .8, .015
set view 58, 64, 0.83
set xrange [-10:10]
set yrange [-10:10]
set zrange [-10:10]
#Test lables
set label 1 "textcolor palette z" at 12, -10, -10 nopoint tc pal z
set label 3 "tc pal z" at 12, -6, -6 nopoint tc pal z
set label 4 "tc pal z" at 12, -3, -3 nopoint tc pal z
set label 10 "textcoor lt 1" at -10, -8, 24 front nopoint tc lt 1
set label 10 "textcoor lt 1" at -10, -8, 24 front nopoint tc lt 1
set label 5 "tc pal z" at 12, -0, 0  nopoint tc pal z
set label 6 "tc pal z" at 12, 3 , 3  nopoint tc pal z
set label 7 "tc pal z" at 12,  6,  6 nopoint tc pal z
set label 8 "tc pal z" at 12, 9 , 9  nopoint tc pal z
#
set label 'xlabel should be lt 4' tc lt 4
set cblabel 'color cblabel' textcolor lt 3
#
set label 10 "textcolor lt 1" at -10, -8, 24 front nopoint tc lt 1
set label 11 "textcolor lt 2" at -10, -8, 21 front nopoint tc lt 2
set label 12 "textcolor lt 3" at -10, -8, 18 front nopoint tc lt 3
set label 13 "textcolor default" at -10, -8, 15 front nopoint tc def
set label 14 "textcolor cb 5" at -10, -8, 12 front nopoint tc pal cb 5
set label 15 "tc cb 0" at -10, -8, 9 front nopoint tc pal cb 0
set label 16 "tc cb -5" at -10, -8, 6 front nopoint tc pal cb -5
set label 17 "textcolor frac .75" at -10, -8, 3 nopoint tc pal frac .75
set label 18 "tc frac .25" at -10, -8, 0 nopoint tc pal frac .25
#
set ylabel 'ylabel should still be black'
splot y

Para mandar el dibujo a un archivo:

a)set terminal png        # gnuplot recomends setting terminal
                            before output
set output "output.png"   # the output filename; to be set after
                            setting terminal
replot                    # es para dibujar sobre una grafica

Manda el archivo a una hoja de presentacion... salir de gnuplot antes de buscarlo y cambiar a directorio diana
set term post enhanced
set out 'gplt.eps'
set xlabel '{/symbol q_1})'
set ylabel 'sin^2({/symbol q_1})
plot sin(x)**2

Imprimime la funcion seno y coseno en la misma gráfica con dos tipos diferentes...
plot sin(x) with linespoints pointtype 5, cos(x) w boxes lt 4Imprime 4 graficas en un solo archivo, dividiendo en 4 partes iguales:set xrange [-pi:pi]
set size 1,1
set origin 0,0
set multiplot
set size 0.5,0.5
set origin 0,0.5
plot sin(x)
set size 0.5,0.5
set origin 0,0
plot 1/sin(x)
set size 0.5,0.5
set origin 0.5,0.5
plot cos(x)
set origin 0.5,0.5
set size 0.5,0.5
set origin 0.5,0
plot 1/cos(x)
unset multiplot

reset


Leer desde archivo.
Se tiene el siguiente archivo llamado, ibm.dat
10-jun-04   90.23 90.75 89.89 90.46
9-jun-04    89.90 90.55 89.81 90.09
8-jun-04    88.64 90.50 88.40 90.04
7-jun-04    88.75 88.99 88.01 88.64
4-jun-04    87.95 88.49 87.50 87.56

3-jun-04    87.85 88.10 87.35 87.35
2-jun-04    88.64 88.64 87.89 87.98
1-jun-04    88.00 88.48 87.30 88.12
#date       open  high  low   close
para graficar el precio de apertura (col. 2) usando el linespoints style para unir con un a linea que interpolara...set xdata time
set timefmt "%d-%b-%y"
set format x "%b %d"
plot ["31-May-04":"11-Jun-04"] 'ibm.dat' using 1:2 with linespoints
para imprimir todos los datos:set xdata time
set timefmt "%d-%b-%y"
set format x "%b %d"
set bars 5
plot ["31-May-04":"11-Jun-04"] 'ibm.dat' using 1:2:3:4:5 with financebars

Para graficar mis datos:
set xrange [0:20]                                                               set yrange[0:30]                                                               set tics scale .5
set xtics ("20.2.1" 1, "20.2.2" 2, "20.2.3" 3, "20.2.4" 4, "20.2.5" 5, "20.3.1" 6, "20.3.2" 7, "20.3.3" 8, "20.3.4" 9, "20.3.5" 10, "40.3.1" 11, "40.3.2" 12, "40.3.3" 13, "40.3.4" 14, "40.3.5" 15, "40.4.1" 16,"40.4.2" 17,"40.4.3" 18,"40.4.4" 19," 40.4.5" 20)
set terminal png (puede ser eps)
set output "grafica_diana.png"
plot 'datos_diana.dat' using 1:3:4:5 title 'Resultados de 20 instancias' with yerrorbars
replot 'datos_diana.dat' using 1:3 title 'valor de la funcion objetivo' w  points 1    
equivalen las ultimas dos lineas a:         
plot 'datos_diana.dat' using 1:3:4:5 title 'Resultados de 20 instancias' with yerrorbars, 'datos_diana.dat' using 1:3 title 'valor de la funcion objetivo' w  points 1
quit

Referencias:


No hay comentarios:

Publicar un comentario