Skip to content

[BUG] Negative tick_mark_size moves labels into plot area instead of only changing tick direction #716

@chantakan

Description

@chantakan

Describe the bug

When using set_tick_mark_size with negative values, the intention is to make only the tick marks point inward (into the plot area), which is a common style in scientific papers. However, three problems occur:

  1. Labels move with tick marks: The numeric tick labels and axis descriptions also move into the plot area, instead of staying in their original positions outside the plot.

  2. Axis description overlaps with numeric labels: Because both move inward, the y-axis description ("y (nondimensional)") overlaps with the numeric tick labels.

  3. White background hides grid lines: The moved labels have a white background that covers the grid lines behind them.

Expected behavior:

  • Only the tick marks should point inward
  • Numeric labels and axis descriptions should remain outside the plot area (their normal positions)
  • Similar to matplotlib's ax.tick_params(direction='in')

Actual behavior:

  • Tick marks, numeric labels, and axis descriptions all move into the plot area
  • Labels overlap each other
  • Grid lines are hidden by white label backgrounds
Image

To Reproduce

use plotters::prelude::*;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let root = BitMapBackend::new("inward_ticks.png", (800, 600)).into_drawing_area();
    root.fill(&WHITE)?;

    let mut chart = ChartBuilder::on(&root)
        .margin(10)
        .x_label_area_size(40)
        .y_label_area_size(60)
        .build_cartesian_2d(-4.0f32..4.0f32, -4.0f32..4.0f32)?;

    chart
        .configure_mesh()
        .x_desc("x (nondimensional)")
        .y_desc("y (nondimensional)")
        .set_tick_mark_size(LabelAreaPosition::Left, -5)
        .set_tick_mark_size(LabelAreaPosition::Bottom, -5)
        .draw()?;

    root.present()?;
    Ok(())
}

Version Information

  • plotters: 0.3.7 (from crates.io)
  • rustc: 1.87.0 (17067e9ac 2025-05-09)
  • OS: Ubuntu 24.04.3 LTS

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions