Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Panic occurs when drawing with logarithmic coordinate system #532

Open
YeahhhhzZ opened this issue Jan 2, 2024 · 0 comments
Open
Labels
bug Something isn't working

Comments

@YeahhhhzZ
Copy link

Describe the bug

use plotters::prelude::*;

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

    let mut chart = ChartBuilder::on(&root)
        .caption("Example Diagram", ("sans-serif", 50).into_font())
        .margin(5)
        .x_label_area_size(30)
        .y_label_area_size(30)
        .build_cartesian_2d(0f32..10f32, (1e-6f32..1f32).log_scale())?;

    chart.configure_mesh().draw()?;

    let data = vec![
        (2f32, 1e-4f32),
        (4f32, 1e-3f32),
        (6f32, 1e-2f32),
        (8f32, 1e-1f32),
    ];

    chart.draw_series(
        data.iter()
            .map(|&(x, y)| Rectangle::new([(x - 0.5, 0.0), (x + 0.5, y)], RED.filled())),
    )?;

    Ok(())
}
thread 'main' panicked at 'attempt to add with overflow', /home/ye.li/.cargo/registry/src/index.crates.io-6f17d22bba15001f/plotters-0.3.5/src/coord/ranged1d/types/numeric.rs:263:1
stack backtrace:
   0: rust_begin_unwind
             at /rustc/eb26296b556cef10fb713a38f3d16b9886080f26/library/std/src/panicking.rs:593:5
   1: core::panicking::panic_fmt
             at /rustc/eb26296b556cef10fb713a38f3d16b9886080f26/library/core/src/panicking.rs:67:14
   2: core::panicking::panic
             at /rustc/eb26296b556cef10fb713a38f3d16b9886080f26/library/core/src/panicking.rs:117:5
   3: <plotters::coord::ranged1d::types::numeric::RangedCoordf64 as plotters::coord::ranged1d::Ranged>::map
             at /home/ye.li/.cargo/registry/src/index.crates.io-6f17d22bba15001f/plotters-0.3.5/src/coord/ranged1d/types/numeric.rs:93:28
   4: <plotters::coord::ranged1d::combinators::logarithmic::LogCoord<V> as plotters::coord::ranged1d::Ranged>::map
             at /home/ye.li/.cargo/registry/src/index.crates.io-6f17d22bba15001f/plotters-0.3.5/src/coord/ranged1d/combinators/logarithmic.rs:192:9
   5: <plotters::coord::ranged2d::cartesian::Cartesian2d<X,Y> as plotters::coord::translate::CoordTranslate>::translate
             at /home/ye.li/.cargo/registry/src/index.crates.io-6f17d22bba15001f/plotters-0.3.5/src/coord/ranged2d/cartesian.rs:119:13
   6: <plotters::element::BackendCoordOnly as plotters::element::CoordMapper>::map
             at /home/ye.li/.cargo/registry/src/index.crates.io-6f17d22bba15001f/plotters-0.3.5/src/element/mod.rs:268:23
   7: plotters::drawing::area::DrawingArea<DB,CT>::draw::{{closure}}
             at /home/ye.li/.cargo/registry/src/index.crates.io-6f17d22bba15001f/plotters-0.3.5/src/drawing/area.rs:324:13
   8: core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &mut F>::call_once
             at /rustc/eb26296b556cef10fb713a38f3d16b9886080f26/library/core/src/ops/function.rs:305:13
   9: core::option::Option<T>::map
             at /rustc/eb26296b556cef10fb713a38f3d16b9886080f26/library/core/src/option.rs:1075:29
  10: <core::iter::adapters::map::Map<I,F> as core::iter::traits::iterator::Iterator>::next
             at /rustc/eb26296b556cef10fb713a38f3d16b9886080f26/library/core/src/iter/adapters/map.rs:103:26
  11: <plotters::element::basic_shapes::Rectangle<Coord> as plotters::element::Drawable<DB>>::draw
             at /home/ye.li/.cargo/registry/src/index.crates.io-6f17d22bba15001f/plotters-0.3.5/src/element/basic_shapes.rs:180:16
  12: plotters::drawing::area::DrawingArea<DB,CT>::draw::{{closure}}
             at /home/ye.li/.cargo/registry/src/index.crates.io-6f17d22bba15001f/plotters-0.3.5/src/drawing/area.rs:326:35
  13: plotters::drawing::area::DrawingArea<DB,CT>::backend_ops
             at /home/ye.li/.cargo/registry/src/index.crates.io-6f17d22bba15001f/plotters-0.3.5/src/drawing/area.rs:282:13
  14: plotters::drawing::area::DrawingArea<DB,CT>::draw
             at /home/ye.li/.cargo/registry/src/index.crates.io-6f17d22bba15001f/plotters-0.3.5/src/drawing/area.rs:326:9
  15: plotters::chart::context::ChartContext<DB,CT>::draw_series_impl
             at /home/ye.li/.cargo/registry/src/index.crates.io-6f17d22bba15001f/plotters-0.3.5/src/chart/context.rs:104:13
  16: plotters::chart::context::ChartContext<DB,CT>::draw_series
             at /home/ye.li/.cargo/registry/src/index.crates.io-6f17d22bba15001f/plotters-0.3.5/src/chart/context.rs:131:9
  17: map_plugin_test::main
             at ./src/main.rs:25:5
  18: core::ops::function::FnOnce::call_once
             at /rustc/eb26296b556cef10fb713a38f3d16b9886080f26/library/core/src/ops/function.rs:250:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

To Reproduce

Version Information
0.3.5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant