Presentation is loading. Please wait.

Presentation is loading. Please wait.

EGR 115 Introduction to Computing for Engineers 2D Plotting – Part I Wednesday 17 Sept 2014 EGR 115 Introduction to Computing for Engineers.

Similar presentations


Presentation on theme: "EGR 115 Introduction to Computing for Engineers 2D Plotting – Part I Wednesday 17 Sept 2014 EGR 115 Introduction to Computing for Engineers."— Presentation transcript:

1 EGR 115 Introduction to Computing for Engineers 2D Plotting – Part I Wednesday 17 Sept 2014 EGR 115 Introduction to Computing for Engineers

2 Lecture Outline Wednesday 17 Sept 2014 EGR 115 Introduction to Computing for Engineers 2D Plotting  Additional plotting features Slide 2 of 13

3 2D Plotting Additional Plotting Features – LineSpec Review Wednesday 17 Sept 2014 EGR 115 Introduction to Computing for Engineers Review of Line Specifications For Example: >> x=0:0.1:pi; >> plot(x, sin(x), ‘k>:') Line ColorMarker Line Style b blue. point - solid g green o circle : dotted r red x x-mark -. dashdot c cyan + plus -- dashed m magenta * star (none) no line y yellow s square k black d diamond w white v triangle (down) ^ triangle (up) < triangle (left) > triangle (right) p pentagram h hexagram Slide 3 of 13

4 2D Plotting Additional Plotting Features – Log Scales Wednesday 17 Sept 2014 EGR 115 Introduction to Computing for Engineers Linear / Linear plot Slide 4 of 13

5 2D Plotting Additional Plotting Features – Log Scales Wednesday 17 Sept 2014 EGR 115 Introduction to Computing for Engineers  A log / linear plot >> semilogx(f, sqrt(G.* conj(G))) >> xlabel('Freq in Hz'); >> ylabel('Attenuation') >> title('Attenuation of a Low-Pass Filter') Cut-off freq of 200 Hz Slide 5 of 13

6 2D Plotting Additional Plotting Features – Log Scales Wednesday 17 Sept 2014 EGR 115 Introduction to Computing for Engineers Plot the attenuation in db = 20 log 10 (?)  A log / log plot >> loglog(f, (sqrt(G.* conj(G))).^20) >> xlabel('Freq in Hz'); >> ylabel('Attenuation in db') >> title('Attenuation of a Low-Pass Filter') >> grid Cut-off freq of 200 Hz at -3 db Slide 6 of 13

7 2D Plotting Additional Plotting Features – Plot Limits Wednesday 17 Sept 2014 EGR 115 Introduction to Computing for Engineers Controlling the limits for the x and y axes of a plot axis([xminxmaxyminymax]) Sets the limits for thex-andy-axis of the current plot axis tightSets the axis limits to the range of the data axis equal Sets the aspect ratio so that the data units are the same axis offturns off all axis lines, tick marks, and labels axis squaremakes the current axes region square xlim([xminxmax])Sets only the x-axis limitsylim([yminymax])Sets only the y-axis limits Slide 7 of 13

8 2D Plotting Additional Plotting Features – Plot Limits Wednesday 17 Sept 2014 EGR 115 Introduction to Computing for Engineers Data units the same i.e., 0.2 in x = 0.2 in y Square aspect ratio Slide 8 of 13

9 2D Plotting Additional Plotting Features – Left / Right Axis Plots Wednesday 17 Sept 2014 EGR 115 Introduction to Computing for Engineers Plotting with Both Left and Right Side Axes  A Hwk problem with speed and position (MATLAB code) plotyy(time, height, time, speed) plot(time, height, time, speed) Labeling the right axis can be tricky!! Slide 9 of 13

10 2D Plotting Additional Plotting Features – Creating Multiple Figures Wednesday 17 Sept 2014 EGR 115 Introduction to Computing for Engineers Issuing multiple plot commands will result in overwriting the prior plot window:  The “figure” command creates a new plot window >> t = 0:0.1:2*pi; >> plot(t, sin(t), 'b') >> plot(t, cos(t), 'r') Overwrites the Prior Plot >> t = 0:0.1:2*pi; >> figure(1) >> plot(t, sin(t), 'b') >> figure(2) >> plot(t, cos(t), 'r') Creates two Plot Windows Slide 10 of 13

11 2D Plotting Additional Plotting Features – SubPlots Wednesday 17 Sept 2014 EGR 115 Introduction to Computing for Engineers We can also place multiple plots in a single figure:  Subplot(num_rows, num_cols, position) Position#1 Position#2 Position#3Position#4 % An in class example of subplots t = 0:0.1:2*pi; % Array of angles (rad) figure(1); % Open a new figure subplot(2, 2, 1); % Subplot#1 at position 1,1 plot(t, sin(t)); % Plot sin(theta) title('Subplot 1: Sin(\theta)') subplot(2, 2, 2); % Subplot#2 at position 1,2 plot(t, cos(t)); % Plot cos(theta) title('Subplot 2: Cos(\theta)') subplot(2, 2, 3); % Subplot#1 at position 2,1 plot(t, sin(2*t)); % Plot sin(2 theta) title('Subplot 3: Sin(2\theta)') subplot(2, 2, 4); % Subplot#2 at position 2,2 plot(t, cos(2*t)); % Plot cos(2 theta) title('Subplot 4: Cos(2\theta)') Slide 11 of 13

12 2D Plotting Additional Plotting Features – SubPlots Wednesday 17 Sept 2014 EGR 115 Introduction to Computing for Engineers Create the following plot: Slide 12 of 13

13 Next Lecture Wednesday 17 Sept 2014 EGR 115 Introduction to Computing for Engineers Annotation of Plots Polar, Bar, Pie, … Plots Slide 13 of 13


Download ppt "EGR 115 Introduction to Computing for Engineers 2D Plotting – Part I Wednesday 17 Sept 2014 EGR 115 Introduction to Computing for Engineers."

Similar presentations


Ads by Google