add_imshow Subroutine

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

Add an image plot using imshow.

Note

  • Based on code by Ricardo Torres, 4/2/2017.

Type Bound

pyplot

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)


Calls

proc~~add_imshow~~CallsGraph proc~add_imshow pyplot%add_imshow proc~add_str pyplot%add_str proc~add_imshow->proc~add_str proc~matrix_to_string matrix_to_string proc~add_imshow->proc~matrix_to_string proc~vec_to_string vec_to_string proc~add_imshow->proc~vec_to_string proc~matrix_to_string->proc~vec_to_string

Source Code

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

    class(pyplot),          intent (inout) :: me            !! pyplot handler
    real(wp),dimension(:,:),intent (in)    :: x             !! x values
    real(wp),dimension(2),  intent (in), optional :: xlim   !! x-axis range
    real(wp),dimension(2),  intent (in), optional :: ylim   !! y-axis range
    integer,                intent (out),optional :: istat  !! status output (0 means no problems)

    character(len=:), allocatable :: xstr         !! x values stringified
    character(len=*), parameter   :: xname = 'x'  !! x variable name for script

    !axis limits (optional):
    character(len=:), allocatable :: xlimstr      !! xlim values stringified
    character(len=:), allocatable :: ylimstr      !! ylim values stringified

    if (allocated(me%str)) then

        if (present(istat)) istat = 0

        if (present(xlim)) call vec_to_string(xlim, me%real_fmt, xlimstr, me%use_numpy)
        if (present(ylim)) call vec_to_string(ylim, me%real_fmt, ylimstr, me%use_numpy)

        !convert the arrays to strings:
        call matrix_to_string(x, me%real_fmt, xstr, me%use_numpy)

        !write the arrays:
        call me%add_str(trim(xname)//' = '//xstr)
        call me%add_str('')

        !write the plot statement:
        call me%add_str('ax.imshow('//trim(xname)//')')
        call me%add_str('')

        !axis limits:
        if (allocated(xlimstr)) call me%add_str('ax.set_xlim('//xlimstr//')')
        if (allocated(ylimstr)) call me%add_str('ax.set_ylim('//ylimstr//')')

    else
        if (present(istat)) istat = -1
        write(error_unit,'(A)') 'Error in add_imshow: pyplot class not properly initialized.'
    end if

    end subroutine add_imshow