@@ -13,6 +13,15 @@ module fplot_plot_axis
1313 public :: y_axis
1414 public :: y2_axis
1515 public :: z_axis
16+ public :: name_value_pair
17+
18+ type name_value_pair
19+ ! ! Defines a name-value pair.
20+ character (len = :), allocatable :: name
21+ ! ! The name.
22+ real (real64) :: value
23+ ! ! The associated value.
24+ end type
1625
1726 type, abstract, extends(plot_object) :: plot_axis
1827 ! ! Defines a plot axis object.
@@ -66,6 +75,10 @@ module fplot_plot_axis
6675 ! ! The axis title x offset, in characters.
6776 integer (int32), private :: m_titleYOffset = 0
6877 ! ! The axis title y offset, in characters.
78+ logical , private :: m_useManualTicLabels = .false.
79+ ! ! Use manual (user-defined) tic labels?
80+ type (name_value_pair), private , allocatable , dimension (:) :: m_ticLabels
81+ ! ! A list of user-defined tic labels.
6982 contains
7083 procedure , public :: get_title = > pa_get_title
7184 procedure , public :: set_title = > pa_set_title
@@ -110,6 +123,12 @@ module fplot_plot_axis
110123 procedure , public :: set_title_x_offset = > pa_set_title_x_offset
111124 procedure , public :: get_title_y_offset = > pa_get_title_y_offset
112125 procedure , public :: set_title_y_offset = > pa_set_title_y_offset
126+ procedure , public :: get_use_manual_tic_labels = > &
127+ pa_get_use_manual_tic_labels
128+ procedure , public :: set_use_manual_tic_labels = > &
129+ pa_set_use_manual_tic_labels
130+ procedure , public :: get_manual_tic_labels = > pa_get_manual_tic_labels
131+ procedure , public :: set_manual_tic_labels = > pa_set_manual_tic_labels
113132 end type
114133
115134 interface
@@ -241,7 +260,8 @@ pure function pa_get_axis_limits(this) result(x)
241260! --------------------
242261 subroutine pa_set_axis_limits (this , lower , upper )
243262 ! ! Gets the axis display limits, assuming autoscaling is not
244- ! ! active for this axis.
263+ ! ! active for this axis. This routine also calls [[set_autoscale]] and
264+ ! ! sets the property value to false.
245265 class(plot_axis), intent (inout ) :: this
246266 ! ! The plot_axis object.
247267 real (real64), intent (in ) :: lower
@@ -250,6 +270,7 @@ subroutine pa_set_axis_limits(this, lower, upper)
250270 ! ! The upper display limit.
251271 this% m_limits(1 ) = min (lower, upper)
252272 this% m_limits(2 ) = max (lower, upper)
273+ call this% set_autoscale(.false. )
253274 end subroutine
254275
255276! ------------------------------------------------------------------------------
@@ -286,6 +307,8 @@ function pa_get_cmd_string(this) result(txt)
286307 real (real32) :: angle
287308 character (len = :), allocatable :: axis, fmt
288309 real (real64) :: lim(2 )
310+ integer (int32) :: i
311+ type (name_value_pair), allocatable , dimension (:) :: ticLabels
289312
290313 ! Process
291314 axis = this% get_id_string()
@@ -400,6 +423,22 @@ function pa_get_cmd_string(this) result(txt)
400423 call str% append (to_string(this% get_zero_axis_line_width()))
401424 end if
402425
426+ ! Use manual labels
427+ ticLabels = this% get_manual_tic_labels()
428+ if (this% get_use_manual_tic_labels() .and. size (ticLabels) > 0 ) then
429+ call str% append (new_line(' a' ))
430+ call str% append (" set " )
431+ call str% append (this% get_id_string() // " tics(" )
432+ do i = 1 , size (ticLabels)
433+ call str% append (' "' )
434+ call str% append (ticLabels(i)% name)
435+ call str% append (' " ' )
436+ call str% append (to_string(ticLabels(i)% value))
437+ if (i /= size (ticLabels)) call str% append (" , " )
438+ end do
439+ call str% append (" )" )
440+ end if
441+
403442 ! Output
404443 txt = char (str% to_string())
405444 end function
@@ -711,6 +750,56 @@ subroutine pa_set_title_y_offset(this, x)
711750 this% m_titleYOffset = x
712751 end subroutine
713752
753+ ! ------------------------------------------------------------------------------
754+ pure function pa_get_use_manual_tic_labels (this ) result(rst)
755+ ! ! Gets a value determining if manual tic labels should be used.
756+ class(plot_axis), intent (in ) :: this
757+ ! ! The plot_axis object.
758+ logical :: rst
759+ ! ! True if manual tic labels should be used; else, false.
760+ rst = this% m_useManualTicLabels
761+ end function
762+
763+ ! --------------------
764+ subroutine pa_set_use_manual_tic_labels (this , x )
765+ ! ! Sets a value determining if manual tic labels should be used.
766+ class(plot_axis), intent (inout ) :: this
767+ ! ! The plot_axis object.
768+ logical , intent (in ) :: x
769+ ! ! Set to true if manual tic labels should be used; else, false.
770+ this% m_useManualTicLabels = x
771+ end subroutine
772+
773+ ! ------------------------------------------------------------------------------
774+ pure function pa_get_manual_tic_labels (this ) result(rst)
775+ ! ! Gets a list of manual tic labels.
776+ class(plot_axis), intent (in ) :: this
777+ ! ! The plot_axis object.
778+ type (name_value_pair), allocatable , dimension (:) :: rst
779+ ! ! A list of name-value pairs where the name defines the label
780+ ! ! shown with the corresponding axis value.
781+ if (allocated (this% m_ticLabels)) then
782+ rst = this% m_ticLabels
783+ else
784+ allocate (rst(0 ))
785+ end if
786+ end function
787+
788+ ! --------------------
789+ subroutine pa_set_manual_tic_labels (this , x )
790+ ! ! Sets a list of manual tic labels. This routine also sets
791+ ! ! [[set_use_manual_tic_labels]] to true.
792+ class(plot_axis), intent (inout ) :: this
793+ ! ! The plot_axis object.
794+ type (name_value_pair), intent (in ), dimension (:) :: x
795+ ! ! The list of tic values with the name component representing the
796+ ! ! displayed label text and the value is the associated axis value.
797+
798+ if (allocated (this% m_ticLabels)) deallocate (this% m_ticLabels)
799+ allocate (this% m_ticLabels(size (x)), source = x)
800+ call this% set_use_manual_tic_labels(.true. )
801+ end subroutine
802+
714803! ******************************************************************************
715804! X_AXIS MEMBERS
716805! ------------------------------------------------------------------------------
0 commit comments