X Plotted Against Y

This example shows how to create a chart with y-axes on the left and right sides using the yyaxis function. It also shows how to label each axis, combine multiple plots, and clear the plots associated with one or both of the sides.

The variables xand yare related in such a way that when y xis plotted against xa straight line is obtained, as shown in the graph. The line passes through the points (1, 3) and (3, –1). (i) Express yin terms of x. It is a scatter plot of residuals on the y axis and the predictor (x) values on the x axis. For a simple linear regression model, if the predictor on the x axis is the same predictor that is used in the regression model, the residuals vs. Predictor plot offers no new information to that which is already learned by the residuals vs. An example of real GDP (y) plotted against time (x). Often time is denoted as t instead of x. The IS curve moves to the right if spending plans at any potential interest rate go up, causing the new equilibrium to have higher interest rates (i) and expansion in the 'real' economy (real GDP, or Y).

The best way to think about this is to imagine a scatterplot of points with y on the vertical axis and x represented by the horizontal axis. Given this framework, you see a cloud of points, which may be vaguely circular, or may be elongated into an ellipse.

Plot Data Against Left y-Axis

Create axes with a y-axis on the left and right sides. The yyaxis left command creates the axes and activates the left side. Subsequent graphics functions, such as plot, target the active side. Plot data against the left y-axis.

Plot Data Against Right y-Axis

Activate the right side using yyaxis right. Then plot a set of data against the right y-axis.

Add Title and Axis Labels

Control which side of the axes is active using the yyaxis left and yyaxis right commands. Then, add a title and axis labels.

Plot Additional Data Against Each Side

Add two more lines to the left side using the hold on command. Add an errorbar to the right side. The new plots use the same color as the corresponding y-axis and cycle through the line style order. The hold on command affects both the left and right sides.

Clear One Side of Axes

Against

Clear the data from the right side of the axes by first making it active, and then using the cla command.

Clear Axes and Remove Right y-Axis

Clear the entire axes and remove the right y-axis using cla reset.

Plot X Against Y Python

Now when you create a plot, it only has one y-axis. For example, plot three lines against the single y-axis.

Add Second y-Axis to Existing Chart

Plot X Vs Y In R

Add a second y-axis to an existing chart using yyaxis. The existing plots and the left y-axis do not change colors. The right y-axis uses the next color in the axes color order. New plots added to the axes use the same color as the corresponding y-axis.

See Also

Functions

  • cla hold plot title xlabel ylabel yyaxis

Plot X Vs Y Python

Related Topics