add_bar Subroutine

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

Add a bar plot.

Type Bound

pyplot

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)


Calls

proc~~add_bar~~CallsGraph proc~add_bar pyplot_module::pyplot%add_bar proc~add_str pyplot_module::pyplot%add_str proc~add_bar->proc~add_str proc~vec_to_string pyplot_module::vec_to_string proc~add_bar->proc~vec_to_string

Source Code

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

    class(pyplot),          intent(inout)         :: me            !! pyplot handler
    real(wp), dimension(:), intent(in)            :: x             !! x bar values
    real(wp), dimension(:), intent(in)            :: height        !! height bar values
    character(len=*),       intent(in)            :: label         !! plot label
    real(wp), dimension(:), intent(in),  optional :: width         !! width values
    real(wp), dimension(:), intent(in),  optional :: bottom        !! bottom values
    character(len=*),       intent(in),  optional :: color         !! plot color
    real(wp), dimension(:), intent(in),  optional :: yerr          !! yerr values
    character(len=*),       intent(in),  optional :: align         !! default: 'center'
    real(wp),dimension(2),  intent (in), optional :: xlim          !! x-axis range
    real(wp),dimension(2),  intent (in), optional :: 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)

    character(len=:), allocatable :: xstr               !! x axis values stringified
    character(len=:), allocatable :: ystr               !! y axis values stringified
    character(len=:), allocatable :: xlimstr            !! xlim values stringified
    character(len=:), allocatable :: ylimstr            !! ylim values stringified
    character(len=:), allocatable :: wstr               !! width values stringified
    character(len=:), allocatable :: bstr               !! bottom values stringified
    character(len=:), allocatable :: plt_str            !! plot string
    character(len=:), allocatable :: yerr_str           !!  yerr values stringified
    character(len=*), parameter   :: xname = 'x'        !! x axis name
    character(len=*), parameter   :: yname = 'y'        !! y axis name
    character(len=*), parameter   :: wname = 'w'        !! width name
    character(len=*), parameter   :: bname = 'b'        !! bottom name
    character(len=*), parameter   :: yerrname = 'yerr'  !! yerr name

    if (allocated(me%str)) then

        if (present(istat)) istat = 0

        !axis limits (optional):
        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 vec_to_string(x,      me%real_fmt, xstr,     me%use_numpy)
                             call vec_to_string(height, me%real_fmt, ystr,     me%use_numpy)
        if (present(width))  call vec_to_string(width,  me%real_fmt, wstr,     me%use_numpy)
        if (present(bottom)) call vec_to_string(bottom, me%real_fmt, bstr,     me%use_numpy)
        if (present(yerr))   call vec_to_string(yerr,   me%real_fmt, yerr_str, me%use_numpy)

        !write the arrays:
                             call me%add_str(trim(xname)//' = '//xstr)
                             call me%add_str(trim(yname)//' = '//ystr)
        if (present(width))  call me%add_str(trim(wname)//' = '//wstr)
        if (present(bottom)) call me%add_str(trim(bname)//' = '//bstr)
        if (present(yerr))   call me%add_str(trim(yerrname)//' = '//yerr_str)
        call me%add_str('')

        !create the plot string:
        plt_str = 'ax.bar('//&
                  'x='//trim(xname)//','//&
                  'height='//trim(yname)//','
        if (present(yerr))   plt_str=plt_str//'yerr='//trim(yerrname)//','
        if (present(width))  plt_str=plt_str//'width='//trim(wname)//','
        if (present(bottom)) plt_str=plt_str//'bottom='//trim(bstr)//','
        if (present(color))  plt_str=plt_str//'color='//trim(me%raw_str_token)//'"'//trim(color)//'",'
        if (present(align))  plt_str=plt_str//'align='//trim(me%raw_str_token)//'"'//trim(align)//'",'
        plt_str=plt_str//'label='//trim(me%raw_str_token)//'"'//trim(label)//'")'

        !write the plot statement:
        call me%add_str(plt_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//')')

        !axis scales:
        if (present(xscale)) call me%add_str('ax.set_xscale('//trim(me%raw_str_token)//'"'//xscale//'")')
        if (present(yscale)) call me%add_str('ax.set_yscale('//trim(me%raw_str_token)//'"'//yscale//'")')

        call me%add_str('')

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

    end subroutine add_bar