question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Stop overriding user-input colormap lookup table size

See original GitHub issue

Description

It seems proplot does not work with the conventional discrete color in matplotlib (which I used heavily…).

I noticed the document mentioned discrete several places, but it seems not what I’m looking for. I can specify discrete=True with scatter, but it gives 10 levels instead of 5 levels as I specified in the code.

Any hint for me? Many thanks!

Steps to reproduce

import numpy as np
from matplotlib import pyplot as plt
import proplot as pplt

fig, ax = pplt.subplot(journal='nat1', refaspect=1)
x, y, c = np.random.rand(3, 100)
cl = ax.scatter(x, y, c=c, cmap=plt.get_cmap('viridis', 5))
ax.colorbar(cl)

Expected behavior: [What you expected to happen] image

Actual behavior: [What actually happened] image

Equivalent steps in matplotlib

Please try to make sure this bug is related to a proplot-specific feature. If you’re not sure, try to replicate it with the native matplotlib API. Matplotlib bugs belong on the matplotlib github page.

import numpy as np
from matplotlib import pyplot as plt
import proplot as pplt

ax = plt.subplot()
x, y, c = np.random.rand(3, 100)
cl = ax.scatter(x, y, c=c, cmap=plt.get_cmap('viridis', 5))
plt.colorbar(cl)

Proplot version

Paste the results of import matplotlib; print(matplotlib.__version__); import proplot; print(proplot.version)here.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
lukelbdcommented, Feb 19, 2022

Thanks @syrte for the report and @zxdawn for the help!

That’s interesting that proplot overrides the lookup table size of 5 in your example (note a “lookup table” is an N x 3 array of RGB colors generated from the linear transitions specified by the LinearSegmentedColormap).

Indeed there are two ways of “discretizing” continuous colormaps: decreasing the lookup table size (as you have done, or could be done with rc['image.lut'] = 5), or pairing the dense lookup table with a matplotlib BoundaryNorm (or proplot DiscreteNorm) that selects a smaller subset of RGB colors in that table.

Proplot elects to use DiscreteNorm as the universal method for discretizing continuous colormaps, and leaves the “lookup table size” as something internal and mostly irrelevant for users, because DiscreteNorm is more flexible (e.g. for getting out-of-bounds colors right). However, we should not be silently overwriting a colormap’s lookup table size when users want to discretize in this way, as I know this is a popular method.

Maybe this could be fixed by disabling the application of DiscreteNorm when a colormap’s lookup table size is below a certain threshold (similar to the rc['cmap.listedthresh'] setting).

1reaction
syrtecommented, Feb 19, 2022

Thanks a lot for your quick reply @zxdawn Your solution is nice and much simpler than mine! I didn’t notice the usage of levels. Thanks.

Read more comments on GitHub >

github_iconTop Results From Across the Web

colormaps (cm) do not properly handle NaN values. #9892
Bug report Bug summary When using a colormap to generate a color array ... scaled to map to lookup table f *= N...
Read more >
proplot.colors — ProPlot documentation - Read the Docs
NOTE: To avoid name conflicts between registered colormaps and colors, print # set(pplt.colors. ... optional Number of points in the colormap lookup table....
Read more >
View and set current colormap - MATLAB colormap - MathWorks
This MATLAB function sets the colormap for the current figure to one of ... The new colormap is the same length (number of...
Read more >
matplotlib.colors.Colormap Example - Program Talk
If called with label='auto', this parameter will override the ... optional Font size to use for super title at top of figure colorbar...
Read more >
https://imagej.nih.gov/ij//plugins/download/misc/A...
5) Add support for all sizes of Color Look Up tables. * 6) Re-code to be cleaner. This is my second Java program...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found