savefig Subroutine

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

Save the figure.

History

  • modified: Johannes Rieke 6/16/2017
  • modified: Jacob Williams 6/16/2017

Type Bound

pyplot

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


Calls

proc~~savefig~~CallsGraph proc~savefig pyplot%savefig proc~add_str pyplot%add_str proc~savefig->proc~add_str proc~execute pyplot%execute proc~savefig->proc~execute proc~finish_ops pyplot%finish_ops proc~savefig->proc~finish_ops proc~finish_ops->proc~add_str

Source Code

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

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

    character(len=:),allocatable :: tmp  !! for building the `savefig` arguments.

    if (allocated(me%str)) then

        if (present(istat)) istat = 0

        !finish up the string:
        call me%finish_ops()

        !build the savefig arguments:
        tmp = trim(me%raw_str_token)//'"'//trim(figfile)//'"'
        if (present(dpi)) tmp = tmp//', dpi='//trim(dpi)
        if (present(transparent)) then
            if (transparent) then
                tmp = tmp//', transparent=True'
            else
                tmp = tmp//', transparent=False'
            end if
        end if
        if (present(facecolor)) tmp = tmp//', facecolor="'//trim(facecolor)//'"'
        if (present(edgecolor)) tmp = tmp//', edgecolor="'//trim(edgecolor)//'"'
        if (present(orientation)) tmp = tmp//', orientation="'//trim(orientation)//'"'
        if (me%use_oo_api) then
            call me%add_str('canvas = FigureCanvas(fig)')
            call me%add_str('canvas.print_figure('//tmp//')')
        else
            call me%add_str('plt.savefig('//tmp//')')
        endif
        deallocate(tmp)

        !run it:
        call me%execute(pyfile, istat=istat, python=python)

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

    end subroutine savefig