@@ -71,6 +71,9 @@ module pyplot_module
7171 logical :: tight_layout = .false. ! ! tight layout option
7272 logical :: usetex = .false. ! ! enable LaTeX
7373
74+ character (len= :),allocatable :: xaxis_date_fmt ! ! date format for the x-axis. Example: `"%m/%d/%y %H:%M:%S"`
75+ character (len= :),allocatable :: yaxis_date_fmt ! ! date format for the y-axis. Example: `"%m/%d/%y %H:%M:%S"`
76+ 7477 character (len= :),allocatable :: real_fmt ! ! real number formatting
7578
7679 contains
@@ -162,7 +165,7 @@ end subroutine add_str
162165 subroutine initialize (me , grid , xlabel , ylabel , zlabel , title , legend , use_numpy , figsize , &
163166 font_size , axes_labelsize , xtick_labelsize , ytick_labelsize , ztick_labelsize , &
164167 legend_fontsize , mplot3d , axis_equal , polar , real_fmt , use_oo_api , axisbelow ,&
165- tight_layout , raw_strings , usetex )
168+ tight_layout , raw_strings , usetex , xaxis_date_fmt , yaxis_date_fmt )
166169
167170 class(pyplot), intent (inout ) :: me ! ! pyplot handler
168171 logical , intent (in ), optional :: grid ! ! activate grid drawing
@@ -189,6 +192,8 @@ subroutine initialize(me, grid, xlabel, ylabel, zlabel, title, legend, use_numpy
189192 logical , intent (in ), optional :: raw_strings ! ! if True, all strings sent to Python are treated as
190193 ! ! raw strings (e.g., r'str'). Default is False.
191194 logical , intent (in ), optional :: usetex ! ! if True, enable LaTeX. (default if false)
195+ character (len=* ), intent (in ), optional :: xaxis_date_fmt ! ! if present, used to set the date format for the x-axis
196+ character (len=* ), intent (in ), optional :: yaxis_date_fmt ! ! if present, used to set the date format for the y-axis
192197
193198 character (len= max_int_len) :: width_str ! ! figure width dummy string
194199 character (len= max_int_len) :: height_str ! ! figure height dummy string
@@ -257,6 +262,16 @@ subroutine initialize(me, grid, xlabel, ylabel, zlabel, title, legend, use_numpy
257262 else
258263 me% usetex = .false.
259264 end if
265+ if (present (xaxis_date_fmt)) then
266+ me% xaxis_date_fmt = xaxis_date_fmt
267+ else
268+ if (allocated (me% xaxis_date_fmt)) deallocate (me% xaxis_date_fmt)
269+ end if
270+ if (present (yaxis_date_fmt)) then
271+ me% yaxis_date_fmt = yaxis_date_fmt
272+ else
273+ if (allocated (me% yaxis_date_fmt)) deallocate (me% yaxis_date_fmt)
274+ end if
260275
261276 call optional_int_to_string(font_size, font_size_str, default_font_size_str)
262277 call optional_int_to_string(axes_labelsize, axes_labelsize_str, default_font_size_str)
@@ -1401,11 +1416,11 @@ subroutine execute(me, pyfile, istat, python)
14011416 write (error_unit,' (A)' ) ' Error closing file: ' // trim (file)
14021417 else
14031418
1404- if (present (python)) then
1419+ if (present (python)) then
14051420 python_ = trim (python)
1406- else
1421+ else
14071422 python_ = python_exe
1408- end if
1423+ end if
14091424
14101425 ! run the file using python:
14111426 if (index (file,' ' )>0 ) then
@@ -1477,6 +1492,14 @@ subroutine finish_ops(me)
14771492 end if
14781493 call me% add_str(' ' )
14791494 end if
1495+ if (allocated (me% xaxis_date_fmt) .or. allocated (me% yaxis_date_fmt)) then
1496+ call me% add_str(' from matplotlib.dates import DateFormatter' )
1497+ if (allocated (me% xaxis_date_fmt)) &
1498+ call me% add_str(' ax.xaxis.set_major_formatter(DateFormatter("' // trim (me% xaxis_date_fmt)// ' "))' )
1499+ if (allocated (me% yaxis_date_fmt)) &
1500+ call me% add_str(' ax.yaxis.set_major_formatter(DateFormatter("' // trim (me% yaxis_date_fmt)// ' "))' )
1501+ call me% add_str(' ' )
1502+ end if
14801503 if (me% tight_layout) then
14811504 call me% add_str(' fig.tight_layout()' )
14821505 call me% add_str(' ' )
0 commit comments