Javatpoint Logo
Javatpoint Logo

MATLAB 2-D Plots

Objective: To study graphics, i.e., 2-D plots, printing labels, grid and axis box, text in plot, bar, and pie chart.

Example

Output:

MATLAB 2-D Plots

Multiple plots:

Examples

Output:

MATLAB 2-D Plots

Line color, Line style, Marker style, and legends:

  • Line color:
y
m
c
r
g
b
w
k
  • Marker style:
.  → point                                                             
o → circle
x → x-mark
+ → plus
*→ star
s → square
d → diamond
v → triangle(left)
^ → triangle(up)
< → triangle(left)
>→ triangle(right)
p → pentagon
h → hexagon
            <none> → no marker
  • Line style:
-  → solid 
-. → dashed dot
-- →dashed
.. → dotted
<none> → no line

TITLE:

Title ('title_string', 'Font Name', Helvetica','Font Size',20.'color','green','Font Weight','light/bold/normal','Font Angle','Normal/italic');

AXES:

Axes('Position',[left, bottom,width,height])

E.g.: To create axes at (0.2,0.2), size half of the figure window.

            axes ('Position', [.2 .2 .5  .5]);

MATLAB 2-D Plots

TEXT:

To add a text string to a specified location in the plot area.

text(r,c,'string');

GTEXT: need not to specify text location.

gtext('string');

where we click, the text will be displayed there.

LEGEND:

Position of legend:

top left		top center		top right
medium left medium center medium right
bottom left bottom center bottom right

Example

Output:

MATLAB 2-D Plots

Statistical plots:

pie(x):

Example

Output:

MATLAB 2-D Plots

To pull out 3rd slide:

Example

Output:

MATLAB 2-D Plots

To pull text labels:

Example

Output:

MATLAB 2-D Plots

Bar graphs:

bar(x): It plots the bar. Plot the values of x against the time index.

bar(t,x): if we want to give t by ourselves.

Example

Output:

MATLAB 2-D Plots

bar(x,'stacked'):

Output:

MATLAB 2-D Plots

Print command:

print<option><filename>

options:

  • -deps: It creates a monochrome encapsulated postscript image.
  • -depsc: It creates a colored encapsulated postscript image.
  • -djpeg: Its joint photography expert group.
  • -dpng: Its portable network graphics.

E.g.: print -djpeg myimg.jpeg






Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA