Skip to content

Commit 48172c7

Browse files
committed
Compare cmap values in tests (not image comparisons)
1 parent 9de0239 commit 48172c7

7 files changed

+58
-38
lines changed
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

lib/matplotlib/tests/test_colorbar.py

+58-38
Original file line numberDiff line numberDiff line change
@@ -188,64 +188,84 @@ def test_gridspec_make_colorbar():
188188
plt.subplots_adjust(top=0.95, right=0.95, bottom=0.2, hspace=0.25)
189189

190190

191-
@image_comparison(baseline_images=['colorbar_join',
192-
'colorbar_join_frac', ],
193-
extensions=['png'], remove_text=True,
194-
savefig_kwarg={'dpi': 40})
195191
def test_join_colorbar():
196-
data = np.arange(1200).reshape(30, 40)
192+
test_points = [0.1, 0.3, 0.5, 0.7, 0.9]
197193

198194
# Jet is a LinearSegmentedColormap
199195
cmap1 = plt.get_cmap('viridis', 5)
200196
cmap2 = plt.get_cmap('jet', 5)
201197

202198
# This should be a listed colormap.
203199
cmap = cmap1.join(cmap2)
204-
205-
plt.figure()
206-
plt.pcolormesh(data, cmap=cmap)
207-
plt.colorbar(orientation='vertical')
200+
vals = cmap(test_points)
201+
_vals = np.array(
202+
[[0.229739, 0.322361, 0.545706, 1. ],
203+
[0.369214, 0.788888, 0.382914, 1. ],
204+
[0., 0., 0.5, 1. ],
205+
[0.48387097, 1., 0.48387097, 1., ],
206+
[0.5, 0., 0, 1., ]]
207+
)
208+
assert np.allclose(vals, _vals)
208209

209210
# Use the 'frac_self' kwarg for the listed cmap
210211
cmap = cmap1.join(cmap2, frac_self=0.7, N=50)
211-
212-
plt.figure()
213-
plt.pcolormesh(data, cmap=cmap)
214-
plt.colorbar(orientation='vertical')
212+
vals = cmap(test_points)
213+
_vals = np.array(
214+
[[0.267004, 0.004874, 0.329415, 1., ],
215+
[0.127568, 0.566949, 0.550556, 1., ],
216+
[0.369214, 0.788888, 0.382914, 1., ],
217+
[0., 0., 0.5, 1., ],
218+
[1., 0.59259259, 0., 1., ]]
219+
)
220+
assert np.allclose(vals, _vals)
215221

216222

217-
@image_comparison(baseline_images=['colorbar_truncate',
218-
'colorbar_trunc-getitem',
219-
'colorbar_trunc-getitem-int',
220-
'colorbar_trunc-getitem-int-1jN', ],
221-
extensions=['png'], remove_text=True,
222-
savefig_kwarg={'dpi': 40})
223223
def test_truncate_colorbar():
224-
data = np.arange(1200).reshape(30, 40)
225-
224+
test_points = [0.1, 0.3, 0.5, 0.7, 0.9]
225+
226226
cmap = plt.get_cmap('viridis', 32).truncate(0.2, 0.7)
227-
228-
plt.figure()
229-
plt.pcolormesh(data, cmap=cmap)
230-
plt.colorbar(orientation='vertical')
227+
vals = cmap(test_points)
228+
_vals = np.array(
229+
[[0.243113, 0.292092, 0.538516, 1. ],
230+
[0.19586, 0.395433, 0.555276, 1. ],
231+
[0.144759, 0.519093, 0.556572, 1. ],
232+
[0.12478, 0.640461, 0.527068, 1. ],
233+
[0.226397, 0.728888, 0.462789, 1. ]]
234+
)
235+
assert np.allclose(vals, _vals)
231236

232237
cmap = plt.get_cmap('viridis', 128)[0.2:-0.3:16 * 1j]
233-
234-
plt.figure()
235-
plt.pcolormesh(data, cmap=cmap)
236-
plt.colorbar(orientation='vertical')
238+
vals = cmap(test_points)
239+
_vals = np.array(
240+
[[0.241237, 0.296485, 0.539709, 1. ],
241+
[0.192357, 0.403199, 0.555836, 1. ],
242+
[0.140536, 0.530132, 0.555659, 1. ],
243+
[0.12138, 0.629492, 0.531973, 1. ],
244+
[0.214, 0.722114, 0.469588, 1. ]]
245+
)
246+
assert np.allclose(vals, _vals)
237247

238248
cmap = plt.get_cmap('viridis', 128)[25:90]
239-
240-
plt.figure()
241-
plt.pcolormesh(data, cmap=cmap)
242-
plt.colorbar(orientation='vertical')
243-
249+
vals = cmap(test_points)
250+
_vals = np.array(
251+
[[0.233603, 0.313828, 0.543914, 1. ],
252+
[0.185556, 0.41857, 0.556753, 1. ],
253+
[0.14618, 0.515413, 0.556823, 1. ],
254+
[0.119483, 0.614817, 0.537692, 1. ],
255+
[0.19109, 0.708366, 0.482284, 1. ]]
256+
)
257+
assert np.allclose(vals, _vals)
258+
244259
cmap = plt.get_cmap('viridis', 128)[25:90:16 * 1j]
245-
246-
plt.figure()
247-
plt.pcolormesh(data, cmap=cmap)
248-
plt.colorbar(orientation='vertical')
260+
vals = cmap(test_points)
261+
_vals = np.array(
262+
[[0.241237, 0.296485, 0.539709, 1. ],
263+
[0.192357, 0.403199, 0.555836, 1. ],
264+
[0.140536, 0.530132, 0.555659, 1. ],
265+
[0.12138, 0.629492, 0.531973, 1. ],
266+
[0.214, 0.722114, 0.469588, 1. ]]
267+
)
268+
assert np.allclose(vals, _vals)
249269

250270

251271
@image_comparison(baseline_images=['colorbar_single_scatter'],

0 commit comments

Comments
 (0)