python-colorspace icon indicating copy to clipboard operation
python-colorspace copied to clipboard

error using heat_hcl

Open meteosimon opened this issue 4 years ago • 4 comments

Trying to use the cmap method of heat_hcl I get the error:

AttributeError: 'heat_hcl' object has no attribute '_rev'

I guess this attribute is not initialized?

meteosimon avatar Apr 22 '21 13:04 meteosimon

Dear Mr. Simon

Do you have a minimal to reproduce this issue? The following should work:

from colorspace import heat_hcl

pal1 = heat_hcl()
print(pal1(3))
print(pal1(3, rev = True))

I have, however, encountered another small problem where double-reverse will not work:

pal2 = heat_hcl(rev = True)
print(pal2(3))
print(pal2(3, rev = True))

... which gives twice the same series of colors (always 'reversed').

retostauffer avatar Apr 23 '21 07:04 retostauffer

The error occurs using the cmap method of the palette for matplotlib:

from colorspace import heat_hcl
pal = heat_hcl()
pal.cmap()

I guess adding

        self._rev = False

to the __init__ method of heat_hcl should do it?

meteosimon avatar Apr 23 '21 07:04 meteosimon

Ok, I see the error occurs when calling

pal.cmap(rev = True)

I have to address this; Not intended to revert the .cmap(), the palette should be reverted instead. Does it work if you use the following:

from colorspace import heat_hcl
pal = heat_hcl(rev = True)
# and then use pal.cmap() from here

retostauffer avatar Apr 23 '21 07:04 retostauffer

I just forked the repo and added this line, it now seems to work, no error, specplot is identical to R's colorspace.

BTW: terrain_hcl() would need the same fix.

meteosimon avatar Apr 23 '21 08:04 meteosimon

I think that this has been addressed. But as the current code is a bit different from what Thorsten proposed, I'm pinging Reto @retostauffer to double check...

zeileis avatar Jun 03 '24 23:06 zeileis

Some more digging: I think this was addressed in the PR https://github.com/retostauffer/python-colorspace/pull/4

zeileis avatar Jun 03 '24 23:06 zeileis

That is, indeed, fixed. Reversing colors is either done when creating a colorspace palette (using the _rev = True argument) but can also be done later on the matplotlib cmap using e.g., rainbow().cmap().reversed().

Here is a small gist test script with a quick test/example.

retostauffer avatar Jun 05 '24 06:06 retostauffer