sesión 2 - graficas daniel bernal
TRANSCRIPT
-
5/21/2018 Sesin 2 - Graficas Daniel Bernal
1/29
Sesion 2Grficas enMATLAB
Ing. Daniel Bernal
-
5/21/2018 Sesin 2 - Graficas Daniel Bernal
2/29
Componentes de una grafica
2
Universidad Industrial de SantanderCurso Bsico de MATLAB
-
5/21/2018 Sesin 2 - Graficas Daniel Bernal
3/29
Edicin de los parmetros Ttulo: title(el ttulo de la grfica)
Ttulo eje x: xlabel(ttulo del eje x)
Ttulo eje y: ylabel(ttulo del eje y)
Leyendas: legend(nombre de la curva1,nombre de la curva 2)
Ejes: axis [Xmin Xmax Ymin Ymax] o axissquare.
Texto en la figura text(x,y,texto)
Universidad Industrial de Santander CursoBsico de MATLAB
3
-
5/21/2018 Sesin 2 - Graficas Daniel Bernal
4/29
Grficas 2Dplot (valores eje x, valores eje y)
Universidad Industrial de Santander CursoBsico de MATLAB
4
-
5/21/2018 Sesin 2 - Graficas Daniel Bernal
5/29
GRFICAS DE DATOS
Universidad Industrial de SantanderCurso Bsico de MATLAB
5
x=-3:0.01:3;y=x.*exp(-x.^2);plot(x,y)title('y=x*exp(-x^2)')
xlabel('x')ylabel('y')text(-0.4,-0.4, Valor Minimo)
title('\alpha \beta \gamma)title(x^{2})http://www.mathworks.com/help/symbolic/mupad_ug/typeset-symbols-available-in-mupad.html
Titulos y otros textos
-
5/21/2018 Sesin 2 - Graficas Daniel Bernal
6/29
Plot (valores eje x, valores eje y, color,estilo,marcador)
Universidad Industrial de Santander CursoBsico de MATLAB
6
Especificadores de lnea
c cyan - lnea continua . Puntos
m magenta -- lnea a trazos o Crculos
y yellow : lnea a puntos x Marcas en x
r red -. lnea a barra - punto + Marcas en +g green * Marcas en *
b blue s Cuadrados
w white d Diamantes
k black ^ Tringulo hacia arriba
v Tringulo hacia abajo
> Tring. hacia la derecha< Tring. hacia la izq.
p Estrella de 5 puntas
h Estrella de 6 puntas
COLORES ESTILO DE LNEA MARCADORES
-
5/21/2018 Sesin 2 - Graficas Daniel Bernal
7/29
Ejemplos x=linspace(0,2*pi,100);
y=cos(x);
figure,plot(x,y, 'r'); figure,plot(x,y, ':');
figure,plot(x,y, 'r:');
figure,plot(x,y, 'b:');
figure,plot(x,y, 'm--');
figure,plot(x,y, '--m'); figure,plot(x,y, '+');
figure,plot(x,y, 'kp:');
Universidad Industrial de Santander CursoBsico de MATLAB
7
-
5/21/2018 Sesin 2 - Graficas Daniel Bernal
8/29
Propiedades y Valores
Propiedad Descripcin Posible valor de la propiedad
LineWidth o linewidth Especifica el grosor de la lnea.
El nmero representado en
unidades de puntos (el valor por
defecto 0,5).
MarkerSize o
markersize
Especifica el tamao de las
marcas.
Un numero representado en
unidades de puntos.
MarkerEdgeColor o
markeredgecolor
Especifica el color del
marcador, o el color del borde
de la lnea para marcadores de
relleno.
Especificadores de color, como los
vistos en tablas anteriores,
introducidos en forma de cadena.
MarkerFaceColor o
markerfacecolor
Especifica el color de relleno de
los marcadores.
Especificadores de color, como los
vistos en tablas anteriores,
introducidos en forma de cadena.
Universidad Industrial de Santander CursoBsico de MATLAB
8
plot(valoresX, valoresY, Nombre_Propiedad, Valor_Propiedad)
-
5/21/2018 Sesin 2 - Graficas Daniel Bernal
9/29
Especificadores de Lnea
Universidad Industrial de Santander CursoBsico de MATLAB
9
Especificador PropiedadPosible valor para la
propiedad
Estilo de lnea LineStyle o linestyleEspecificador de estilo de
lnea.*
Color de lnea Color o color Especificador de color.*
Marcador Marker o marker Especificador de marcador.*
*Como los vistos en las tablas anteriores introducidos en
forma de cadena.
plot(valoresX, valoresY, Nombre_Propiedad, Valor_Propiedad)
-
5/21/2018 Sesin 2 - Graficas Daniel Bernal
10/29
Ejemploplot(0:0.1:2*pi , sin(0:0.1:2*pi),'-mo','linewidth',2,
'markersize',8,'MarkerEdgeColor','g',
'markerfacecolor','y')
Universidad Industrial de Santander CursoBsico de MATLAB
10
0 1 2 3 4 5 6 7
-1
-0.8
-0.6
-0.4
-0.2
0
0.2
0.4
0.6
0.8
1
-
5/21/2018 Sesin 2 - Graficas Daniel Bernal
11/29
plot(valoresX, valoresY, Nombre_Propiedad, Valor_Propiedad)
x=[-2:0.01:4];
y=3.5.^(-0.5*x).*cos(6*x);
plot(x,y, 'Color', 'r', 'Marker', 's','LineWidth',2,...
'MarkerEdgeColor', 'b',...
'MarkerSize', 10);
xlabel('x', 'Fontweight', 'bold',...
'fontsize',15);
ylabel('y', 'fontsize',15,...
'fontweight','bold');
title('Funcin Amortiguada', 'Fontsize',15,'Fontweight','bold');
Universidad Industrial de Santander CursoBsico de MATLAB
11
-
5/21/2018 Sesin 2 - Graficas Daniel Bernal
12/29
Grficas de funcionesfplot (funcion,[Xmin Xmax])
Universidad Industrial de Santander CursoBsico de MATLAB
12
fplot('x*exp(-x^2)',[-3 3])title('y=x*exp(-x^2)')xlabel('x')
ylabel('y')grid on
-3 -2 -1 0 1 2 3-0.5
-0.4
-0.3
-0.2
-0.1
0
0.1
0.2
0.3
0.4
0.5y=x*exp(-x2)
x
y
-
5/21/2018 Sesin 2 - Graficas Daniel Bernal
13/29
EjemplosGraficar, asignar titulo, ejes y algunapropiedad de lnea vista.
Universidad Industrial de Santander CursoBsico de MATLAB
13
2
2 )sin(
t
tx )sin(ttx
-
5/21/2018 Sesin 2 - Graficas Daniel Bernal
14/29
Graficas Polarespolar (,r())
Universidad Industrial de Santander CursoBsico de MATLAB
14
%% Grficas Polares
phi=0:0.05:2*pi;
r=2*cos(2*phi);
polar(phi,r,'g--')title('Grfica
Polar')
0.5
1
1.5
2
30
210
60
240
90
270
120
300
150
330
180 0
Grfica Polar
-
5/21/2018 Sesin 2 - Graficas Daniel Bernal
15/29
Graficas por partesEmplear las funciones de comparacin
Universidad Industrial de Santander CursoBsico de MATLAB
15
-
5/21/2018 Sesin 2 - Graficas Daniel Bernal
16/29
Graficas por partes
Universidad Industrial de Santander CursoBsico de MATLAB
16
x=-3:0.01:4;
f1=x.^2.*(x
-
5/21/2018 Sesin 2 - Graficas Daniel Bernal
17/29
MLTIPLES GRFICAS EN SOLO
EJEMtodo 1Plot (x1,y1,x2,y2,,xn,yn)
Universidad Industrial de Santander CursoBsico de MATLAB
17
x=0:0.01:2*pi;
y1=sin(pi*x);y2=cos(pi*x);
plot(x,y1,x,y2,'g-.')
legend('seno
(x)','coseno (x)')
gridon
0 1 2 3 4 5 6 7-1
-0.8
-0.6
-0.4
-0.2
0
0.2
0.4
0.6
0.8
1
seno (x)
coseno (x)
-
5/21/2018 Sesin 2 - Graficas Daniel Bernal
18/29
MLTIPLES GRFICAS EN SOLOEJEMtodo 2
Universidad Industrial de Santander CursoBsico de MATLAB
18
x=0:0.01:2*pi;
y1=sin(pi*x);
plot(x,y1)gridon
holdon
y2=cos(pi*x);
plot(x,y2,'r.')
legend('seno(x)','coseno (x)')
holdoff0 1 2 3 4 5 6 7
-1
-0.8
-0.6
-0.4
-0.2
0
0.2
0.4
0.6
0.8
1
seno (x)
coseno (x)
-
5/21/2018 Sesin 2 - Graficas Daniel Bernal
19/29
MLTIPLES GRFICAS EN UNA
SOLA FIGURAsubplot (fila,columna,posicion)
Universidad Industrial de Santander CursoBsico de MATLAB
19
x = 0:0.1:100;
Y1 =sin(pi.*x);
Y2=tan(x);
Y3=exp(-x);
Y4=log(x);
subplot(2,2,1);plot(x,Y1);
subplot(2,2,2);plot(x,Y2);
subplot(2,2,3);plot(x,Y3);
subplot(2,2,4);plot(x,Y4);
-
5/21/2018 Sesin 2 - Graficas Daniel Bernal
20/29
GRFICAS ESTADISTICASDiagrama de Sectores pie(x), pie3(x)X=[]
Universidad Industrial de Santander CursoBsico de MATLAB
20
16%
15%
21%
23%
25%
datos
pruebas
casas
perroslocos
23%
25%
21%
15%
16%
-
5/21/2018 Sesin 2 - Graficas Daniel Bernal
21/29
Diagramas de barras
Universidad Industrial de Santander CursoBsico de MATLAB
21
Bar, barh, bar3, bar3h
1 2 3 4 50
5
10
15
20
Barras Verticales
0 5 10 15 20
1
2
3
4
5
Barras Horizontales
12
34
5
0
10
20
Barras Verticales 3D
0
10
20
1
2
3
4
5
Barras Horizontales 3D 1 2 3 40
5
10
15
Barras Verticales
0 5 10 15
1
2
3
4
Barras Horizontales
1 2
3
12
34
0
10
20
Barras Verticales 3D
0
10
20
1
2
3
4
Barras Horizontales 3D
-
5/21/2018 Sesin 2 - Graficas Daniel Bernal
22/29
Graficas en 3D(Curvas en el Espacio)
Universidad Industrial de Santander CursoBsico de MATLAB
22
t=linspace(0,8*pi,2000);plot3(sin(t),cos(t),t),grid on
-
5/21/2018 Sesin 2 - Graficas Daniel Bernal
23/29
Superficies B=[1:10; 10:-1:1; 3:12; 5:14; sin(1:10)];
mesh(B);
figure;
surf(B);
surf(peaks)
Universidad Industrial de Santander CursoBsico de MATLAB
23
-
5/21/2018 Sesin 2 - Graficas Daniel Bernal
24/29
Universidad Industrial de Santander CursoBsico de MATLAB
24
http://www.mat.ucm.es/~rrdelrio/documentos/rrrescorial2002.pdf
-
5/21/2018 Sesin 2 - Graficas Daniel Bernal
25/29
Para complementar
Universidad Industrial de Santander CursoBsico de MATLAB
25
-3 -2 -1 0 1 2 3 40
50
100
150
200
250
-
5/21/2018 Sesin 2 - Graficas Daniel Bernal
26/29
Universidad Industrial de Santander CursoBsico de MATLAB
26
Configurando las propiedades de los ejes
Comando setset(ejes, Nombre_Propiedad,Valor de la propiedad);
x=0:pi/100:2*pi;
y=sin(x);
plot(x,y);get(gca)set(gca,'ydir','reverse');set(gca,'xaxislocation','top');figur=figure(1)get(figur)
-
5/21/2018 Sesin 2 - Graficas Daniel Bernal
27/29
Universidad Industrial de Santander CursoBsico de MATLAB
27
ALGUNAS PROPIEDADES DE LOS EJES
xgrid, ygrid set(gca,xgrid,on); set(gca,xgrid,off);
xticklabel,ytickla
bel
set(gca,xticklabel,
xaxislocation,
yaxislocation
set(gca,xaxislocation,top);
set(gca,yaxislocation,right);
xdir,ydir set(gca,xdir,reverse), set(gca,ydir,reverse);
xlim, ylim set(gca,xlim,[min(x) max(x)])
xminorgrid,
yminorgrid
set(gca,xminorgrid,on);
set(gca,yminorgrid,on);
xcolor, ycolor set(gca,xcolor,[ 0 0 1]); set(gca,ycolor,m);
-
5/21/2018 Sesin 2 - Graficas Daniel Bernal
28/29
Universidad Industrial de Santander CursoBsico de MATLAB
28
ALGUNAS PROPIEDADES DE LAS LNEAS
linestyle set(h,linestyle,-.);
linewidth set(h,linewidth,2);
marker set(h,marker,d);
MarkerEdgeColor
set(h,markerEdgeColor,[0.2 0.5 0.6])
MarkerFaceC
olor
set(h,markerFaceColor,r);
MarkerSize set(h,markersize, 12);
Color set(h,Color,y);
-
5/21/2018 Sesin 2 - Graficas Daniel Bernal
29/29
Universidad Industrial de Santander CursoBsico de MATLAB
29
Configurando las propiedades de la lnea
Comando setset(Lnea, Nombre_Propiedad,Valor de la propiedad);
x=0:pi/100:2*pi;
y=sin(x);
h=plot(x,y);set(h,linewidth,2);set(h,marker,s);set(h,markersize,2);