plot_surface Subroutine

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

Add a surface plot.

Note

This requires use_numpy to be True.

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), 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)


Calls

proc~~plot_surface~~CallsGraph proc~plot_surface pyplot_module::pyplot%plot_surface proc~add_str pyplot_module::pyplot%add_str proc~plot_surface->proc~add_str proc~matrix_to_string pyplot_module::matrix_to_string proc~plot_surface->proc~matrix_to_string proc~optional_int_to_string pyplot_module::optional_int_to_string proc~plot_surface->proc~optional_int_to_string proc~optional_logical_to_string pyplot_module::optional_logical_to_string proc~plot_surface->proc~optional_logical_to_string proc~vec_to_string pyplot_module::vec_to_string proc~plot_surface->proc~vec_to_string proc~matrix_to_string->proc~vec_to_string proc~integer_to_string pyplot_module::integer_to_string proc~optional_int_to_string->proc~integer_to_string

Source Code

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

    class(pyplot),           intent (inout)         :: me           !! pyplot handler
    real(wp),dimension(:),   intent (in)            :: x            !! x values
    real(wp),dimension(:),   intent (in)            :: y            !! y values
    real(wp),dimension(:,:), intent (in)            :: 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(wp),dimension(:),   intent (in),  optional :: 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)

    character(len=:), allocatable :: xstr           !! x values stringified
    character(len=:), allocatable :: ystr           !! y values stringified
    character(len=:), allocatable :: zstr           !! z values stringified
    character(len=:), allocatable :: levelstr       !! levels vector stringified
    character(len=:), allocatable :: antialiasedstr !! antialiased stringified
    character(len=max_int_len)    :: iline          !! actual line width
    character(len=*), parameter   :: xname = 'x'    !! x variable name for script
    character(len=*), parameter   :: yname = 'y'    !! y variable name for script
    character(len=*), parameter   :: zname = 'z'    !! z variable name for script
    character(len=*), parameter   :: xname_ = 'X'   !! X variable name for contour
    character(len=*), parameter   :: yname_ = 'Y'   !! Y variable name for contour
    character(len=*), parameter   :: zname_ = 'Z'   !! Z variable name for contour
    character(len=:), allocatable :: extras         !! optional stuff

    if (allocated(me%str)) then

        if (present(istat)) istat = 0

        !convert the arrays to strings:
        call vec_to_string(x, me%real_fmt, xstr, me%use_numpy)
        call vec_to_string(y, me%real_fmt, ystr, me%use_numpy)
        call matrix_to_string(z, me%real_fmt, zstr, me%use_numpy)
        if (present(levels)) call vec_to_string(levels, me%real_fmt, levelstr, me%use_numpy)

        !get optional inputs (if not present, set default value):
        call optional_int_to_string(linewidth, iline, '3')
        call optional_logical_to_string(antialiased, antialiasedstr, 'False')

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

        !convert inputs for contour plotting:
        call me%add_str(xname_//', '//yname_//' = np.meshgrid('//trim(xname)//', '//trim(yname)//')')
        call me%add_str(zname_//' = np.transpose('//zname//')')

        !optional arguments:
        extras = ''
        if (present(levels))     extras = extras//','//'levels='//levelstr
        if (present(color))      extras = extras//','//'colors='//trim(me%raw_str_token)//'"'//color//'"'
        if (present(linewidth))  extras = extras//','//'linewidths='//trim(adjustl(iline))
        if (present(cmap))       extras = extras//','//'cmap='//trim(me%raw_str_token)//'"'//cmap//'"'

        !write the plot statement:
        call me%add_str('CS = ax.plot_surface'//'('//xname_//','//yname_//','//zname_//','//&
                        'label='//trim(me%raw_str_token)//'"'//trim(label)//'",'//&
                        'antialiased='//trim(antialiasedstr)//','//&
                        'linestyles='//trim(me%raw_str_token)//'"'//trim(adjustl(linestyle))//'"'//&
                        extras//')')

        if (present(colorbar)) then
            if (colorbar) call me%add_str('fig.colorbar(CS)')
        end if

        call me%add_str('')

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

    end subroutine plot_surface