Skip to content

Commit 797d74b

Browse files
committed
added axisbelow option.
1 parent 26aa0b1 commit 797d74b

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/pyplot_module.f90

+10-1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ module pyplot_module
4242
logical :: mplot3d = .false. !! it is a 3d plot
4343
logical :: polar = .false. !! it is a polar plot
4444
logical :: axis_equal = .false. !! equal scale on each axis
45+
logical :: axisbelow = .true. !! axis below other chart elements
4546

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

@@ -108,7 +109,7 @@ end subroutine add_str
108109

109110
subroutine initialize(me, grid, xlabel, ylabel, zlabel, title, legend, use_numpy, figsize, &
110111
font_size, axes_labelsize, xtick_labelsize, ytick_labelsize, ztick_labelsize, &
111-
legend_fontsize, mplot3d, axis_equal, polar, real_fmt, use_oo_api)
112+
legend_fontsize, mplot3d, axis_equal, polar, real_fmt, use_oo_api, axisbelow)
112113

113114
class(pyplot), intent(inout) :: me !! pyplot handler
114115
logical, intent(in), optional :: grid !! activate grid drawing
@@ -130,6 +131,7 @@ subroutine initialize(me, grid, xlabel, ylabel, zlabel, title, legend, use_numpy
130131
logical, intent(in), optional :: polar !! set true for polar plots (cannot use with mplot3d)
131132
character(len=*), intent(in), optional :: real_fmt !! format string for real numbers (examples: '(E30.16)' [default], '*')
132133
logical, intent(in), optional :: use_oo_api !! avoid matplotlib's GUI by using the OO interface (cannot use with showfig)
134+
logical, intent(in), optional :: axisbelow !! to put the grid lines below the other chart elements [default is true]
133135

134136
character(len=max_int_len) :: width_str !! figure width dummy string
135137
character(len=max_int_len) :: height_str !! figure height dummy string
@@ -240,6 +242,13 @@ subroutine initialize(me, grid, xlabel, ylabel, zlabel, title, legend, use_numpy
240242
if (grid) call me%add_str('ax.grid()')
241243
end if
242244

245+
if (present(axisbelow)) then
246+
me%axisbelow = axisbelow
247+
else
248+
me%axisbelow = .true. ! default
249+
end if
250+
if (me%axisbelow) call me%add_str('ax.set_axisbelow(True)')
251+
243252
if (present(xlabel)) call me%add_str('ax.set_xlabel("'//trim(xlabel)//'")')
244253
if (present(ylabel)) call me%add_str('ax.set_ylabel("'//trim(ylabel)//'")')
245254
if (present(zlabel)) call me%add_str('ax.set_zlabel("'//trim(zlabel)//'")')

src/tests/test.f90

+2-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ program test
7878
end do
7979
call plt%initialize(grid=.true.,xlabel='x angle (rad)',&
8080
ylabel='y angle (rad)',figsize=[10,10],&
81-
title='Contour plot test', real_fmt='*')
81+
title='Contour plot test', real_fmt='*',&
82+
axisbelow=.false.)
8283
call plt%add_contour(x, y, z, label='contour', linestyle='-', &
8384
linewidth=2, filled=.true., cmap='bone',istat=istat)
8485
call plt%savefig('contour.png',pyfile='contour.py',istat=istat)

0 commit comments

Comments
 (0)