1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
|
import matplotlib as mpl
import numpy as np
import pytest
from matplotlib.figure import Figure
import cmyt
from cmyt._utils import cmyt_cmaps, prefix_name
mpl_compare = pytest.mark.skip
@pytest.fixture()
def example_data():
# generate example data
prng = np.random.RandomState(0x4D3D3D3)
noise = prng.random_sample((100, 100))
x, y = np.mgrid[-50:50, -50:50]
z = 5 * np.exp(-(x**2 + y**2) / 1000)
return z + noise
@mpl_compare
@pytest.mark.parametrize("name", cmyt_cmaps)
def test_from_str(name, example_data):
fig = Figure(figsize=(12, 4))
axes = fig.subplots(ncols=2)
pname = prefix_name(name)
for cmap, ax in zip([pname, f"{pname}_r"], axes, strict=True):
ax.set_title(cmap)
im = ax.imshow(example_data, cmap=cmap)
fig.colorbar(im, ax=ax)
return fig
@mpl_compare
@pytest.mark.parametrize("name", cmyt_cmaps)
def test_from_obj(name, example_data):
fig = Figure(figsize=(12, 4))
axes = fig.subplots(ncols=2)
for cmap, ax in zip([name, f"{name}_r"], axes, strict=True):
ax.set_title(cmap)
im = ax.imshow(example_data, cmap=getattr(cmyt, cmap))
fig.colorbar(im, ax=ax)
return fig
@pytest.mark.parametrize("name", cmyt_cmaps)
def test_cmap_name_attr(name):
assert getattr(cmyt, name).name == name
assert mpl.colormaps[f"cmyt.{name}"].name == prefix_name(name)
|