Open ardouglas opened 3 years ago
TL;DR: How about removing the bin margin? The PNG has overlapping bins and it's not really perfect either. Removing the margin gives you both histograms with the same and decent looks.
chart.draw_series(
Histogram::vertical(&chart)
.style(RED.mix(0.5).filled())
+ .margin(0)
.data(DATA.iter().map(|x: &u32| (*x, 1))),
)?;
So, here is the code where those negative width happen:
Histogram
calculated bin widths (b.0 - a.0
) to 2 or 3 px in this example. On the other hand, it also had a default left/right margin of 5 px (for each). Adding/Subtracting margin without testing caused left-right inversion (a.0 >= b.0
) here. BitMapBackend
did draw a rect as if x's are swapped, though SVGBackend
generated a negative-width (-7 or -8 px) rect.
I think plotters should detect these kinds of invalid configurations and give a warning (or an error) at least. Auto-correcting can also be beneficial, but I'm not sure how this should be corrected...
Describe the bug When generating histogram plots with the SVG backend, the widths of the rect tags are sometimes negative. The same code with the Bitmap backend produces a valid image. svg with negative rects png with normal rects
To Reproduce This code snippet reproduces the issue:
Version Information
plotters = "0.3.1"