EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 360+ Courses All in One Bundle
  • Login
Home Data Science Data Science Tutorials Matlab Tutorial Matlab yyaxis
Secondary Sidebar
What is MapReduce in Hadoop?

Virtualization in Cloud Computing

Bias-Variance

MongoDB vs Postgres

Oracle Java

Data Analysis Tools

Matlab yyaxis

Matlab yyaxis

Introduction to Matlab yyaxis

Matlab provides a different kind of functionality to the user; the yyaxis is the one functionality that is provided by Matlab. By using the yyaxis we can create the axes on both sides, that is the left side and right side. Basically in yyaxis left axes are activating from the current associated with the left side axes, at the same time some graphics commands choose the left side. When the current axis does not include the two y-axes at that time graphics commands add the required axis that is yaxis to yyaxis. By using yyaxis we can draw the graph as per our requirement.

Syntax

Start Your Free Data Science Course

Hadoop, Data Science, Statistics & others

There are multiple syntaxes available for yyaxis as follows.

yyaxis left activate side
yyaxis left activate side
yyaxis (axis, specified activate side)

Explanation

In the first syntax, we define the left activate side of axes and that associated with the left y-axis. When we define this syntax, at the same graphics commands select the left side. If there are no axes then the graphics command adds a second y-axis.

In the second syntax, we define the right activated side of axes and that associated with the right y-axis. When we define this syntax, at the same graphics commands select the right side. If there are no axes then the graphics command added a second y-axis

In the third syntax, we can define the specified activated side of axes instead of the current axes. Similarly, there are no axes then the graphics command added two y-axes.

How yyaxis works in Matlab?

Now let’s see how yyaxis works in Matlab as follows.

There are different ways to draw the graph as follows.

  1. Draw graph by using two y-axes:

In this method, we need to use the y-axis on the left and right sides. We start the plotting graph from the left side to the right activated side. After that graphics command, select the activated right side against the provided data and specify the limit for the right y-axis.

  1. Now let’s see how we can add title and labels on each side:

In this method we can add titles and labels for charts by using y-axes. To add title and labels we need to use hwtdata () and label () commands as per our requirement.

  1. Multiple sets on each data side:

In this method we can plot the two different lines against records of the left y-axis by using the hold on command as per requirement.

  1. Now let’s see how we can add the colors to the chart:

We can add color combinations by using the colororder () function. In this method we can specify the color of each side of the axes, here we can set the two different colors as per our requirement and after that, we can plot the two lines against the left side and right side y-axis.

  1. Now let’s see how we can control the plot colors:

By using this method we can plot the bar chart as per our requirement and we can use different color combinations for each bar by using colororder () function.

Now let’s see what the input argument is and how it is helpful to yyaxis as follows.

Basically, we use two input arguments to plot the chart such as target axes. Normally target axes are used to specify the axes object if we miss specifying the object then yyaxis use current axes.

Yyaxis uses grid lines, color, and Line styles algorithm to plot the required chart or bar as per our requirement.

Examples

Now let’s see the different examples of yyaxis in Matlab for better understanding as follows. Now let’s see how we can plot records by using two y axes as follows.

a = linspace(0,8);
b = sin(4*a);
yyaxis left
plot(a,b)
c = sin(4*a).*exp(1.5*a);
yyaxis right
plot(a,c)
ylim([-100 100])

Explanation

By using the above example we plot the records by using two y-axes. Here we use the linspace() function as well as sin as shown in the above example. At the end of the example, we set the limit for right side axes. The final output of the above statement we illustrated by using the screenshot as follows.

Matlab yyaxis output 1

Now let’s see how we can plot a chart with multiple sets for each side as follows.

a = linspace(0,8);
yl1 = sin(a);
yl2 = sin(a/2);
yyaxis left
plot(a,yl1)
hold on
plot(a,yl2)

Explanation

In the above example, we use the hold-on command to plot the two lines against the left axes as shown in the above example. The final output of the above statement we illustrated by using the screenshot as follows.

Matlab yyaxis output 2

Similarly we can plot two lines by using right side axes as follows.

a = linspace(0,8);
yr1 = a;
yr2 = a.^4;
yyaxis right
plot(a,yr1)
plot(a,yr2)
hold off

Explanation

In the above example, we use the linspace () function to plot the chart. See here when we plot right we need to use some different parameter as compared to the left y-axes. Here we use yr1 instead of yl1 and hold off of instead of hold on as shown in the above example. After that, we also need to change the direction that means left to right yyaxis as shown. The final output of the above statement we illustrated by using the screenshot as follows.

output 3

Suppose we need to activate the left side at that time we can use the following statement as follows.

yyaxis left
cla

Explanation

The final output of the above statement we illustrated by using the screenshot as follows.

output 4

Now let’s see the example of a color chart that means we can add the color as follows.

colororder({'b','m'})
yyaxis left
a = [2 3; 4 5];
plot(y)
yyaxis right
b = [5 4; 3 2];
plot(b)
legend

Explanation

In the above example, we use the colororder () command. The final output of the above statement we illustrated by using the screenshot as follows.

output 5

So in this way, we can plot any type of chart or bar as per our requirement with different color combinations.

Conclusion

We hope from this article you learn Matlab yyaxis. From the above article, we have learned the basic syntax of yyaxis and we also see different examples of yyaxis. From this article, we learned how and when we use Matlab yyaxis.

Recommended Articles

This is a guide to Matlab yyaxis. Here we discuss the basic syntax of yyaxis and we also see different examples of yyaxis. You may also have a look at the following articles to learn more –

  1. Matlab Backslash
  2. Matlab Block Comment
  3. Matlab Saveas
  4. Multiple Plots in Matlab
Popular Course in this category
MATLAB Training (3 Courses, 1 Project)
  3 Online Courses |  1 Hands-on Project |  8+ Hours |  Verifiable Certificate of Completion
4.5
Price

View Course

Related Courses

R Programming Training (13 Courses, 20+ Projects)4.9
All in One Data Science Bundle (360+ Courses, 50+ projects)4.8
Primary Sidebar
Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Live Classes
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Database Management
  • Machine Learning
  • All Tutorials
Certification Courses
  • All Courses
  • Data Science Course - All in One Bundle
  • Machine Learning Course
  • Hadoop Certification Training
  • Cloud Computing Training Course
  • R Programming Course
  • AWS Training Course
  • SAS Training Course

ISO 10004:2018 & ISO 9001:2015 Certified

© 2023 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

Let’s Get Started

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA Login

Forgot Password?

By signing up, you agree to our Terms of Use and Privacy Policy.

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more