@@ -71,6 +71,9 @@ module pyplot_module
71
71
logical :: tight_layout = .false. ! ! tight layout option
72
72
logical :: usetex = .false. ! ! enable LaTeX
73
73
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
+
74
77
character (len= :),allocatable :: real_fmt ! ! real number formatting
75
78
76
79
contains
@@ -162,7 +165,7 @@ end subroutine add_str
162
165
subroutine initialize (me , grid , xlabel , ylabel , zlabel , title , legend , use_numpy , figsize , &
163
166
font_size , axes_labelsize , xtick_labelsize , ytick_labelsize , ztick_labelsize , &
164
167
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 )
166
169
167
170
class(pyplot), intent (inout ) :: me ! ! pyplot handler
168
171
logical , intent (in ), optional :: grid ! ! activate grid drawing
@@ -189,6 +192,8 @@ subroutine initialize(me, grid, xlabel, ylabel, zlabel, title, legend, use_numpy
189
192
logical , intent (in ), optional :: raw_strings ! ! if True, all strings sent to Python are treated as
190
193
! ! raw strings (e.g., r'str'). Default is False.
191
194
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
192
197
193
198
character (len= max_int_len) :: width_str ! ! figure width dummy string
194
199
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
257
262
else
258
263
me% usetex = .false.
259
264
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
260
275
261
276
call optional_int_to_string(font_size, font_size_str, default_font_size_str)
262
277
call optional_int_to_string(axes_labelsize, axes_labelsize_str, default_font_size_str)
@@ -1401,11 +1416,11 @@ subroutine execute(me, pyfile, istat, python)
1401
1416
write (error_unit,' (A)' ) ' Error closing file: ' // trim (file)
1402
1417
else
1403
1418
1404
- if (present (python)) then
1419
+ if (present (python)) then
1405
1420
python_ = trim (python)
1406
- else
1421
+ else
1407
1422
python_ = python_exe
1408
- end if
1423
+ end if
1409
1424
1410
1425
! run the file using python:
1411
1426
if (index (file,' ' )>0 ) then
@@ -1477,6 +1492,14 @@ subroutine finish_ops(me)
1477
1492
end if
1478
1493
call me% add_str(' ' )
1479
1494
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
1480
1503
if (me% tight_layout) then
1481
1504
call me% add_str(' fig.tight_layout()' )
1482
1505
call me% add_str(' ' )
0 commit comments