pyplot Derived Type

type, public :: pyplot

The main pyplot class.


Components

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: "%m/%d/%y %H:%M:%S"

character(len=:), private, allocatable :: yaxis_date_fmt

date format for the y-axis. Example: "%m/%d/%y %H:%M:%S"

character(len=:), private, allocatable :: real_fmt

real number formatting


Type-Bound Procedures

procedure, public :: initialize

initialize pyplot instance

  • private subroutine initialize(me, grid, xlabel, ylabel, zlabel, title, legend, use_numpy, figsize, font_size, axes_labelsize, xtick_labelsize, ytick_labelsize, ztick_labelsize, legend_fontsize, mplot3d, axis_equal, polar, real_fmt, use_oo_api, axisbelow, tight_layout, raw_strings, usetex, xaxis_date_fmt, yaxis_date_fmt)

    Author
    Jacob Williams

    Initialize a plot

    Arguments

    Type IntentOptional 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

procedure, public :: add_plot

add a 2d plot to pyplot instance

  • private subroutine add_plot(me, x, y, label, linestyle, markersize, linewidth, xlim, ylim, xscale, yscale, color, istat)

    Author
    Jacob Williams

    Add an x,y plot.

    Arguments

    Type IntentOptional 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)

procedure, public :: add_errorbar

add a 2d error bar plot to pyplot instance

  • private subroutine add_errorbar(me, x, y, label, linestyle, xerr, yerr, markersize, linewidth, xlim, ylim, xscale, yscale, color, istat)

    Author
    Alexander Sandrock

    Add an x,y plot with errorbars.

    Arguments

    Type IntentOptional 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)

procedure, public :: add_3d_plot

add a 3d plot to pyplot instance

  • private subroutine add_3d_plot(me, x, y, z, label, linestyle, markersize, linewidth, istat)

    Author
    Jacob Williams

    Add a 3D x,y,z plot.

    Read more…

    Arguments

    Type IntentOptional 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)

procedure, public :: add_sphere

add a 3d sphere to pyplot instance

  • private subroutine add_sphere(me, r, xc, yc, zc, n_facets, linewidth, antialiased, color, istat)

    Author
    Jacob Williams

    Add a sphere to a 3D x,y,z plot.

    Read more…

    Arguments

    Type IntentOptional 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)

procedure, public :: add_contour

add a contour plot to pyplot instance

  • private subroutine add_contour(me, x, y, z, linestyle, linewidth, levels, color, filled, cmap, colorbar, istat)

    Author
    Jacob Williams

    Add a contour plot.

    Read more…

    Arguments

    Type IntentOptional 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 filled=False]

    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)

procedure, public :: plot_wireframe

add a wireframe plot to pyplot instance

  • private subroutine plot_wireframe(me, x, y, z, label, linestyle, linewidth, levels, color, cmap, colorbar, antialiased, istat)

    Author
    Jacob Williams

    Add a wireframe plot.

    Read more…

    Arguments

    Type IntentOptional 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)

procedure, public :: plot_surface

add a surface plot to pyplot instance

  • private subroutine plot_surface(me, x, y, z, label, linestyle, linewidth, levels, color, cmap, colorbar, antialiased, istat)

    Author
    Jacob Williams

    Add a surface plot.

    Read more…

    Arguments

    Type IntentOptional 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)

procedure, public :: add_bar

add a barplot to pyplot instance

  • private subroutine add_bar(me, x, height, label, width, bottom, color, yerr, align, xlim, ylim, xscale, yscale, istat)

    Author
    Jacob Williams

    Add a bar plot.

    Arguments

    Type IntentOptional 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)

procedure, public :: add_imshow

add an image plot (using imshow)

  • private subroutine add_imshow(me, x, xlim, ylim, istat)

    Add an image plot using imshow.

    Read more…

    Arguments

    Type IntentOptional 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)

procedure, public :: add_hist

add a histogram plot to pyplot instance

  • private subroutine add_hist(me, x, label, xlim, ylim, xscale, yscale, bins, normed, cumulative, istat)

    Author
    Jimmy Leta

    Add a histogram plot.

    Arguments

    Type IntentOptional 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)

procedure, public :: savefig

save plots of pyplot instance

  • private subroutine savefig(me, figfile, pyfile, dpi, transparent, facecolor, edgecolor, orientation, istat, python)

    Author
    Jacob Williams

    Save the figure.

    Read more…

    Arguments

    Type IntentOptional 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')

procedure, public :: showfig

show plots of pyplot instance

  • private subroutine showfig(me, pyfile, istat, python)

    Author
    Johannes Rieke
    Date
    6/16/2017

    Shows the figure.

    Arguments

    Type IntentOptional 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')

procedure, public :: destroy

destroy pyplot instance

  • private subroutine destroy(me)

    Author
    Jacob Williams

    Destructor.

    Arguments

    Type IntentOptional Attributes Name
    class(pyplot), intent(inout) :: me

    pyplot handler

procedure, public :: execute

execute pyplot commands

  • private subroutine execute(me, pyfile, istat, python)

    Author
    Jacob Williams
    Date
    8/16/2015

    Write the buffer to a file, and then execute it with Python.

    Read more…

    Arguments

    Type IntentOptional 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')

procedure, public :: add_str

add string to pytplot instance buffer

  • private subroutine add_str(me, str)

    Author
    Jacob Williams

    Add a string to the buffer.

    Arguments

    Type IntentOptional Attributes Name
    class(pyplot), intent(inout) :: me

    pyplot handler

    character(len=*), intent(in) :: str

    str to be added to pyplot handler buffer

procedure, public :: finish_ops

some final ops before saving

  • private subroutine finish_ops(me)

    Author
    Jacob Williams

    Some final things to add before saving or showing the figure.

    Arguments

    Type IntentOptional Attributes Name
    class(pyplot), intent(inout) :: me

    pyplot handler

Source Code

    type, public :: pyplot

        !!  The main pyplot class.

        private

        character(len=:), allocatable :: str !! string buffer

        character(len=1) :: raw_str_token = ' ' !! will be 'r' if using raw strings

        logical :: show_legend = .false.     !! show legend into plot
        logical :: use_numpy   = .true.      !! use numpy python module
        logical :: use_oo_api  = .false.     !! use OO interface of matplotlib (incopatible with showfig subroutine)
        logical :: mplot3d     = .false.     !! it is a 3d plot
        logical :: polar       = .false.     !! it is a polar plot
        logical :: axis_equal  = .false.     !! equal scale on each axis
        logical :: axisbelow   = .true.      !! axis below other chart elements
        logical :: tight_layout = .false.    !! tight layout option
        logical :: usetex      = .false.     !! enable LaTeX

        character(len=:),allocatable :: xaxis_date_fmt  !! date format for the x-axis. Example: `"%m/%d/%y %H:%M:%S"`
        character(len=:),allocatable :: yaxis_date_fmt  !! date format for the y-axis. Example: `"%m/%d/%y %H:%M:%S"`

        character(len=:),allocatable :: real_fmt  !! real number formatting

    contains

        ! public methods
        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 `imshow`)
        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

        ! private methods
        procedure :: execute    !! execute pyplot commands
        procedure :: add_str    !! add string to pytplot instance buffer
        procedure :: finish_ops !! some final ops before saving

    end type pyplot