Skip to content

[BUG] HSLColor always renders as solid red, ignoring hue adjustments #696

Open
@goodguyjay

Description

@goodguyjay

Describe the bug

Drawing with HSLColor(hue, 1.0, 0.5) produces a solid red image regardless of hue.
Expected behaviour: hue 0 -> red, 120 -> green, 240 -> blue (smooth gradient).


Environment

Item Value
Plotters version 0.3.7
Rust version 1.86.0
OS / Toolchain Windows 11

I'm pulling from cargo.


To Reproduce

use plotters::prelude::*;
use plotters::style::HSLColor;

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

    // sweep hue 0° (red) -> 240° (blue) horizontally
    for x in 0..200 {
        let hue = 240.0 * x as f64 / 200.0;
        let color = HSLColor(hue, 1.0, 0.5);
        for y in 0..200 {
            root.draw_pixel((x as i32, y as i32), &color)?;
        }
    }

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

Actual output:

Image

Expected output

The same sweep converted manually HSL -> RGB shows the full spectrum:

import numpy as np, matplotlib.pyplot as plt, colorsys, imageio.v3 as iio

w = 200
img = np.zeros((w, w, 3), dtype=np.uint8)
for x in range(w):
    hue = 240.0 * x / w / 360.0          # hue in [0,1]
    r, g, b = colorsys.hls_to_rgb(hue, 0.5, 1.0)
    img[:, x] = (np.array([r, g, b]) * 255).astype(np.uint8)

iio.imwrite("expected_hsl_gradient.png", img)

Image

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