fortplot_ticks Module

Tick generation and formatting for all scale types

This module handles all tick-related functionality including linear, logarithmic, and symmetric logarithmic tick generation, following Single Responsibility Principle by focusing solely on tick calculation and formatting.

Author: fortplot contributors



Functions

public function format_tick_value(value, range) result(formatted)

Format tick value based on data range like matplotlib

Arguments

Type IntentOptional Attributes Name
real(kind=wp), intent(in) :: value
real(kind=wp), intent(in) :: range

Return Value character(len=20)

public function format_tick_value_smart(value, max_chars) result(formatted)

Smart tick value formatting with automatic exponential notation for long labels Limits output to max_chars and uses exponential notation when needed

Arguments

Type IntentOptional Attributes Name
real(kind=wp), intent(in) :: value
integer, intent(in) :: max_chars

Return Value character(len=20)

public function format_log_tick_value(value) result(formatted)

Format logarithmic tick values using scientific notation like matplotlib

Arguments

Type IntentOptional Attributes Name
real(kind=wp), intent(in) :: value

Return Value character(len=20)

public function format_tick_value_consistent(value, decimal_places) result(formatted)

Format tick value with consistent decimal places for uniform appearance

Arguments

Type IntentOptional Attributes Name
real(kind=wp), intent(in) :: value
integer, intent(in) :: decimal_places

Return Value character(len=20)


Subroutines

public subroutine calculate_tick_labels(data_min, data_max, num_ticks, labels)

Calculate appropriate tick labels at nice locations like matplotlib Ensures all labels have consistent formatting and nice round numbers

Arguments

Type IntentOptional Attributes Name
real(kind=wp), intent(in) :: data_min
real(kind=wp), intent(in) :: data_max
integer, intent(in) :: num_ticks
character(len=20), intent(out) :: labels(:)

public subroutine calculate_tick_labels_log(data_min, data_max, num_ticks, labels)

Calculate logarithmic tick labels at powers of 10 with sub-ticks

Arguments

Type IntentOptional Attributes Name
real(kind=wp), intent(in) :: data_min
real(kind=wp), intent(in) :: data_max
integer, intent(in) :: num_ticks
character(len=20), intent(out) :: labels(:)

public subroutine calculate_tick_labels_symlog(data_min, data_max, linear_threshold, num_ticks, labels)

Calculate symlog tick labels with improved linear and log regions

Arguments

Type IntentOptional Attributes Name
real(kind=wp), intent(in) :: data_min
real(kind=wp), intent(in) :: data_max
real(kind=wp), intent(in) :: linear_threshold
integer, intent(in) :: num_ticks
character(len=20), intent(out) :: labels(:)

public subroutine calculate_nice_axis_limits(data_min, data_max, target_num_ticks, nice_min, nice_max)

Calculate nice axis limits that encompass the data like matplotlib The axis limits are set to nice round numbers based on tick locations

Arguments

Type IntentOptional Attributes Name
real(kind=wp), intent(in) :: data_min
real(kind=wp), intent(in) :: data_max
integer, intent(in) :: target_num_ticks
real(kind=wp), intent(out) :: nice_min
real(kind=wp), intent(out) :: nice_max

public subroutine find_nice_tick_locations(data_min, data_max, target_num_ticks, nice_min, nice_max, nice_step, tick_locations, actual_num_ticks)

Find nice tick locations following matplotlib's MaxNLocator algorithm exactly

Arguments

Type IntentOptional Attributes Name
real(kind=wp), intent(in) :: data_min
real(kind=wp), intent(in) :: data_max
integer, intent(in) :: target_num_ticks
real(kind=wp), intent(out) :: nice_min
real(kind=wp), intent(out) :: nice_max
real(kind=wp), intent(out) :: nice_step
real(kind=wp), intent(out) :: tick_locations(:)
integer, intent(out) :: actual_num_ticks

public subroutine generate_scale_aware_tick_labels(data_min, data_max, num_ticks, labels, scale, threshold)

Generate tick labels based on scale type - common function for all backends

Arguments

Type IntentOptional Attributes Name
real(kind=wp), intent(in) :: data_min
real(kind=wp), intent(in) :: data_max
integer, intent(in) :: num_ticks
character(len=20), intent(out) :: labels(:)
character(len=*), intent(in), optional :: scale
real(kind=wp), intent(in), optional :: threshold