add_contour Subroutine

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

Arguments

Type IntentOptional AttributesName
class(pyplot), intent(inout) :: me
real(kind=wp), intent(in), dimension(:):: x
real(kind=wp), intent(in), dimension(:):: y
real(kind=wp), intent(in), dimension(:,:):: z
character(len=*), intent(in) :: label
character(len=*), intent(in) :: linestyle
integer, intent(in), optional :: linewidth
real(kind=wp), intent(in), optional dimension(:):: levels
character(len=*), intent(in), optional :: color
logical, intent(in), optional :: filled
character(len=*), intent(in), optional :: cmap

Calls

proc~~add_contour~~CallsGraph proc~add_contour add_contour proc~vec_to_string vec_to_string proc~add_contour->proc~vec_to_string proc~optional_int_to_string optional_int_to_string proc~add_contour->proc~optional_int_to_string proc~matrix_to_string matrix_to_string proc~add_contour->proc~matrix_to_string proc~integer_to_string integer_to_string proc~optional_int_to_string->proc~integer_to_string proc~matrix_to_string->proc~vec_to_string
Help

Source Code


Source Code

    subroutine add_contour(me, x, y, z, label, linestyle, linewidth, levels, color, filled, cmap)

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

    character(len=:), allocatable :: xstr          !! x values strinfied
    character(len=:), allocatable :: ystr          !! y values strinfied
    character(len=:), allocatable :: zstr          !! z values strinfied
    character(len=:), allocatable :: levelstr      !! levels vector strinfied
    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
    character(len=:), allocatable :: contourfunc   !! 'contour' or 'contourf'

    if (allocated(me%str)) then

        !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')

        !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(yname_//', '//xname_//' = np.meshgrid('//trim(xname)//', '//trim(yname)//')')
        call me%add_str(zname_//' = '//zname)

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

        !filled or regular:
        contourfunc = 'contour'  !default
        if (present(filled)) then
            if (filled) contourfunc = 'contourf'  !filled contour
        end if

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

        call me%add_str('ax.clabel(CS, fontsize=9, inline=1)')
        call me%add_str('')

    else
        error stop 'Error in add_plot: pyplot class not properly initialized.'
    end if

    end subroutine add_contour


add_3d_plot add_bar add_contour add_plot add_str bctoi_I1P bctoi_I2P bctoi_I4P bctoi_I8P bcton bctor_R16P bctor_R4P bctor_R8P bit_size bit_size bit_size_chr bit_size_R16P bit_size_R4P bit_size_R8P bstr bstr_I1P bstr_I2P bstr_I4P bstr_I8P bstr_R16P bstr_R4P bstr_R8P byte_size byte_size_chr byte_size_I1P byte_size_I2P byte_size_I4P byte_size_I8P byte_size_R16P byte_size_R4P byte_size_R8P check_endian compact_real_string compute compute compute compute compute compute compute compute compute compute create create create create create create create create create create_alpha_coefficients create_alpha_coefficients_js_constructor create_alpha_coefficients_m_constructor create_alpha_coefficients_z_constructor create_base_object create_interpolator_constructor create_interpolator_js_constructor create_optimal_weights create_optimal_weights_js_constructor create_polynomials create_polynomials_js_constructor create_smoothness_indicators create_smoothness_indicators_js_constructor ctoi_I1P ctoi_I2P ctoi_I4P ctoi_I8P cton ctor_R16P ctor_R4P ctor_R8P description description description description description description description description description description description description destroy destroy destroy destroy destroy destroy destroy destroy destroy destroy destroy_interpolator_constructor digit digit_I1 digit_I2 digit_I4 digit_I8 execute initialize integer_to_string interpolate interpolate matrix_to_string optional_int_to_string penf_init penf_print savefig str str_a_I1P str_a_I2P str_a_I4P str_a_I8P str_a_R16P str_a_R4P str_a_R8P str_bol str_I1P str_I2P str_I4P str_I8P str_R16P str_R4P str_R8P strf_I1P strf_I2P strf_I4P strf_I8P strf_R16P strf_R4P strf_R8P strz strz_I1P strz_I2P strz_I4P strz_I8P tau vec_to_string weno_exp weno_odd wenoof_create