Subplot Demo

Subplot Demo

Source: subplot_demo.f90

Demonstration of subplot functionality using the stateful API.

  • 2x2 subplot grid: Four different mathematical functions arranged in a 2×2 grid
  • 1x3 subplot layout: Three polynomial functions arranged horizontally
  • Independent subplot titles and labels: Each subplot has its own title and axis labels
  • Multiple plot types: Different mathematical functions visualized in each subplot
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')
  1. Top-left: sin(x)
  2. Top-right: cos(x)
  3. Bottom-left: Damped oscillation e^(-x/2) * cos(2x)
  4. Bottom-right: Quadratic function x²/50

  5. Left: Linear function x

  6. Center: Quadratic function x²
  7. Right: Cubic function x³

Files

  • subplot_demo.f90 - Source code
  • Generated media in output/example/fortran/subplot_demo/

Running

make example ARGS="subplot_demo"

Output

Subplot 1X3 Demo

subplot_1x3_demo.png

Text backend output


                               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

Download text

Download PDF

Subplot 2X2 Demo

subplot_2x2_demo.png

Text backend output


                     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

Download text

Download PDF