|
| 1 | +import numpy as np |
1 | 2 | import matplotlib.pyplot as plt |
2 | 3 | import plotly.tools as tls |
3 | 4 |
|
@@ -84,3 +85,73 @@ def test_multiple_traces_native_legend(): |
84 | 85 | assert plotly_fig.data[0].mode == "lines" |
85 | 86 | assert plotly_fig.data[1].mode == "markers" |
86 | 87 | assert plotly_fig.data[2].mode == "lines+markers" |
| 88 | + |
| 89 | + |
| 90 | +def test_violinplot_bodies_are_filled_polygons(): |
| 91 | + fig, ax = plt.subplots() |
| 92 | + ax.violinplot(np.random.randn(100, 3)) |
| 93 | + plotly_fig = tls.mpl_to_plotly(fig) |
| 94 | + bodies = [t for t in plotly_fig.data if t.fill == "toself" and len(t.x) > 100] |
| 95 | + assert len(bodies) >= 3 |
| 96 | + |
| 97 | + |
| 98 | +def test_pcolor_rectangles_render(): |
| 99 | + x = np.linspace(-3, 3, 10) |
| 100 | + X, Y = np.meshgrid(x, x) |
| 101 | + fig, ax = plt.subplots() |
| 102 | + ax.pcolor(X, Y, np.sin(X) * np.cos(Y)) |
| 103 | + plotly_fig = tls.mpl_to_plotly(fig) |
| 104 | + assert len(plotly_fig.data) == 100 |
| 105 | + assert all(len(t.x) >= 4 for t in plotly_fig.data) |
| 106 | + |
| 107 | + |
| 108 | +def test_eventplot_segments_render(): |
| 109 | + fig, ax = plt.subplots() |
| 110 | + ax.eventplot([np.random.randn(20) for _ in range(5)]) |
| 111 | + plotly_fig = tls.mpl_to_plotly(fig) |
| 112 | + assert len(plotly_fig.data) == 100 |
| 113 | + |
| 114 | + |
| 115 | +def test_stackplot_areas_render(): |
| 116 | + x = np.arange(10) |
| 117 | + fig, ax = plt.subplots() |
| 118 | + ax.stackplot(x, np.random.rand(10), np.random.rand(10), np.random.rand(10)) |
| 119 | + plotly_fig = tls.mpl_to_plotly(fig) |
| 120 | + assert len(plotly_fig.data) >= 3 |
| 121 | + |
| 122 | + |
| 123 | +def test_fill_between_renders(): |
| 124 | + x = np.linspace(0, 2 * np.pi, 50) |
| 125 | + fig, ax = plt.subplots() |
| 126 | + ax.fill_between(x, np.sin(x), np.cos(x)) |
| 127 | + plotly_fig = tls.mpl_to_plotly(fig) |
| 128 | + assert len(plotly_fig.data) >= 1 |
| 129 | + |
| 130 | + |
| 131 | +def test_stem_plot_renders(): |
| 132 | + x = np.linspace(0, 2 * np.pi, 20) |
| 133 | + fig, ax = plt.subplots() |
| 134 | + ax.stem(x, np.sin(x)) |
| 135 | + plotly_fig = tls.mpl_to_plotly(fig) |
| 136 | + assert len(plotly_fig.data) >= 20 |
| 137 | + |
| 138 | + |
| 139 | +def test_contour_lines_convert(): |
| 140 | + """Contour lines used to crash with an ndarray line width.""" |
| 141 | + x = np.linspace(-3, 3, 30) |
| 142 | + X, Y = np.meshgrid(x, x) |
| 143 | + fig, ax = plt.subplots() |
| 144 | + ax.contour(X, Y, np.sin(X) * np.cos(Y), 10) |
| 145 | + plotly_fig = tls.mpl_to_plotly(fig) |
| 146 | + assert len(plotly_fig.data) > 0 |
| 147 | + |
| 148 | + |
| 149 | +def test_contourf_bands_render(): |
| 150 | + """Contourf bands (multi-subpath collections) must render as fills.""" |
| 151 | + x = np.linspace(-3, 3, 30) |
| 152 | + X, Y = np.meshgrid(x, x) |
| 153 | + fig, ax = plt.subplots() |
| 154 | + ax.contourf(X, Y, np.sin(X) * np.cos(Y), 10) |
| 155 | + plotly_fig = tls.mpl_to_plotly(fig) |
| 156 | + filled = [t for t in plotly_fig.data if t.fill == "toself"] |
| 157 | + assert len(filled) > 0 |
0 commit comments