@@ -302,11 +302,11 @@ end subroutine add_plot
302302! *****************************************************************************************
303303
304304! *****************************************************************************************
305- ! > author: Jacob Williams
305+ ! > author: Jimmy Leta
306306!
307307! Add a histogram plot.
308308
309- subroutine add_hist (me , x , label , xlim , ylim , xscale , yscale )
309+ subroutine add_hist (me , x , label , xlim , ylim , xscale , yscale , bins , normed , cumulative )
310310
311311 class(pyplot), intent (inout ) :: me ! ! pyplot handler
312312 real (wp), dimension (:), intent (in ) :: x ! ! x values
@@ -315,11 +315,18 @@ subroutine add_hist(me, x, label, xlim, ylim, xscale, yscale)
315315 real (wp),dimension (2 ), intent (in ), optional :: ylim ! ! y-axis range
316316 character (len=* ), intent (in ), optional :: xscale ! ! example: 'linear' (default), 'log'
317317 character (len=* ), intent (in ), optional :: yscale ! ! example: 'linear' (default), 'log'
318+ integer , intent (in ), optional :: bins ! !
319+ logical , intent (in ), optional :: normed
320+ logical , intent (in ), optional :: cumulative
318321
319322 character (len= :), allocatable :: xstr ! ! x values stringified
320323 character (len= :), allocatable :: xlimstr ! ! xlim values stringified
321324 character (len= :), allocatable :: ylimstr ! ! ylim values stringified
325+ character (len= max_int_len) :: binsstr ! !
322326 character (len=* ), parameter :: xname = ' x' ! ! x variable name for script
327+ character (len= :), allocatable :: extras ! ! optional stuff
328+ character (len= 5 ) :: normedstr= ' '
329+ character (len= 5 ) :: cumulativestr= ' '
323330
324331 if (allocated (me% str)) then
325332
@@ -334,10 +341,38 @@ subroutine add_hist(me, x, label, xlim, ylim, xscale, yscale)
334341 call me% add_str(trim (xname)// ' = ' // xstr)
335342 call me% add_str(' ' )
336343
344+ ! get optional inputs (if not present, set default value):
345+ call optional_int_to_string(bins, binsstr, ' 10' )
346+
347+ ! optional arguments:
348+ if (present (bins)) extras = extras// ' ,' // ' bins="' // binsstr// ' "'
349+
350+ if (present (normed) .and. normed) then
351+ normedstr = ' True'
352+ else
353+ normedstr = ' False'
354+ end if
355+
356+ if (present (cumulative) .and. cumulative) then
357+ cumulativestr = ' True'
358+ else
359+ cumulativestr = ' False'
360+ end if
361+
337362 ! write the plot statement:
338363 call me% add_str(' ax.hist(' // &
339364 trim (xname)// ' ,' // &
340- ' label="' // trim (label)// ' ")' )
365+ ' label="' // trim (label)// ' ",' // &
366+ ' bins=' // trim (binsstr)// ' ,' // &
367+ ' cumulative=' // trim (cumulativestr)// ' ,' // &
368+ ' normed=' // trim (normedstr)// ' )' )
369+
370+ ! write the plot statement:
371+ ! call me%add_str('CS = ax.'//contourfunc//'('//xname_//','//yname_//','//zname_//','//&
372+ ! 'label="'//trim(label)//'",'//&
373+ ! 'linestyles="'//trim(adjustl(linestyle))//'"'//&
374+ ! extras//')')
375+
341376
342377 ! axis limits:
343378 if (allocated (xlimstr)) call me% add_str(' ax.set_xlim(' // xlimstr// ' )' )
0 commit comments