Hi there
I want to know, how can I graph the two plot in one frame?
2 Answers
0
accepted
I am not sure if you are asking how to create two sub-plots next to each other or how to have two lines inside the same set of axes, so I will give you both answers.
If you simply want two lines inside of a set of axes, you can either:
- Pass in multiple columns of data, since each column will be plotted as a different line.
- Use one of the
plotAdd
functions to add another line, scatter series, etc.
Plot multiple columns
x = seqa(1, 1, 10);
//Create two sample 'y' columns
y = rndn(10,2);
//Plot both 'y' columns inside same axes
plotXY(x, y);
Use plotAdd
If the second column of data is not of the same length as the first, it is difficult to put them together as two columns in the same matrix. You can actually do this by padding the shorter column with missing values, but it is much simpler to just use a plotAdd
function like this
x = seqa(1, 1, 10);
//Create first example 'y' column
y = rndn(10,1);
//Create second example 'x' and 'y'
x_2 = seqa(1, 1, 14);
y_2 = rndn(14,1);
//Plot first 'y' column
plotXY(x, y);
//Add second 'y' column to the plot just created
plotAddXY(x_2, y_2);
How to create two sub-plots
For this, you use the plotLayout
command. I think the code and comments below are the best way to explain its usage.
//Create some data to plot
x = seqa(1,1,10);
y = rndn(10,1);
//Divide plot canvas into
//a 2x1 grid and place
//the next plot in the FIRST cell
plotLayout(2, 1, 1);
plotXY(x, y);
//Reuse 'x', new 'y' for second plot
y = rndn(10,1);
//Divide plot canvas into
//a 2x1 grid and place
//the next plot in the SECOND cell
plotLayout(2, 1, 2);
plotXY(x, y);
//Clear the plot grid/layout
//so future plots are not inside the grid
plotClearLayout();
0
thank you so much.
Your Answer
2 Answers
I am not sure if you are asking how to create two sub-plots next to each other or how to have two lines inside the same set of axes, so I will give you both answers.
If you simply want two lines inside of a set of axes, you can either:
- Pass in multiple columns of data, since each column will be plotted as a different line.
- Use one of the
plotAdd
functions to add another line, scatter series, etc.
Plot multiple columns
x = seqa(1, 1, 10);
//Create two sample 'y' columns
y = rndn(10,2);
//Plot both 'y' columns inside same axes
plotXY(x, y);
Use plotAdd
If the second column of data is not of the same length as the first, it is difficult to put them together as two columns in the same matrix. You can actually do this by padding the shorter column with missing values, but it is much simpler to just use a plotAdd
function like this
x = seqa(1, 1, 10);
//Create first example 'y' column
y = rndn(10,1);
//Create second example 'x' and 'y'
x_2 = seqa(1, 1, 14);
y_2 = rndn(14,1);
//Plot first 'y' column
plotXY(x, y);
//Add second 'y' column to the plot just created
plotAddXY(x_2, y_2);
How to create two sub-plots
For this, you use the plotLayout
command. I think the code and comments below are the best way to explain its usage.
//Create some data to plot
x = seqa(1,1,10);
y = rndn(10,1);
//Divide plot canvas into
//a 2x1 grid and place
//the next plot in the FIRST cell
plotLayout(2, 1, 1);
plotXY(x, y);
//Reuse 'x', new 'y' for second plot
y = rndn(10,1);
//Divide plot canvas into
//a 2x1 grid and place
//the next plot in the SECOND cell
plotLayout(2, 1, 2);
plotXY(x, y);
//Clear the plot grid/layout
//so future plots are not inside the grid
plotClearLayout();
thank you so much.