@@ -43,6 +43,7 @@ module pyplot_module
4343 logical :: polar = .false. ! ! it is a polar plot
4444 logical :: axis_equal = .false. ! ! equal scale on each axis
4545 logical :: axisbelow = .true. ! ! axis below other chart elements
46+ logical :: tight_layout = .false. ! ! tight layout option
4647
4748 character (len= :),allocatable :: real_fmt ! ! real number formatting
4849
@@ -109,7 +110,8 @@ end subroutine add_str
109110
110111 subroutine initialize (me , grid , xlabel , ylabel , zlabel , title , legend , use_numpy , figsize , &
111112 font_size , axes_labelsize , xtick_labelsize , ytick_labelsize , ztick_labelsize , &
112- legend_fontsize , mplot3d , axis_equal , polar , real_fmt , use_oo_api , axisbelow )
113+ legend_fontsize , mplot3d , axis_equal , polar , real_fmt , use_oo_api , axisbelow ,&
114+ tight_layout )
113115
114116 class(pyplot), intent (inout ) :: me ! ! pyplot handler
115117 logical , intent (in ), optional :: grid ! ! activate grid drawing
@@ -132,6 +134,7 @@ subroutine initialize(me, grid, xlabel, ylabel, zlabel, title, legend, use_numpy
132134 character (len=* ), intent (in ), optional :: real_fmt ! ! format string for real numbers (examples: '(E30.16)' [default], '*')
133135 logical , intent (in ), optional :: use_oo_api ! ! avoid matplotlib's GUI by using the OO interface (cannot use with showfig)
134136 logical , intent (in ), optional :: axisbelow ! ! to put the grid lines below the other chart elements [default is true]
137+ logical , intent (in ), optional :: tight_layout ! ! enable tight layout [default is false]
135138
136139 character (len= max_int_len) :: width_str ! ! figure width dummy string
137140 character (len= max_int_len) :: height_str ! ! figure height dummy string
@@ -186,6 +189,11 @@ subroutine initialize(me, grid, xlabel, ylabel, zlabel, title, legend, use_numpy
186189 else
187190 me% real_fmt = real_fmt_default
188191 end if
192+ if (present (tight_layout)) then
193+ me% tight_layout = tight_layout
194+ else
195+ me% tight_layout = .false.
196+ end if
189197
190198 call optional_int_to_string(font_size, font_size_str, default_font_size_str)
191199 call optional_int_to_string(axes_labelsize, axes_labelsize_str, default_font_size_str)
@@ -1096,6 +1104,10 @@ subroutine finish_ops(me)
10961104 end if
10971105 call me% add_str(' ' )
10981106 end if
1107+ if (me% tight_layout) then
1108+ call me% add_str(' fig.tight_layout()' )
1109+ call me% add_str(' ' )
1110+ end if
10991111
11001112 end subroutine finish_ops
11011113! *****************************************************************************************
0 commit comments