For making simple x-y plots from Fortran. It works by generating a Python script and executing it.
Note
The default real kind (wp
) can be
changed using optional preprocessor flags.
This library was built with real kind:
real(kind=real64)
[8 bytes]
Type | Visibility | Attributes | Name | Initial | |||
---|---|---|---|---|---|---|---|
integer, | public, | parameter | :: | pyplot_wp | = | real64 |
real kind used by this module [8 bytes] |
integer, | private, | parameter | :: | wp | = | pyplot_wp |
local copy of |
character(len=*), | private, | parameter | :: | tmp_file | = | 'pyplot_module_temp_1234567890.py' |
Default name of the temporary file (this can also be user-specified). |
character(len=*), | private, | parameter | :: | python_exe | = | 'python' |
The python executable name. |
character(len=*), | private, | parameter | :: | int_fmt | = | '(I10)' |
integer format string |
integer, | private, | parameter | :: | max_int_len | = | 10 |
max string length for integers |
character(len=*), | private, | parameter | :: | real_fmt_default | = | '(E30.16)' |
default real number format string |
integer, | private, | parameter | :: | max_real_len | = | 60 |
max string length for reals |
The main pyplot class.
Type | Visibility | Attributes | Name | Initial | |||
---|---|---|---|---|---|---|---|
character(len=:), | private, | allocatable | :: | str |
string buffer |
||
character(len=1), | private | :: | raw_str_token | = | ' ' |
will be 'r' if using raw strings |
|
logical, | private | :: | show_legend | = | .false. |
show legend into plot |
|
logical, | private | :: | use_numpy | = | .true. |
use numpy python module |
|
logical, | private | :: | use_oo_api | = | .false. |
use OO interface of matplotlib (incopatible with showfig subroutine) |
|
logical, | private | :: | mplot3d | = | .false. |
it is a 3d plot |
|
logical, | private | :: | polar | = | .false. |
it is a polar plot |
|
logical, | private | :: | axis_equal | = | .false. |
equal scale on each axis |
|
logical, | private | :: | axisbelow | = | .true. |
axis below other chart elements |
|
logical, | private | :: | tight_layout | = | .false. |
tight layout option |
|
logical, | private | :: | usetex | = | .false. |
enable LaTeX |
|
character(len=:), | private, | allocatable | :: | xaxis_date_fmt |
date format for the x-axis. Example: |
||
character(len=:), | private, | allocatable | :: | yaxis_date_fmt |
date format for the y-axis. Example: |
||
character(len=:), | private, | allocatable | :: | real_fmt |
real number formatting |
procedure, public :: initialize | ../../ initialize pyplot instance |
procedure, public :: add_plot | ../../ add a 2d plot to pyplot instance |
procedure, public :: add_errorbar | ../../ add a 2d error bar plot to pyplot instance |
procedure, public :: add_3d_plot | ../../ add a 3d plot to pyplot instance |
procedure, public :: add_sphere | ../../ add a 3d sphere to pyplot instance |
procedure, public :: add_contour | ../../ add a contour plot to pyplot instance |
procedure, public :: plot_wireframe | ../../ add a wireframe plot to pyplot instance |
procedure, public :: plot_surface | ../../ add a surface plot to pyplot instance |
procedure, public :: add_bar | ../../ add a barplot to pyplot instance |
procedure, public :: add_imshow | ../../ add an image plot (using |
procedure, public :: add_hist | ../../ add a histogram plot to pyplot instance |
procedure, public :: savefig | ../../ save plots of pyplot instance |
procedure, public :: showfig | ../../ show plots of pyplot instance |
procedure, public :: destroy | ../../ destroy pyplot instance |
procedure, public :: execute | ../../ execute pyplot commands |
procedure, public :: add_str | ../../ add string to pytplot instance buffer |
procedure, public :: finish_ops | ../../ some final ops before saving |
Destructor.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(pyplot), | intent(inout) | :: | me |
pyplot handler |
Add a string to the buffer.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(pyplot), | intent(inout) | :: | me |
pyplot handler |
||
character(len=*), | intent(in) | :: | str |
str to be added to pyplot handler buffer |
Initialize a plot
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(pyplot), | intent(inout) | :: | me |
pyplot handler |
||
logical, | intent(in), | optional | :: | grid |
activate grid drawing |
|
character(len=*), | intent(in), | optional | :: | xlabel |
label of x axis |
|
character(len=*), | intent(in), | optional | :: | ylabel |
label of y axis |
|
character(len=*), | intent(in), | optional | :: | zlabel |
label of z axis |
|
character(len=*), | intent(in), | optional | :: | title |
plot title |
|
logical, | intent(in), | optional | :: | legend |
plot legend |
|
logical, | intent(in), | optional | :: | use_numpy |
activate usage of numpy python module |
|
integer, | intent(in), | optional, | dimension(2) | :: | figsize |
dimension of the figure |
integer, | intent(in), | optional | :: | font_size |
font size |
|
integer, | intent(in), | optional | :: | axes_labelsize |
size of axis labels |
|
integer, | intent(in), | optional | :: | xtick_labelsize |
size of x axis tick lables |
|
integer, | intent(in), | optional | :: | ytick_labelsize |
size of y axis tick lables |
|
integer, | intent(in), | optional | :: | ztick_labelsize |
size of z axis tick lables |
|
integer, | intent(in), | optional | :: | legend_fontsize |
size of legend font |
|
logical, | intent(in), | optional | :: | mplot3d |
set true for 3d plots (cannot use with polar) |
|
logical, | intent(in), | optional | :: | axis_equal |
set true for axis = 'equal' |
|
logical, | intent(in), | optional | :: | polar |
set true for polar plots (cannot use with mplot3d) |
|
character(len=*), | intent(in), | optional | :: | real_fmt |
format string for real numbers (examples: '(E30.16)' [default], '*') |
|
logical, | intent(in), | optional | :: | use_oo_api |
avoid matplotlib's GUI by using the OO interface (cannot use with showfig) |
|
logical, | intent(in), | optional | :: | axisbelow |
to put the grid lines below the other chart elements [default is true] |
|
logical, | intent(in), | optional | :: | tight_layout |
enable tight layout [default is false] |
|
logical, | intent(in), | optional | :: | raw_strings |
if True, all strings sent to Python are treated as raw strings (e.g., r'str'). Default is False. |
|
logical, | intent(in), | optional | :: | usetex |
if True, enable LaTeX. (default if false) |
|
character(len=*), | intent(in), | optional | :: | xaxis_date_fmt |
if present, used to set the date format for the x-axis |
|
character(len=*), | intent(in), | optional | :: | yaxis_date_fmt |
if present, used to set the date format for the y-axis |
Add an x,y plot.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(pyplot), | intent(inout) | :: | me |
pyplot handler |
||
real(kind=wp), | intent(in), | dimension(:) | :: | x |
x values |
|
real(kind=wp), | intent(in), | dimension(:) | :: | y |
y values |
|
character(len=*), | intent(in) | :: | label |
plot label |
||
character(len=*), | intent(in) | :: | linestyle |
style of the plot line |
||
integer, | intent(in), | optional | :: | markersize |
size of the plot markers |
|
integer, | intent(in), | optional | :: | linewidth |
width of the plot line |
|
real(kind=wp), | intent(in), | optional, | dimension(2) | :: | xlim |
x-axis range |
real(kind=wp), | intent(in), | optional, | dimension(2) | :: | ylim |
y-axis range |
character(len=*), | intent(in), | optional | :: | xscale |
example: 'linear' (default), 'log' |
|
character(len=*), | intent(in), | optional | :: | yscale |
example: 'linear' (default), 'log' |
|
real(kind=wp), | intent(in), | optional, | dimension(:) | :: | color |
RGB color tuple [0-1,0-1,0-1] |
integer, | intent(out), | optional | :: | istat |
status output (0 means no problems) |
Add a histogram plot.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(pyplot), | intent(inout) | :: | me |
pyplot handler |
||
real(kind=wp), | intent(in), | dimension(:) | :: | x |
array of data |
|
character(len=*), | intent(in) | :: | label |
plot label |
||
real(kind=wp), | intent(in), | optional, | dimension(2) | :: | xlim |
x-axis range |
real(kind=wp), | intent(in), | optional, | dimension(2) | :: | ylim |
y-axis range |
character(len=*), | intent(in), | optional | :: | xscale |
example: 'linear' (default), 'log' |
|
character(len=*), | intent(in), | optional | :: | yscale |
example: 'linear' (default), 'log' |
|
integer, | intent(in), | optional | :: | bins |
number of bins |
|
logical, | intent(in), | optional | :: | normed |
boolean flag that determines whether bin counts are normalized [NO LONGER USED] |
|
logical, | intent(in), | optional | :: | cumulative |
boolean flag that determines whether histogram represents the cumulative density of dataset |
|
integer, | intent(out), | optional | :: | istat |
status output (0 means no problems) |
Add a contour plot.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(pyplot), | intent(inout) | :: | me |
pyplot handler |
||
real(kind=wp), | intent(in), | dimension(:) | :: | x |
x values |
|
real(kind=wp), | intent(in), | dimension(:) | :: | y |
y values |
|
real(kind=wp), | intent(in), | dimension(:,:) | :: | z |
z values (a matrix) |
|
character(len=*), | intent(in) | :: | linestyle |
style of the plot line |
||
integer, | intent(in), | optional | :: | linewidth |
width of the plot line [only used when |
|
real(kind=wp), | intent(in), | optional, | dimension(:) | :: | levels |
contour levels to plot |
character(len=*), | intent(in), | optional | :: | color |
color of the contour line |
|
logical, | intent(in), | optional | :: | filled |
use filled control (default=False) |
|
character(len=*), | intent(in), | optional | :: | cmap |
colormap if filled=True (examples: 'jet', 'bone') |
|
logical, | intent(in), | optional | :: | colorbar |
add a colorbar (default=False) |
|
integer, | intent(out), | optional | :: | istat |
status output (0 means no problems) |
Add a surface plot.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(pyplot), | intent(inout) | :: | me |
pyplot handler |
||
real(kind=wp), | intent(in), | dimension(:) | :: | x |
x values |
|
real(kind=wp), | intent(in), | dimension(:) | :: | y |
y values |
|
real(kind=wp), | intent(in), | dimension(:,:) | :: | z |
z values (a matrix) |
|
character(len=*), | intent(in) | :: | label |
plot label |
||
character(len=*), | intent(in) | :: | linestyle |
style of the plot line |
||
integer, | intent(in), | optional | :: | linewidth |
width of the plot line |
|
real(kind=wp), | intent(in), | optional, | dimension(:) | :: | levels |
contour levels to plot |
character(len=*), | intent(in), | optional | :: | color |
Color of the surface patches |
|
character(len=*), | intent(in), | optional | :: | cmap |
colormap if filled=True (examples: 'jet', 'bone') |
|
logical, | intent(in), | optional | :: | colorbar |
add a colorbar (default=False) |
|
logical, | intent(in), | optional | :: | antialiased |
The surface is made opaque by using antialiased=False |
|
integer, | intent(out), | optional | :: | istat |
status output (0 means no problems) |
Add a wireframe plot.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(pyplot), | intent(inout) | :: | me |
pyplot handler |
||
real(kind=wp), | intent(in), | dimension(:) | :: | x |
x values |
|
real(kind=wp), | intent(in), | dimension(:) | :: | y |
y values |
|
real(kind=wp), | intent(in), | dimension(:,:) | :: | z |
z values (a matrix) |
|
character(len=*), | intent(in) | :: | label |
plot label |
||
character(len=*), | intent(in) | :: | linestyle |
style of the plot line |
||
integer, | intent(in), | optional | :: | linewidth |
width of the plot line |
|
real(kind=wp), | intent(in), | optional, | dimension(:) | :: | levels |
contour levels to plot |
character(len=*), | intent(in), | optional | :: | color |
Color of the surface patches |
|
character(len=*), | intent(in), | optional | :: | cmap |
colormap if filled=True (examples: 'jet', 'bone') |
|
logical, | intent(in), | optional | :: | colorbar |
add a colorbar (default=False) |
|
logical, | intent(in), | optional | :: | antialiased |
The surface is made opaque by using antialiased=False |
|
integer, | intent(out), | optional | :: | istat |
status output (0 means no problems) |
Add a 3D x,y,z plot.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(pyplot), | intent(inout) | :: | me |
pyplot handler |
||
real(kind=wp), | intent(in), | dimension(:) | :: | x |
x values |
|
real(kind=wp), | intent(in), | dimension(:) | :: | y |
y values |
|
real(kind=wp), | intent(in), | dimension(:) | :: | z |
z values |
|
character(len=*), | intent(in) | :: | label |
plot label |
||
character(len=*), | intent(in) | :: | linestyle |
style of the plot line |
||
integer, | intent(in), | optional | :: | markersize |
size of the plot markers |
|
integer, | intent(in), | optional | :: | linewidth |
width of the plot line |
|
integer, | intent(out), | optional | :: | istat |
status output (0 means no problems) |
Add a sphere to a 3D x,y,z plot.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(pyplot), | intent(inout) | :: | me |
pyplot handler |
||
real(kind=wp), | intent(in) | :: | r |
radius of the sphere |
||
real(kind=wp), | intent(in) | :: | xc |
x value of sphere center |
||
real(kind=wp), | intent(in) | :: | yc |
y value of sphere center |
||
real(kind=wp), | intent(in) | :: | zc |
z value of sphere center |
||
integer, | intent(in), | optional | :: | n_facets |
[default is 100] |
|
integer, | intent(in), | optional | :: | linewidth |
line width |
|
logical, | intent(in), | optional | :: | antialiased |
enabled anti-aliasing |
|
character(len=*), | intent(in), | optional | :: | color |
color of the contour line |
|
integer, | intent(out), | optional | :: | istat |
status output (0 means no problems) |
Add a bar plot.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(pyplot), | intent(inout) | :: | me |
pyplot handler |
||
real(kind=wp), | intent(in), | dimension(:) | :: | x |
x bar values |
|
real(kind=wp), | intent(in), | dimension(:) | :: | height |
height bar values |
|
character(len=*), | intent(in) | :: | label |
plot label |
||
real(kind=wp), | intent(in), | optional, | dimension(:) | :: | width |
width values |
real(kind=wp), | intent(in), | optional, | dimension(:) | :: | bottom |
bottom values |
character(len=*), | intent(in), | optional | :: | color |
plot color |
|
real(kind=wp), | intent(in), | optional, | dimension(:) | :: | yerr |
yerr values |
character(len=*), | intent(in), | optional | :: | align |
default: 'center' |
|
real(kind=wp), | intent(in), | optional, | dimension(2) | :: | xlim |
x-axis range |
real(kind=wp), | intent(in), | optional, | dimension(2) | :: | ylim |
y-axis range |
character(len=*), | intent(in), | optional | :: | xscale |
example: 'linear' (default), 'log' |
|
character(len=*), | intent(in), | optional | :: | yscale |
example: 'linear' (default), 'log' |
|
integer, | intent(out), | optional | :: | istat |
status output (0 means no problems) |
Add an image plot using imshow
.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(pyplot), | intent(inout) | :: | me |
pyplot handler |
||
real(kind=wp), | intent(in), | dimension(:,:) | :: | x |
x values |
|
real(kind=wp), | intent(in), | optional, | dimension(2) | :: | xlim |
x-axis range |
real(kind=wp), | intent(in), | optional, | dimension(2) | :: | ylim |
y-axis range |
integer, | intent(out), | optional | :: | istat |
status output (0 means no problems) |
Add an x,y plot with errorbars.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(pyplot), | intent(inout) | :: | me |
pyplot handler |
||
real(kind=wp), | intent(in), | dimension(:) | :: | x |
x values |
|
real(kind=wp), | intent(in), | dimension(:) | :: | y |
y values |
|
character(len=*), | intent(in) | :: | label |
plot label |
||
character(len=*), | intent(in) | :: | linestyle |
style of the plot line |
||
real(kind=wp), | intent(in), | optional, | dimension(:) | :: | xerr |
x errorbar sizes |
real(kind=wp), | intent(in), | optional, | dimension(:) | :: | yerr |
y errorbar sizes |
integer, | intent(in), | optional | :: | markersize |
size of the plot markers |
|
integer, | intent(in), | optional | :: | linewidth |
width of the plot line |
|
real(kind=wp), | intent(in), | optional, | dimension(2) | :: | xlim |
x-axis range |
real(kind=wp), | intent(in), | optional, | dimension(2) | :: | ylim |
y-axis range |
character(len=*), | intent(in), | optional | :: | xscale |
example: 'linear' (default), 'log' |
|
character(len=*), | intent(in), | optional | :: | yscale |
example: 'linear' (default), 'log' |
|
real(kind=wp), | intent(in), | optional, | dimension(:) | :: | color |
RGB color tuple [0-1,0-1,0-1] |
integer, | intent(out), | optional | :: | istat |
status output (0 means no problems) |
Integer to string, specifying the default value if the optional argument is not present.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer, | intent(in), | optional | :: | int_value |
integer value |
|
character(len=*), | intent(out) | :: | string_value |
integer value stringified |
||
character(len=*), | intent(in) | :: | default_value |
default integer value |
Logical to string, specifying the default value if the optional argument is not present.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
logical, | intent(in), | optional | :: | logical_value | ||
character(len=:), | intent(out), | allocatable | :: | string_value |
integer value stringified |
|
character(len=*), | intent(in) | :: | default_value |
default integer value |
Integer to string conversion.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer, | intent(in), | optional | :: | i |
integer value |
|
character(len=*), | intent(out) | :: | s |
integer value stringified |
Real scalar to string.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=wp), | intent(in) | :: | v |
real values |
||
character(len=*), | intent(in) | :: | fmt |
real format string |
||
character(len=:), | intent(out), | allocatable | :: | str |
real values stringified |
Real vector to string.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=wp), | intent(in), | dimension(:) | :: | v |
real values |
|
character(len=*), | intent(in) | :: | fmt |
real format string |
||
character(len=:), | intent(out), | allocatable | :: | str |
real values stringified |
|
logical, | intent(in) | :: | use_numpy |
activate numpy python module usage |
||
logical, | intent(in), | optional | :: | is_tuple |
if true [default], use '()', if false use '[]' |
Real matrix (rank 2) to string.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=wp), | intent(in), | dimension(:,:) | :: | v |
real values |
|
character(len=*), | intent(in) | :: | fmt |
real format string |
||
character(len=:), | intent(out), | allocatable | :: | str |
real values stringified |
|
logical, | intent(in) | :: | use_numpy |
activate numpy python module usage |
Write the buffer to a file, and then execute it with Python.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(pyplot), | intent(inout) | :: | me |
pytplot handler |
||
character(len=*), | intent(in), | optional | :: | pyfile |
name of the python script to generate |
|
integer, | intent(out), | optional | :: | istat |
status output (0 means no problems) |
|
character(len=*), | intent(in), | optional | :: | python |
python executable to use. (by default, this is 'python') |
Some final things to add before saving or showing the figure.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(pyplot), | intent(inout) | :: | me |
pyplot handler |
Save the figure.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(pyplot), | intent(inout) | :: | me |
pyplot handler |
||
character(len=*), | intent(in) | :: | figfile |
file name for the figure |
||
character(len=*), | intent(in), | optional | :: | pyfile |
name of the Python script to generate |
|
character(len=*), | intent(in), | optional | :: | dpi |
resolution of the figure for png [note this is a string] |
|
logical, | intent(in), | optional | :: | transparent |
transparent background (T/F) |
|
character(len=*), | intent(in), | optional | :: | facecolor |
the colors of the figure rectangle |
|
character(len=*), | intent(in), | optional | :: | edgecolor |
the colors of the figure rectangle |
|
character(len=*), | intent(in), | optional | :: | orientation |
'landscape' or 'portrait' |
|
integer, | intent(out), | optional | :: | istat |
status output (0 means no problems) |
|
character(len=*), | intent(in), | optional | :: | python |
python executable to use. (by default, this is 'python') |
Shows the figure.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(pyplot), | intent(inout) | :: | me |
pyplot handler |
||
character(len=*), | intent(in), | optional | :: | pyfile |
name of the Python script to generate |
|
integer, | intent(out), | optional | :: | istat |
status output (0 means no problems) |
|
character(len=*), | intent(in), | optional | :: | python |
python executable to use. (by default, this is 'python') |