Lesson 6:
basic plots
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
x=rand(20,10);
figure
plot(x(:,10))
plot(x(:,9))
hold on
plot(x(:,10),’r’)
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
MatLab help
search LineSpec
colors
line styles
marker styles
5 minutes to play
xlabel(‘time')
axis([xmin xmax ymin ymax])
title(’random x plot')
ylabel(’column_5')
axis([1 25 -1 1])
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
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
Uncomment the next plot command
highlight lines 48-54
right click and “uncomment”
save
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*');
Uncomment the next plot command
highlight lines 58-61
right click and “uncomment”
save
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
What is the default bin size?
hist(z,25)
hist(z,50)
Try changing the bin size
Uncomment the next plot command
highlight lines 65-72
right click and “uncomment”
save
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’);
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
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”
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
Select area you want enlarged
Using zoom on Matlab plots
Save as
Click on zoom at top of figure
++
Enjoy playing with Matlab plots!!!
Top Related