Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error while using cvd_space #11

Open
nicoguaro opened this issue Jan 2, 2018 · 4 comments
Open

Error while using cvd_space #11

nicoguaro opened this issue Jan 2, 2018 · 4 comments

Comments

@nicoguaro
Copy link

I am trying to convert the hsv colormap simulating colorblindness as described here. But I obtain the following error

ValueError: RGBA values should be within 0-1 range

Due to values outside of [0, 1].

Following an example

from __future__ import division, print_function
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.colors import LinearSegmentedColormap
from colorspacious import cspace_convert


azimuths = np.arange(0, 361, 1)
zeniths = np.arange(40, 70, 1)
values = azimuths * np.ones((30, 361))
data = plt.cm.hsv(np.linspace(0, 1, 64))
fig = plt.figure()
cvd_space = {"name": "sRGB1+CVD",
     "cvd_type": "deuteranomaly",
     "severity": 50}
data2 = cspace_convert(data[:, :3], cvd_space, "sRGB1")
cmap = LinearSegmentedColormap.from_list('my_colormap', data2)
ax = plt.subplot(111, projection='polar')
ax.pcolormesh(azimuths*np.pi/180.0, zeniths, values, cmap=cmap)
ax.set_xticks([])
ax.set_yticks([])
@njsmith
Copy link
Owner

njsmith commented Jan 2, 2018 via email

@nicoguaro
Copy link
Author

I thought about that, and it worked. The only problem is that I obtained values between -1.989 and 1.047 :-/

@njsmith
Copy link
Owner

njsmith commented Jan 3, 2018

Huh, yeah, that is weird. I just double-checked the paper, and it looks like we're implementing their formula correctly, and it really does just gives invalid values sometimes. And AFAICT they don't say anything about this or give any suggestions on how to handle it. I guess clipping is ... possibly not totally wrong? Not sure what to tell you.

@nicoguaro
Copy link
Author

Thanks for double checking! You can see the plots I generated, if you are interested, here: https://nicoguaro.github.io/posts/cyclic_colormaps/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants