@@ -557,27 +557,51 @@ end subroutine add_3d_plot
557557!
558558! @note Must initialize the class with `mplot3d=.true.` and `use_numpy=.true.`.
559559
560- subroutine add_sphere (me , r , xc , yc , zc , istat )
560+ subroutine add_sphere (me , r , xc , yc , zc , n_facets , linewidth , antialiased , color , istat )
561561
562562 implicit none
563563
564- class(pyplot), intent (inout ) :: me ! ! pyplot handler
565- real (wp), intent (in ) :: r ! ! radius of the sphere
566- real (wp), intent (in ) :: xc ! ! x value of sphere center
567- real (wp), intent (in ) :: yc ! ! y value of sphere center
568- real (wp), intent (in ) :: zc ! ! z value of sphere center
569- integer , intent (out ) :: istat ! ! status output (0 means no problems)
570-
571- character (len= :), allocatable :: rstr ! ! r value stringified
572- character (len= :), allocatable :: xcstr ! ! xc value stringified
573- character (len= :), allocatable :: ycstr ! ! yc value stringified
574- character (len= :), allocatable :: zcstr ! ! zc value stringified
575- character (len=* ), parameter :: xname = ' x' ! ! x variable name for script
576- character (len=* ), parameter :: yname = ' y' ! ! y variable name for script
577- character (len=* ), parameter :: zname = ' z' ! ! z variable name for script
564+ class(pyplot), intent (inout ) :: me ! ! pyplot handler
565+ real (wp), intent (in ) :: r ! ! radius of the sphere
566+ real (wp), intent (in ) :: xc ! ! x value of sphere center
567+ real (wp), intent (in ) :: yc ! ! y value of sphere center
568+ real (wp), intent (in ) :: zc ! ! z value of sphere center
569+ integer , intent (in ), optional :: n_facets ! ! [default is 100]
570+ integer , intent (in ), optional :: linewidth ! ! line width
571+ logical , intent (in ), optional :: antialiased ! ! enabled anti-aliasing
572+ character (len=* ), intent (in ), optional :: color ! ! color of the contour line
573+ integer , intent (out ) :: istat ! ! status output (0 means no problems)
574+
575+ character (len= :), allocatable :: rstr ! ! `r` value stringified
576+ character (len= :), allocatable :: xcstr ! ! `xc` value stringified
577+ character (len= :), allocatable :: ycstr ! ! `yc` value stringified
578+ character (len= :), allocatable :: zcstr ! ! `zc` value stringified
579+ character (len=* ), parameter :: xname = ' x' ! ! `x` variable name for script
580+ character (len=* ), parameter :: yname = ' y' ! ! `y` variable name for script
581+ character (len=* ), parameter :: zname = ' z' ! ! `z` variable name for script
582+
583+ character (len= max_int_len) :: linewidth_str ! ! `linewidth` input stringified
584+ character (len= :), allocatable :: antialiased_str ! ! `antialised` input stringified
585+ character (len= max_int_len) :: n_facets_str ! ! `n_facets` input stringified
586+ character (len= :), allocatable :: extras ! ! optional stuff string
578587
579588 if (allocated (me% str)) then
580589
590+ ! get optional inputs (if not present, set default value):
591+ call optional_int_to_string(n_facets, n_facets_str, ' 100' )
592+ extras = ' '
593+ if (present (linewidth)) then
594+ call optional_int_to_string(linewidth, linewidth_str, ' 1' )
595+ extras = extras// ' ,' // ' linewidth=' // linewidth_str
596+ end if
597+ if (present (antialiased)) then
598+ call optional_logical_to_string(antialiased, antialiased_str, ' False' )
599+ extras = extras// ' ,' // ' antialiased=' // antialiased_str
600+ end if
601+ if (present (color)) then
602+ extras = extras// ' ,' // ' color="' // trim (color)// ' "'
603+ end if
604+
581605 istat = 0
582606
583607 ! convert the arrays to strings:
@@ -586,12 +610,13 @@ subroutine add_sphere(me, r, xc, yc, zc, istat)
586610 call real_to_string(yc, me% real_fmt, ycstr)
587611 call real_to_string(zc, me% real_fmt, zcstr)
588612
589- call me% add_str(' u = np.linspace(0, 2 * np.pi, 100)' )
590- call me% add_str(' v = np.linspace(0, np.pi, 100)' )
613+ ! sphere code:
614+ call me% add_str(' u = np.linspace(0, 2 * np.pi, ' // n_facets_str// ' )' )
615+ call me% add_str(' v = np.linspace(0, np.pi, ' // n_facets_str// ' )' )
591616 call me% add_str(xname// ' = ' // xcstr// ' + ' // rstr// ' * np.outer(np.cos(u), np.sin(v))' )
592617 call me% add_str(yname// ' = ' // ycstr// ' + ' // rstr// ' * np.outer(np.sin(u), np.sin(v))' )
593618 call me% add_str(zname// ' = ' // zcstr// ' + ' // rstr// ' * np.outer(np.ones(np.size(u)), np.cos(v))' )
594- call me% add_str(' ax.plot_surface(' // xname// ' , ' // yname// ' , ' // zname// ' , color="Grey" )' )
619+ call me% add_str(' ax.plot_surface(' // xname// ' , ' // yname// ' , ' // zname// extras // ' )' )
595620 call me% add_str(' ' )
596621
597622 else
0 commit comments