
Separate multiple graphs in Octave
In this lesson, I will explain how to create a multiple graph on Octave with two or more separate views.
What is a multiple graph with separate views? In multiple graphs with separate views, the workspace is divided into two or more sections. Each section displays a graph, allowing you to visualize multiple functions using different charts instead of just one. Here's an example of a multiple graph with four different views:
Practical Example
Create an array x and two different function arrays y1 and y2. Each array should have one hundred elements.
>> x=linspace(1,100,100);
>> y1=x.^2;
>> y2=log(x);
To divide the graphing area into multiple charts, use the subplot(rows, columns, graph) command.
To display two graphs side by side, set a single row and two columns.
>> subplot(1,2,1)
The subplot(1, 2, 1) command draws the first Cartesian chart in the first row and first column.
Now, draw the graph of the y1 function using the plot(x, y1) command.
>> plot(x,y1)
The graph is displayed in the first Cartesian chart.
Next, move to the second Cartesian chart using the subplot(1, 2, 2) command.
>> subplot(1,2,2)
This command plots another Cartesian chart on the same row but in the second column.
Then, draw the graph of the y2 function using the plot(x, y2) command.
>> plot(x,y2)
This other graph is drawn in the second chart.
In this way, you can draw multiple graphs in the same workspace without overlapping them.
If you want to overlap the graphs on a single Cartesian chart, I recommend reading this other Octave lesson.
Note. In this example, I showed you how to build two adjacent Cartesian charts. Generally, you can also divide the area into multiple sections. For example, you can divide the graphing area into two rows and two columns by writing subplot(2, 2, 1), subplot(2, 2, 2), subplot(2, 2, 3), subplot(2, 2, 4).
This way, you can view four graphs simultaneously in four Cartesian charts.
If you find this online Octave lesson by Nigiara helpful, continue following us.