Skip to content

Commit 7f314bd

Browse files
Add regression test for histogram conversion with clamped bargap
1 parent 1fcac15 commit 7f314bd

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

plotly/matplotlylib/tests/test_renderer.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import numpy as np
12
import matplotlib.pyplot as plt
23
import plotly.tools as tls
34

@@ -98,3 +99,16 @@ def test_get_bar_gap_clamps_negative_float_noise():
9899
assert get_bar_gap([0.0, 1.0], [1.0 + 1e-15, 2.0]) == 0.0
99100
# positive gaps are unchanged
100101
assert get_bar_gap([0.0, 2.0], [1.0, 3.0]) == 1.0
102+
103+
104+
def test_histogram_converts():
105+
"""Histograms must convert without error and keep bargap in plotly's
106+
valid [0, 1] range; get_bar_gap can return a gap with floating point
107+
noise for touching bars, which plotly rejects."""
108+
fig, ax = plt.subplots()
109+
ax.hist(np.random.randn(1000), 30)
110+
111+
plotly_fig = tls.mpl_to_plotly(fig)
112+
113+
assert len(plotly_fig.data) == 1
114+
assert 0 <= plotly_fig.layout.bargap <= 1

0 commit comments

Comments
 (0)