How to Plot MATLAB Graph with Colors, Markers, Line Specification Complete Details

This is a typical single color graph as shown below.


This graph still looks good as you are drawing a single graph on the MATLAB display.

Each color describes one graph and that makes the graph self-descriptive.

How can you decorate your MATLAB graph?

In this tutorial, you will learn to plot the colorful graphs in MATLAB.

I am also explaining by plotting a graph for the mathematical equation on MATLAB by using a single color, simple marker and line specification.

We will also see what are the most important and useful color coding functions, marker style and line-specification designing functions available in MATLAB.
By using these functions, you can draw the graph or waveform as per your color and plotting style choice. And you can easily understand the particular equation’s graph.

Let’s begin by considering the top three essential components to decorate your graph more meaningful.


  • Colour
  • Marker Style
  • Line Specification

Explanation of these three component functions are one-by-one,

MATLAB Plot Colors to draw the Graph
If you are drawing any picture on paper, you have different color pencils to use.

Likewise, for plotting the graph on MATLAB, we have different colors code or functions.

Widely, eight colors are used for MATLAB graph. And each color has the corresponding color code.

The below table shows color specification with the color code.

You can use these eight colors code to draw the colorful waveforms in MATLAB.

MATLAB Plot Marker | Different Style to Draw the Graph
Rather than just a simple line, do you want to make your waveform look different?

There are different marker style functions. For example, star format function, point format function, square format function, plus format function and so on.
In the below table, I am sharing the 12 marker style functions and its useful code for MATLAB graph.

How does the graph look different after using these marker styles? This we will see later in this tutorial example.

MATLAB Plot Line Specification | Code for MATLAB Graph

The four different spaceline codes are used for the plotting waveform or graph.

Check this below table, for line specification code.

The syntax for plotting graph to add color, marker, and line specification:

plot (x, y, 'colour marker linespec')

These codes are placed inside single inverted comma.

How to Plot MATLAB Graph with different colors, markers, and line specifier

How to change Colour, Marker, and Line-Specification in MATLAB plot?

Let’s take these two mathematical equations to plot the MATLAB graph.
Now its time to implement all three essentials components (color, marker, and line specifier) for decorating the MATLAB graph.

1)  y(x)=sin(2x) 

2) derivative of the same function d/dx(sin(2x)) on the same graph.

Solution:

The first mathematical equation is trigonometric.

y1`= sin (2x)

And it’s derivative of a mathematical equation of y(x) is

y2= d/dx (y1)= 2 cos (2x)

MATLAB Code:

Here is MATLAB code you can write to plot the graph for the function of f(x) and its d/dx (f(x)).

x=[0:0.01:10];
y1 = sin(2*x);
y2=2.*cos(2.x);
plot(x,y1,'r * -');
hold on
plot(x,y2,'k . :');
legend('sin', 'cos');

In this program, I have used the ‘legend’ function to label data series plotted on a graph. You can see in the below MATLAB output.

We are using different colors, markers and line specifications for plotting two different graphs.

Output:

Share:

Total Pageviews

CONTACT US

Prof. Roshan P. Helonde
Mobile: +917276355704
WhatsApp: +917276355704
Email: roshanphelonde@rediffmail.com

Enter Project Title

Popular Projects

All Archive

Contact Form

Name

Email *

Message *