fortplot_figure_colorbar Module

Stateful colorbar rendering (matplotlib-style).

Implements: - Plot-area splitting for right/left/top/bottom colorbar placement - Scalar-mappable detection (pcolormesh/scatter/contour) - Gradient rendering + ticks/labels using existing primitives



Functions

public pure function colorbar_tick_target(vertical, plot_area) result(target)

Target tick count for the colorbar long axis, sized to the bar's pixel length like matplotlib's length-aware MaxNLocator. matplotlib allows roughly one tick per ~40 px (its default ~0.4 in spacing at 100 dpi), then snaps to a nice step. A fixed count (e.g. 5) yields coarse steps (0.5) on tall bars where matplotlib renders 0.2.

Arguments

Type IntentOptional Attributes Name
logical, intent(in) :: vertical
type(plot_area_t), intent(in) :: plot_area

Return Value integer


Subroutines

public subroutine prepare_colorbar_layout(backend, location, fraction, pad, shrink, saved_area, main_area, colorbar_area, supported)

Arguments

Type IntentOptional Attributes Name
class(plot_context), intent(inout) :: backend
character(len=*), intent(in) :: location
real(kind=wp), intent(in) :: fraction
real(kind=wp), intent(in) :: pad
real(kind=wp), intent(in) :: shrink
type(plot_area_t), intent(out) :: saved_area
type(plot_area_t), intent(out) :: main_area
type(plot_area_t), intent(out) :: colorbar_area
logical, intent(out) :: supported

public subroutine resolve_colorbar_mappable(plots, plot_count, preferred_index, plot_index, vmin, vmax, colormap, ok)

Arguments

Type IntentOptional Attributes Name
type(plot_data_t), intent(in) :: plots(:)
integer, intent(in) :: plot_count
integer, intent(in) :: preferred_index
integer, intent(out) :: plot_index
real(kind=wp), intent(out) :: vmin
real(kind=wp), intent(out) :: vmax
character(len=20), intent(out) :: colormap
logical, intent(out) :: ok

public subroutine render_colorbar(backend, plot_area, vmin, vmax, colormap, location, label, custom_ticks, custom_ticklabels, label_fontsize, line_levels, line_width)

Arguments

Type IntentOptional Attributes Name
class(plot_context), intent(inout) :: backend
type(plot_area_t), intent(in) :: plot_area
real(kind=wp), intent(in) :: vmin
real(kind=wp), intent(in) :: vmax
character(len=*), intent(in) :: colormap
character(len=*), intent(in) :: location
character(len=*), intent(in), optional :: label
real(kind=wp), intent(in), optional :: custom_ticks(:)
character(len=*), intent(in), optional :: custom_ticklabels(:)
real(kind=wp), intent(in), optional :: label_fontsize
real(kind=wp), intent(in), optional :: line_levels(:)
real(kind=wp), intent(in), optional :: line_width

public subroutine colorbar_auto_tick_labels(vmin, vmax, target_ticks, ticks, labels, n)

Automatic colorbar ticks inside [vmin, vmax] and their labels.

Arguments

Type IntentOptional Attributes Name
real(kind=wp), intent(in) :: vmin
real(kind=wp), intent(in) :: vmax
integer, intent(in) :: target_ticks
real(kind=wp), intent(out) :: ticks(40)
character(len=50), intent(out) :: labels(40)
integer, intent(out) :: n