Skip to content

Commit

Permalink
added tight_layout. Fixes #18
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobwilliams committed Mar 5, 2018
1 parent 797d74b commit fd73436
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
14 changes: 13 additions & 1 deletion src/pyplot_module.f90
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ module pyplot_module
logical :: polar = .false. !! it is a polar plot
logical :: axis_equal = .false. !! equal scale on each axis
logical :: axisbelow = .true. !! axis below other chart elements
logical :: tight_layout = .false. !! tight layout option

character(len=:),allocatable :: real_fmt !! real number formatting

Expand Down Expand Up @@ -109,7 +110,8 @@ end subroutine add_str

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, use_oo_api, axisbelow)
legend_fontsize, mplot3d, axis_equal, polar, real_fmt, use_oo_api, axisbelow,&
tight_layout)

class(pyplot), intent(inout) :: me !! pyplot handler
logical, intent(in), optional :: grid !! activate grid drawing
Expand All @@ -132,6 +134,7 @@ subroutine initialize(me, grid, xlabel, ylabel, zlabel, title, legend, use_numpy
character(len=*), intent(in), optional :: real_fmt !! format string for real numbers (examples: '(E30.16)' [default], '*')
logical, intent(in), optional :: use_oo_api !! avoid matplotlib's GUI by using the OO interface (cannot use with showfig)
logical, intent(in), optional :: axisbelow !! to put the grid lines below the other chart elements [default is true]
logical, intent(in), optional :: tight_layout !! enable tight layout [default is false]

character(len=max_int_len) :: width_str !! figure width dummy string
character(len=max_int_len) :: height_str !! figure height dummy string
Expand Down Expand Up @@ -186,6 +189,11 @@ subroutine initialize(me, grid, xlabel, ylabel, zlabel, title, legend, use_numpy
else
me%real_fmt = real_fmt_default
end if
if (present(tight_layout)) then
me%tight_layout = tight_layout
else
me%tight_layout = .false.
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)
Expand Down Expand Up @@ -1096,6 +1104,10 @@ subroutine finish_ops(me)
end if
call me%add_str('')
end if
if (me%tight_layout) then
call me%add_str('fig.tight_layout()')
call me%add_str('')
end if

end subroutine finish_ops
!*****************************************************************************************
Expand Down
3 changes: 2 additions & 1 deletion src/tests/test.f90
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ program test

!2d line plot:
call plt%initialize(grid=.true.,xlabel='angle (rad)',figsize=[20,10],&
title='plot test',legend=.true.,axis_equal=.true.)
title='plot test',legend=.true.,axis_equal=.true.,&
tight_layout=.true.)
call plt%add_plot(x,sx,label='$\sin (x)$',linestyle='b-o',markersize=5,linewidth=2,istat=istat)
call plt%add_plot(x,cx,label='$\cos (x)$',linestyle='r-o',markersize=5,linewidth=2,istat=istat)
call plt%add_plot(x,tx,label='$\sin (x) \cos (x)$',linestyle='g-o',markersize=2,linewidth=1,istat=istat)
Expand Down

0 comments on commit fd73436

Please sign in to comment.