@@ -53,6 +53,7 @@ module pyplot_module
5353 procedure , public :: add_3d_plot ! ! add a 3d plot to pyplot instance
5454 procedure , public :: add_contour ! ! add a contour plot to pyplot instance
5555 procedure , public :: add_bar ! ! add a barplot to pyplot instance
56+ procedure , public :: add_imshow ! ! add an image plot (using `imshow`)
5657
5758 procedure , public :: savefig ! ! save plots of pyplot instance
5859 procedure , public :: destroy ! ! destroy pyplot instance
@@ -453,7 +454,8 @@ end subroutine add_3d_plot
453454!
454455! Add a bar plot.
455456
456- subroutine add_bar (me , left , height , label , width , bottom , color , yerr , align , xlim , ylim , xscale , yscale )
457+ subroutine add_bar (me , left , height , label , width , bottom , color , &
458+ yerr , align , xlim , ylim , xscale , yscale )
457459
458460 class(pyplot), intent (inout ) :: me ! ! pyplot handler
459461 real (wp), dimension (:), intent (in ) :: left ! ! left bar values
@@ -535,6 +537,54 @@ subroutine add_bar(me, left, height, label, width, bottom, color, yerr, align, x
535537 end subroutine add_bar
536538! *****************************************************************************************
537539
540+ ! *****************************************************************************************
541+ ! >
542+ ! Add an image plot using `imshow`.
543+ !
544+ ! ### Note
545+ ! * Based on code by Ricardo Torres, 4/2/2017.
546+
547+ subroutine add_imshow (me , x , xlim , ylim )
548+
549+ class(pyplot), intent (inout ) :: me ! ! pyplot handler
550+ real (wp),dimension (:,:),intent (in ) :: x ! ! x values
551+ real (wp),dimension (2 ), intent (in ), optional :: xlim ! ! x-axis range
552+ real (wp),dimension (2 ), intent (in ), optional :: ylim ! ! y-axis range
553+
554+ character (len= :), allocatable :: xstr ! ! x values stringified
555+ character (len=* ), parameter :: xname = ' x' ! ! x variable name for script
556+
557+ ! axis limits (optional):
558+ character (len= :), allocatable :: xlimstr ! ! xlim values stringified
559+ character (len= :), allocatable :: ylimstr ! ! ylim values stringified
560+
561+ if (allocated (me% str)) then
562+
563+ if (present (xlim)) call vec_to_string(xlim, me% real_fmt, xlimstr, me% use_numpy)
564+ if (present (ylim)) call vec_to_string(ylim, me% real_fmt, ylimstr, me% use_numpy)
565+
566+ ! convert the arrays to strings:
567+ call matrix_to_string(x, me% real_fmt, xstr, me% use_numpy)
568+
569+ ! write the arrays:
570+ call me% add_str(trim (xname)// ' = ' // xstr)
571+ call me% add_str(' ' )
572+
573+ ! write the plot statement:
574+ call me% add_str(' ax.imshow(' // trim (xname)// ' )' )
575+ call me% add_str(' ' )
576+
577+ ! axis limits:
578+ if (allocated (xlimstr)) call me% add_str(' ax.set_xlim(' // xlimstr// ' )' )
579+ if (allocated (ylimstr)) call me% add_str(' ax.set_ylim(' // ylimstr// ' )' )
580+
581+ else
582+ error stop ' Error in add_imshow: pyplot class not properly initialized.'
583+ end if
584+
585+ end subroutine add_imshow
586+ ! *****************************************************************************************
587+
538588! *****************************************************************************************
539589! > author: Jacob Williams
540590!
0 commit comments