subroutine initialize(me, grid, xlabel, ylabel, zlabel, title, legend, use_numpy, figsize, &
font_size, axes_labelsize, xtick_labelsize, ytick_labelsize, ztick_labelsize, &
legend_fontsize, mplot3d, axis_equal, polar, real_fmt)
class(pyplot), intent(inout) :: me !! pyplot handler
logical, intent(in), optional :: grid !! activate grid drawing
character(len=*), intent(in), optional :: xlabel !! label of x axis
character(len=*), intent(in), optional :: ylabel !! label of y axis
character(len=*), intent(in), optional :: zlabel !! label of z axis
character(len=*), intent(in), optional :: title !! plot title
logical, intent(in), optional :: legend !! plot legend
logical, intent(in), optional :: use_numpy !! activate usage of numpy python module
integer, dimension(2), intent(in), optional :: figsize !! dimension of the figure
integer, intent(in), optional :: font_size !! font size
integer, intent(in), optional :: axes_labelsize !! size of axis labels
integer, intent(in), optional :: xtick_labelsize !! size of x axis tick lables
integer, intent(in), optional :: ytick_labelsize !! size of y axis tick lables
integer, intent(in), optional :: ztick_labelsize !! size of z axis tick lables
integer, intent(in), optional :: legend_fontsize !! size of legend font
logical, intent(in), optional :: mplot3d !! set true for 3d plots (cannot use with polar)
logical, intent(in), optional :: axis_equal !! set true for axis = 'equal'
logical, intent(in), optional :: polar !! set true for polar plots (cannot use with mplot3d)
character(len=*), intent(in), optional :: real_fmt !! format string for real numbers (examples: '(E30.16)' [default], '*')
character(len=max_int_len) :: width_str !! figure width dummy string
character(len=max_int_len) :: height_str !! figure height dummy string
character(len=max_int_len) :: font_size_str !! font size dummy string
character(len=max_int_len) :: axes_labelsize_str !! size of axis labels dummy string
character(len=max_int_len) :: xtick_labelsize_str !! size of x axis tick labels dummy string
character(len=max_int_len) :: ytick_labelsize_str !! size of x axis tick labels dummy string
character(len=max_int_len) :: ztick_labelsize_str !! size of z axis tick labels dummy string
character(len=max_int_len) :: legend_fontsize_str !! size of legend font dummy string
character(len=*), parameter :: default_font_size_str = '10' !! the default font size for plots
call me%destroy()
if (present(legend)) then
me%show_legend = legend
else
me%show_legend = .false.
end if
if (present(use_numpy)) then
me%use_numpy = use_numpy
else
me%use_numpy = .true.
end if
if (present(figsize)) then
call integer_to_string(figsize(1), width_str)
call integer_to_string(figsize(2), height_str)
end if
if (present(mplot3d)) then
me%mplot3d = mplot3d
else
me%mplot3d = .false.
end if
if (present(polar)) then
me%polar = polar
else
me%polar = .false.
end if
if (present(axis_equal)) then
me%axis_equal = axis_equal
else
me%axis_equal = .false.
end if
if (present(real_fmt)) then
me%real_fmt = trim(adjustl(real_fmt))
else
me%real_fmt = real_fmt_default
end if
call optional_int_to_string(font_size, font_size_str, default_font_size_str)
call optional_int_to_string(axes_labelsize, axes_labelsize_str, default_font_size_str)
call optional_int_to_string(xtick_labelsize, xtick_labelsize_str, default_font_size_str)
call optional_int_to_string(ytick_labelsize, ytick_labelsize_str, default_font_size_str)
call optional_int_to_string(ztick_labelsize, ztick_labelsize_str, default_font_size_str)
call optional_int_to_string(legend_fontsize, legend_fontsize_str, default_font_size_str)
me%str = ''
call me%add_str('#!/usr/bin/env python')
call me%add_str('')
call me%add_str('import matplotlib')
call me%add_str('import matplotlib.pyplot as plt')
if (me%mplot3d) call me%add_str('from mpl_toolkits.mplot3d import Axes3D')
if (me%use_numpy) call me%add_str('import numpy as np')
call me%add_str('')
call me%add_str('matplotlib.rcParams["font.family"] = "Serif"')
call me%add_str('matplotlib.rcParams["font.size"] = '//trim(font_size_str))
call me%add_str('matplotlib.rcParams["axes.labelsize"] = '//trim(axes_labelsize_str))
call me%add_str('matplotlib.rcParams["xtick.labelsize"] = '//trim(xtick_labelsize_str))
call me%add_str('matplotlib.rcParams["ytick.labelsize"] = '//trim(ytick_labelsize_str))
call me%add_str('matplotlib.rcParams["legend.fontsize"] = '//trim(legend_fontsize_str))
call me%add_str('')
if (present(figsize)) then !if specifying the figure size
call me%add_str('fig = plt.figure(figsize=('//trim(width_str)//','//trim(height_str)//'))')
else
call me%add_str('fig = plt.figure()')
end if
if (me%mplot3d) then
call me%add_str('ax = fig.gca(projection=''3d'')')
elseif (me%polar) then
call me%add_str('ax = fig.gca(projection=''polar'')')
else
call me%add_str('ax = fig.gca()')
end if
if (present(grid)) then
if (grid) call me%add_str('ax.grid()')
end if
if (present(xlabel)) call me%add_str('ax.set_xlabel("'//trim(xlabel)//'")')
if (present(ylabel)) call me%add_str('ax.set_ylabel("'//trim(ylabel)//'")')
if (present(zlabel)) call me%add_str('ax.set_zlabel("'//trim(zlabel)//'")')
if (present(title)) call me%add_str('ax.set_title("' //trim(title) //'")')
call me%add_str('')
end subroutine initialize