Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed doc/media/examples/colored_contours/ripple_jet.pdf
Binary file not shown.
Binary file removed doc/media/examples/colored_contours/ripple_jet.png
Binary file not shown.
Binary file not shown.
Binary file not shown.
8 changes: 6 additions & 2 deletions src/fortplot.f90
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ module fortplot

! Core types and constants
use fortplot_figure_core, only: figure_t
use fortplot_constants, only: EPSILON_COMPARE, EPSILON_GEOMETRY
use fortplot_constants, only: EPSILON_COMPARE, EPSILON_GEOMETRY, &
XLABEL_VERTICAL_OFFSET, YLABEL_HORIZONTAL_OFFSET, &
TICK_MARK_LENGTH, TITLE_VERTICAL_OFFSET

! Animation functionality
use fortplot_animation, only: animation_t, FuncAnimation
Expand Down Expand Up @@ -104,7 +106,9 @@ module fortplot
public :: figure_t, wp

! Numerical constants
public :: EPSILON_COMPARE, EPSILON_GEOMETRY
public :: EPSILON_COMPARE, EPSILON_GEOMETRY, &
XLABEL_VERTICAL_OFFSET, YLABEL_HORIZONTAL_OFFSET, TICK_MARK_LENGTH, &
TITLE_VERTICAL_OFFSET

! Coordinate system constants for annotations
public :: COORD_DATA, COORD_FIGURE, COORD_AXIS
Expand Down
40 changes: 40 additions & 0 deletions src/fortplot_constants.f90
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,44 @@ module fortplot_constants
!! Smaller value provides better precision for critical geometric operations.
real(wp), parameter, public :: EPSILON_GEOMETRY = 1e-12_wp

! ========================================================================
! LABEL POSITIONING CONSTANTS
! ========================================================================

!! X-axis label vertical offset below plot area (pixels)
!!
!! This constant defines the vertical distance between the bottom of the
!! plot area and the baseline of the x-axis label text.
!!
!! Used by raster backend for xlabel positioning to ensure consistent
!! spacing below tick labels while avoiding overlap.
integer, parameter, public :: XLABEL_VERTICAL_OFFSET = 30

!! Y-axis label horizontal offset from left edge (pixels)
!!
!! This constant defines the horizontal distance from the left edge of
!! the figure to the left edge of the y-axis label text.
!!
!! Used by raster backend for ylabel positioning to ensure consistent
!! left margin spacing and readability.
integer, parameter, public :: YLABEL_HORIZONTAL_OFFSET = 10

!! Tick mark length extending from axis line (pixels)
!!
!! This constant defines the length of tick marks extending from the
!! axis lines into the plot area or margin.
!!
!! Used by raster backend for drawing consistent tick marks across
!! all axes while maintaining visual hierarchy.
integer, parameter, public :: TICK_MARK_LENGTH = 5

!! Title vertical offset above plot area (pixels)
!!
!! This constant defines the vertical distance between the bottom of the
!! plot area and the baseline of the title text.
!!
!! Used by raster backend for title positioning to ensure consistent
!! spacing above the plot area while maintaining readability.
integer, parameter, public :: TITLE_VERTICAL_OFFSET = 30

end module fortplot_constants
12 changes: 7 additions & 5 deletions src/fortplot_raster.f90
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
module fortplot_raster
use iso_c_binding
use fortplot_context, only: plot_context, setup_canvas
use fortplot_constants, only: EPSILON_COMPARE, EPSILON_GEOMETRY
use fortplot_constants, only: EPSILON_COMPARE, EPSILON_GEOMETRY, &
XLABEL_VERTICAL_OFFSET, YLABEL_HORIZONTAL_OFFSET, &
TICK_MARK_LENGTH, TITLE_VERTICAL_OFFSET
use fortplot_text, only: render_text_to_image, calculate_text_width, calculate_text_height
use fortplot_latex_parser, only: process_latex_in_text
! use fortplot_unicode, only: unicode_to_ascii
Expand Down Expand Up @@ -983,7 +985,7 @@ subroutine raster_draw_axes_and_labels(this, xscale, yscale, symlog_threshold, &
call this%line(x_min, y_min, x_min, y_max)

! Generate and draw tick marks and labels
tick_length = 5 ! Tick length in pixels
tick_length = TICK_MARK_LENGTH ! Tick length in pixels

! X-axis ticks
call compute_scale_ticks(xscale, x_min, x_max, symlog_threshold, x_tick_positions, num_x_ticks)
Expand Down Expand Up @@ -1055,7 +1057,7 @@ subroutine raster_draw_axes_and_labels(this, xscale, yscale, symlog_threshold, &
text_width = calculate_text_width(trim(escaped_text))
! Center horizontally in plot area, position below tick labels
px = this%plot_area%left + this%plot_area%width / 2 - text_width / 2
py = this%plot_area%bottom + this%plot_area%height + 30 ! 30 pixels below plot area
py = this%plot_area%bottom + this%plot_area%height + XLABEL_VERTICAL_OFFSET ! Pixels below plot area
call render_text_to_image(this%raster%image_data, this%width, this%height, &
px, py, trim(escaped_text), text_r, text_g, text_b)
end if
Expand All @@ -1069,7 +1071,7 @@ subroutine raster_draw_axes_and_labels(this, xscale, yscale, symlog_threshold, &
text_width = calculate_text_width(trim(escaped_text))
text_height = calculate_text_height(trim(escaped_text))
! Position to the left of plot area, centered vertically
px = 10 ! 10 pixels from left edge
px = YLABEL_HORIZONTAL_OFFSET ! Pixels from left edge
py = this%plot_area%bottom + this%plot_area%height / 2 - text_height / 2
call render_text_to_image(this%raster%image_data, this%width, this%height, &
px, py, trim(escaped_text), text_r, text_g, text_b)
Expand Down Expand Up @@ -1128,7 +1130,7 @@ subroutine render_title_centered(this, title_text)

! Y position: above plot area (like matplotlib)
! Place title approximately 30 pixels above the plot area
title_py = real(this%plot_area%bottom - 30, wp)
title_py = real(this%plot_area%bottom - TITLE_VERTICAL_OFFSET, wp)

! Get current color and render title directly in pixel coordinates
call this%raster%get_color_bytes(r, g, b)
Expand Down
Loading