Source: subplot_demo.f90
Demonstration of subplot functionality using the stateful API.
use fortplot, only: figure, plot, xlabel, ylabel, title, savefig, subplot
! Create figure and subplot grid
call figure(800, 600)
call subplot(rows, cols, index) ! Create grid and switch to subplot
! Add content to current subplot
call plot(x, y)
call title('Subplot Title')
call xlabel('X Label')
call ylabel('Y Label')
! Save entire subplot grid
call savefig('output.png')
Bottom-right: Quadratic function x²/50
Left: Linear function x
subplot_demo.f90 - Source codeoutput/example/fortran/subplot_demo/make example ARGS="subplot_demo"

Polynomial Growth Comparison
x^3
+------------------------------------------------------------------------------------------+
| Linear Quadratic Cubic |
| |
| 10 100 | |
| | -- | - | - |
| | -- | -- | -- |
| 8 -- 80 -- 800 - |
| | -- | -- | -- |
| | -- 60 - 600 - |
| 6 -- | -- | -- |
| | -- | -- | -- |
| 4 -- 40 -- 400 -- |
| | -- | -- | -- |
| | -- | -- | -- |
| 2 -- 20 --- 200 -- |
| | -- | --- | --- |
| 0-- 0----- 0-------- |
| ++--+---+--+---+--+- ++--+--+---+--+---+ ++--+---+--+---+--+- |
| 0 2 4 6 8 10 2 4 6 8 10 2 4 6 8 10 |
| |
| |
+------------------------------------------------------------------------------------------+
x

Trigonometric and Polynomial Functions
x^2/50
+--------------------------------------------------------------------------------+
| |
| |
| Sine Wave Cosine Wave |
| |
| 1.00-- --- 1.00 -- |
| 0.75- -- -- -- 0.75 ----- |
| 0.50 -- -- - 0.50- - -- |
| 0.25 - - - 0.25-- - -- |
| 0.00 - - -- 0.00 - -- - |
| -0.25 -- -- -- -0.25-- -- -- |
| -0.50 - - - -0.50 -- - -- |
| -0.75 ----- -0.75 -- - -- - |
| ++----+----+----+---+----+- ++----+----+----+---+----+- |
| 0 2 4 6 8 10 -1.00 2 4 6 8 10 |
| -1.00 Damped Oscillation Quadratic Function |
| |
| 1.0 2.00 - |
| |-- 1.75 -- |
| 0.8 1.50 -- |
| 0.6 1.25 -- |
| 0.4- 1.00 --- |
| 0.2- ---- 0.75 --- |
| | - - ---------------- | ---- |
| 0.0-- - - 0.50 ---- |
| -0.2--- 0.25------ |
| ++----+----+----+---+----+- ++----+----+----+---+----+- |
| 0 2 4 6 8 10 0.00 2 4 6 8 10 |
| -0.4 |
| |
| |
+--------------------------------------------------------------------------------+
x