Skip to content

Deprecate ListedColormap(..., N=...) parameter #29135

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

Merged
merged 2 commits into from
Nov 20, 2024

Conversation

timhoffm
Copy link
Member

Truncating or repeating the given colors to a specific value of N is not within the scope of colormaps. Instead, users should create an appropriate color list themselves and feed that to ListedColormap.

Also the current behavior can be surprising: It may well be that a given N was intended to truncate, but depending on the list, it could repeat. Repeated colors in a colormap are dangerous / often not intentended because they create an ambiguity in the color -> value mapping.

Truncating or repeating the given colors to a specific value of N
is not within the scope of colormaps. Instead, users should
create an appropriate color list themselves and feed that to
ListedColormap.

Also the current behavior can be surprising: It may well be that
a given N was intended to truncate, but depending on the list, it
could repeat. Repeated colors in a colormap are dangerous / often
not intentended because they create an ambiguity in the color ->
value mapping.
@timhoffm timhoffm added this to the v3.11.0 milestone Nov 14, 2024
@timhoffm timhoffm marked this pull request as ready for review November 14, 2024 14:07
@timhoffm timhoffm mentioned this pull request Nov 14, 2024
8 tasks
Co-authored-by: Ruth Comer <10599679+rcomer@users.noreply.github.com>
@ksunden ksunden merged commit 2fa9151 into matplotlib:main Nov 20, 2024
41 of 43 checks passed
@timhoffm timhoffm deleted the colormap-N branch November 20, 2024 20:03
@neutrinoceros
Copy link
Contributor

neutrinoceros commented Nov 26, 2024

while adapting cmyt to this change, I noticed that LinearSegmentedColormap still silently accepts the parameter N, shouldn't it be deprecated too ?
(same goes for LinearSegmentedColormap.from_list)

@timhoffm
Copy link
Member Author

The effect / usage of N in LinearSegmentedColormap is different:

  • For ListedColormap it only cuts or expands the given list of colors, which can easily be done by the user.
  • For LinearSegmentedColormap, N defines the internal sampling. The input are RGB curves, which may be very coarsly defined via only a few points. Because we don't want interpolate these curves for every color lookup, LinearSegementedColormap internally samples these curves into a lookup table. N controls this sampling. If we would remove N here, that means the user would have to do the sampling, and then we'd be effectively back to a ListedColormap. In other words, the added benefit of LinearSegmentedColormap is that you can specify the RGB curve on a high level, and the colormap does the sampling into a lookup table for you. That fundamentally needs N as a control parameter.

LinearSegmentedColormap.from_list is only a slightly simpler interface that limits the RGB curves to continuous curves (i.e. you cannot have discontinous jumps), it this equally needs N for the internal sampling.

Therefore, there is no plan to discard N for LinearSegmentedColormap.

@neutrinoceros
Copy link
Contributor

thanks a lot for this detailed explanation !

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

Successfully merging this pull request may close these issues.

4 participants