@@ -437,7 +437,8 @@ end subroutine add_hist
437437!
438438! @note This requires `use_numpy` to be True.
439439
440- subroutine add_contour (me , x , y , z , label , linestyle , linewidth , levels , color , filled , cmap , istat )
440+ subroutine add_contour (me , x , y , z , label , linestyle , linewidth , levels , color , &
441+ filled , cmap , colorbar , istat )
441442
442443 class(pyplot), intent (inout ) :: me ! ! pyplot handler
443444 real (wp),dimension (:), intent (in ) :: x ! ! x values
@@ -450,6 +451,7 @@ subroutine add_contour(me, x, y, z, label, linestyle, linewidth, levels, color,
450451 character (len=* ), intent (in ), optional :: color ! ! color of the contour line
451452 logical , intent (in ), optional :: filled ! ! use filled control (default=False)
452453 character (len=* ), intent (in ), optional :: cmap ! ! colormap if filled=True (examples: 'jet', 'bone')
454+ logical , intent (in ), optional :: colorbar ! ! add a colorbar (default=False)
453455 integer , intent (out ) :: istat ! ! status output (0 means no problems)
454456
455457 character (len= :), allocatable :: xstr ! ! x values stringified
@@ -486,8 +488,8 @@ subroutine add_contour(me, x, y, z, label, linestyle, linewidth, levels, color,
486488 call me% add_str(' ' )
487489
488490 ! convert inputs for contour plotting:
489- call me% add_str(yname_ // ' , ' // xname_ // ' = np.meshgrid(' // trim (xname)// ' , ' // trim (yname)// ' )' )
490- call me% add_str(zname_// ' = ' // zname)
491+ call me% add_str(xname_ // ' , ' // yname_ // ' = np.meshgrid(' // trim (xname)// ' , ' // trim (yname)// ' )' )
492+ call me% add_str(zname_// ' = np.transpose( ' // zname// ' ) ' )
491493
492494 ! optional arguments:
493495 extras = ' '
@@ -508,6 +510,10 @@ subroutine add_contour(me, x, y, z, label, linestyle, linewidth, levels, color,
508510 ' linestyles="' // trim (adjustl (linestyle))// ' "' // &
509511 extras// ' )' )
510512
513+ if (present (colorbar)) then
514+ if (colorbar) call me% add_str(' fig.colorbar(CS)' )
515+ end if
516+
511517 call me% add_str(' ax.clabel(CS, fontsize=9, inline=1)' )
512518 call me% add_str(' ' )
513519
0 commit comments