egr106 week 4 two dimensional plots multiple plots plot formatting homework

18
EGR106 Week 4 • Two Dimensional Plots • Multiple Plots • Plot Formatting • Homework

Post on 21-Dec-2015

216 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: EGR106 Week 4 Two Dimensional Plots Multiple Plots Plot Formatting Homework

EGR106 Week 4

• Two Dimensional Plots

• Multiple Plots

• Plot Formatting

• Homework

Page 2: EGR106 Week 4 Two Dimensional Plots Multiple Plots Plot Formatting Homework

Two Dimensional Plots

• Line type• plot(x,y,’--’) gives a dashed line

• Line color• plot(x,y,’g’) gives a green line

• Line thickness

• Markers• plot(x,y,’--r*’,’linewidth’,2,’markersize’,12)

• Dashed red line with * marker

Page 3: EGR106 Week 4 Two Dimensional Plots Multiple Plots Plot Formatting Homework

Multiple Plots

• Plot(x, y1, x, y2) Plots y1 and y2 vs x• hold on

• Keeps the plot window open for additional lines on the same plot

• hold off• Stops writing to the plot

• subplot(n,m,k)• Selects plot k in an nxm array of plots.• Used for multiple plots on the same page.

Page 4: EGR106 Week 4 Two Dimensional Plots Multiple Plots Plot Formatting Homework

Plot Formatting

• xlabel, ylabel• xlabel(‘time (sec)’)

• title• title(‘Problem 3 Solution’)

• text• text(x,y,’your message at coordinates x,y’)

• legend• legend(‘first curve’,’second curve’)

– used for multiple curves on a single plot

Page 5: EGR106 Week 4 Two Dimensional Plots Multiple Plots Plot Formatting Homework

Plot Formatting

• Subscripts and superscripts

• Greek letters

• Rotating text

Page 6: EGR106 Week 4 Two Dimensional Plots Multiple Plots Plot Formatting Homework

Line Properties and Valuesplot(x,y, 'linewidth',5 )

line width is 5 “points”

Page 7: EGR106 Week 4 Two Dimensional Plots Multiple Plots Plot Formatting Homework

>> x=0:2:10;>> y=x.^2;>> plot(x,y,'--r*','linewidth',2,'markersize',12)>> text(2,50,'\fontsize{30} \alpha Profit= x^2 ', 'rotation',45)

Page 8: EGR106 Week 4 Two Dimensional Plots Multiple Plots Plot Formatting Homework

Line Specifiersplot(x,y, ' r : d ' )

red

dotted line

diamonds

Page 9: EGR106 Week 4 Two Dimensional Plots Multiple Plots Plot Formatting Homework

Multiple Plots on the Same Axes• Plot allows multiple

sets of arrays and line specifiers:

Note colors rotate

Page 10: EGR106 Week 4 Two Dimensional Plots Multiple Plots Plot Formatting Homework

Two Useful Commands

• figure– alone it opens a new window – figure(n) takes you to window n

• ginput(1) – creates crosshairs on the screen– returns (x,y) location of cursor at mouse click– ginput(n) returns n pairs of locations

Page 11: EGR106 Week 4 Two Dimensional Plots Multiple Plots Plot Formatting Homework

Formatting Plots – The Axes

• Adding a grid

grid

• Setting the axis limits:

axis( [ xmin xmax ymin ymax ] )

Page 12: EGR106 Week 4 Two Dimensional Plots Multiple Plots Plot Formatting Homework

Formatting Plots – Adding Text• Week 1:

– xlabel( 'string' )– ylabel( 'string' )– title( 'string' )– text( x, y, 'string' )

• New:– gtext( 'string' ) – cursor controlled – legend( 'string1', … 'stringn', loc)

Page 13: EGR106 Week 4 Two Dimensional Plots Multiple Plots Plot Formatting Homework

Multiple Axes in One Figure - Subplot

subplot(2,2,1)

plot(x1,y1)

subplot(2,2,2)

etc.

Argument is rows, columns, choice

Page 14: EGR106 Week 4 Two Dimensional Plots Multiple Plots Plot Formatting Homework

Click on the arrow to start interaction

Double click on some part of the figure to initiate choices

Page 15: EGR106 Week 4 Two Dimensional Plots Multiple Plots Plot Formatting Homework

Modify text:

Or the lines themselves:

Page 16: EGR106 Week 4 Two Dimensional Plots Multiple Plots Plot Formatting Homework

Other Types of 2-D Plots - Polarx = 1:100;

r = log10(x);

t = x/10;

polar( t, r )

magnitude

angle in radians

0.5

1

1.5

2

30

210

60

240

90

270

120

300

150

330

180 0

Page 17: EGR106 Week 4 Two Dimensional Plots Multiple Plots Plot Formatting Homework

Other Notes

• Line specifiers, properties, axis, grid, … work on many of the plot types

• Most of these tools have additional features – use the help function

• 3-dimensional plots are available (chapter 9) with viewpoint options

Page 18: EGR106 Week 4 Two Dimensional Plots Multiple Plots Plot Formatting Homework

-1-0.5

00.5

1

-1

-0.5

0

0.5

10

10

20

30

40

-1

-0.5

0

0.5

1

-1

-0.5

0

0.5

1

0

20

40

-2-1

01

2

-2

-1

0

1

2-1

-0.5

0

0.5

1