Stop overriding user-input colormap lookup table size
See original GitHub issueDescription
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]
Actual behavior: [What actually happened]
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:
- Created 2 years ago
- Comments:5
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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 theLinearSegmentedColormap
).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 matplotlibBoundaryNorm
(or proplotDiscreteNorm
) 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, becauseDiscreteNorm
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 therc['cmap.listedthresh']
setting).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.