20
Lesson 6: basic plots

Lesson 6: basic plots. Lesson 6 Outline: Plot 1-basic plot commands 1) Figure Line style Marker style Labels and Titles Axes Matlab help LineSpec (colors,

  • View
    224

  • Download
    2

Embed Size (px)

Citation preview

Page 1: Lesson 6: basic plots. Lesson 6 Outline: Plot 1-basic plot commands 1) Figure Line style Marker style Labels and Titles Axes Matlab help LineSpec (colors,

Lesson 6:

basic plots

Page 2: Lesson 6: basic plots. Lesson 6 Outline: Plot 1-basic plot commands 1) Figure Line style Marker style Labels and Titles Axes Matlab help LineSpec (colors,

Lesson 6 Outline:    Plot 1-basic plot commands

1) FigureLine style Marker styleLabels and TitlesAxes

Matlab help LineSpec (colors, marker styles, line styles)

2) Matlab program for basic plots L6_plots.m

line plots: 1D with time Multiple data sets 1D across time

scatter plots: 2Dbar plots : Hx

3) Subplots

4) Managing plotsvisible offpausesaveas

5) Play with zoom

Page 3: Lesson 6: basic plots. Lesson 6 Outline: Plot 1-basic plot commands 1) Figure Line style Marker style Labels and Titles Axes Matlab help LineSpec (colors,

x=rand(20,10);

figure

plot(x(:,10))

plot(x(:,9))

hold on

plot(x(:,10),’r’)

Page 4: Lesson 6: basic plots. Lesson 6 Outline: Plot 1-basic plot commands 1) Figure Line style Marker style Labels and Titles Axes Matlab help LineSpec (colors,

figure

plot(x(:,5),'--b','LineWidth',2)

plot(x(:,4),':ko','LineWidth',2)

hold on

plot(x(:,3),'-md','LineWidth’ 2, 'MarkerEdgeColor’, 'k', 'MarkerFaceColor', 'g', 'MarkerSize', 10)

close all

Page 5: Lesson 6: basic plots. Lesson 6 Outline: Plot 1-basic plot commands 1) Figure Line style Marker style Labels and Titles Axes Matlab help LineSpec (colors,

MatLab help

search LineSpec

colors

line styles

marker styles

5 minutes to play

Page 6: Lesson 6: basic plots. Lesson 6 Outline: Plot 1-basic plot commands 1) Figure Line style Marker style Labels and Titles Axes Matlab help LineSpec (colors,

xlabel(‘time')

axis([xmin xmax ymin ymax])

title(’random x plot')

ylabel(’column_5')

axis([1 25 -1 1])

Page 7: Lesson 6: basic plots. Lesson 6 Outline: Plot 1-basic plot commands 1) Figure Line style Marker style Labels and Titles Axes Matlab help LineSpec (colors,

Uncomment the next plot command

L6_plots.m

highlight lines 35-45

open the m file from your current directory

right click and “uncomment”

save

run the program

Page 8: Lesson 6: basic plots. Lesson 6 Outline: Plot 1-basic plot commands 1) Figure Line style Marker style Labels and Titles Axes Matlab help LineSpec (colors,

What are we plotting?

Let’s look at the code

Run the program and see if you were correct.

Is it a line? What color? Are there markers?

plot(x,'b')hold onplot(y,'r')hold on

Page 9: Lesson 6: basic plots. Lesson 6 Outline: Plot 1-basic plot commands 1) Figure Line style Marker style Labels and Titles Axes Matlab help LineSpec (colors,

Uncomment the next plot command

highlight lines 48-54

right click and “uncomment”

save

Page 10: Lesson 6: basic plots. Lesson 6 Outline: Plot 1-basic plot commands 1) Figure Line style Marker style Labels and Titles Axes Matlab help LineSpec (colors,

What are we plotting?

Let’s look at the code

Run the program and see if you were correct.

Is it a line? What color? Are there markers?

plot(x,y,'b*');

Page 11: Lesson 6: basic plots. Lesson 6 Outline: Plot 1-basic plot commands 1) Figure Line style Marker style Labels and Titles Axes Matlab help LineSpec (colors,

Uncomment the next plot command

highlight lines 58-61

right click and “uncomment”

save

Page 12: Lesson 6: basic plots. Lesson 6 Outline: Plot 1-basic plot commands 1) Figure Line style Marker style Labels and Titles Axes Matlab help LineSpec (colors,

What are we plotting?

Let’s look at the code

Run the program and see how it looks.

Is it a line? What color? Are there markers?

hist(z)

In command window type help hist

Page 13: Lesson 6: basic plots. Lesson 6 Outline: Plot 1-basic plot commands 1) Figure Line style Marker style Labels and Titles Axes Matlab help LineSpec (colors,

What is the default bin size?

hist(z,25)

hist(z,50)

Try changing the bin size

Page 14: Lesson 6: basic plots. Lesson 6 Outline: Plot 1-basic plot commands 1) Figure Line style Marker style Labels and Titles Axes Matlab help LineSpec (colors,

Uncomment the next plot command

highlight lines 65-72

right click and “uncomment”

save

Page 15: Lesson 6: basic plots. Lesson 6 Outline: Plot 1-basic plot commands 1) Figure Line style Marker style Labels and Titles Axes Matlab help LineSpec (colors,

What are we plotting?

Let’s look at the code

Run the program and see if you were correct.

Is it a line? What color? Are there markers?

subplot(3,2,1);plot(x,’r’);subplot(3,2,2);plot(y,’b’);subplot(3,2,3);plot(x2,’-rd’);subplot(3,2,4);plot(y2,’:mo’);subplot(3,2,5);plot(x3,’- -k’);subplot(3,2,6);plot(y3, ‘-.g’);

Page 16: Lesson 6: basic plots. Lesson 6 Outline: Plot 1-basic plot commands 1) Figure Line style Marker style Labels and Titles Axes Matlab help LineSpec (colors,

subplot(3,2,1);subplot(3,2,2);subplot(3,2,3);subplot(3,2,4);subplot(3,2,5);subplot(3,2,6);

3 rows

2 columns

6 plots

Page 17: Lesson 6: basic plots. Lesson 6 Outline: Plot 1-basic plot commands 1) Figure Line style Marker style Labels and Titles Axes Matlab help LineSpec (colors,

Managing figures

where are they?

stops the program

put a pause after each figure (copy and paste line 76)

Save

run the program

How many figures were made when you ran the program?

“pause”

Page 18: Lesson 6: basic plots. Lesson 6 Outline: Plot 1-basic plot commands 1) Figure Line style Marker style Labels and Titles Axes Matlab help LineSpec (colors,

What if you do not want to see the figures? How can you save them to a file?

creating a figure “handle”

saveas(fig_x,[outpath,’xy_scatter.tif’]); copy and paste line 77

adjust figure “handle” and name of file

set(fig_x,’visible’,’off’)’; copy and paste line 75

adjust figure “handle” for this line

fig_x=figure;

% pause be sure to comment out the pauses

Page 19: Lesson 6: basic plots. Lesson 6 Outline: Plot 1-basic plot commands 1) Figure Line style Marker style Labels and Titles Axes Matlab help LineSpec (colors,

Select area you want enlarged

Using zoom on Matlab plots

Save as

Click on zoom at top of figure

++

Page 20: Lesson 6: basic plots. Lesson 6 Outline: Plot 1-basic plot commands 1) Figure Line style Marker style Labels and Titles Axes Matlab help LineSpec (colors,

Enjoy playing with Matlab plots!!!