subroutine add_plot(me, x, y, label, linestyle, markersize, linewidth, xlim, ylim, xscale, yscale)
class(pyplot), intent (inout) :: me !! pyplot handler
real(wp), dimension(:), intent (in) :: x !! x values
real(wp), dimension(:), intent (in) :: y !! y values
character(len=*), intent (in) :: label !! plot label
character(len=*), intent (in) :: linestyle !! style of the plot line
integer, intent (in), optional :: markersize !! size of the plot markers
integer, intent (in), optional :: linewidth !! width of the plot line
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'
character(len=:), allocatable :: xstr !! x values stringified
character(len=:), allocatable :: ystr !! y values stringified
character(len=:), allocatable :: xlimstr !! xlim values stringified
character(len=:), allocatable :: ylimstr !! ylim values stringified
character(len=max_int_len) :: imark !! actual markers size
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
if (allocated(me%str)) then
!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(y, me%real_fmt, ystr, me%use_numpy)
!get optional inputs (if not present, set default value):
call optional_int_to_string(markersize, imark, '3')
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('')
!write the plot statement:
call me%add_str('ax.plot('//&
trim(xname)//','//&
trim(yname)//','//&
'"'//trim(linestyle)//'",'//&
'linewidth='//trim(adjustl(iline))//','//&
'markersize='//trim(adjustl(imark))//','//&
'label="'//trim(label)//'")')
!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("'//xscale//'")')
if (present(yscale)) call me%add_str('ax.set_yscale("'//yscale//'")')
call me%add_str('')
else
error stop 'Error in add_plot: pyplot class not properly initialized.'
end if
end subroutine add_plot