plotly.js
plotly.js copied to clipboard
not support extremely small number
When my normalized color scheme values are extremely small (down to 5 decimal places), this configuration becomes invalid.
thanks for the bug report @missBlueWhite - when you say "becomes invalid", what error message are you seeing? and which version of plotly.js are you using? thanks - @gvwilson
I'm guessing you're creating a heatmap and/or a heatmap-colored contour map. In these modes I believe we convert the colormap to 256 discrete colors, so the way you're generating your colormap all of these except the final color get collapsed into one.
The standard way to use colormaps is to scale the values up so that instead of 0-0.00009 you use the full 0-1 range, then map these to your data using the zmin and zmax attributes (or cmin and cmax in some contexts). Note that the strategy you used here would throw an error if you tried to use it with data outside the 0-1 range.
感谢您的错误报告 - 当您说“变得无效”时,您看到的是什么错误消息?您使用的是哪个版本的 plotly.js?谢谢-
As shown in the figure, the image contains only two colors: red and purple, while the other colors are not displayed. The z-values provided range from 200 to 3,000,000. When setting the colorScale as described above, only purple and red appear, and the other colors fail to render.
@TBusan right, in principle this is a bug that at some point we should fix, but I suspect doing that would be a substantial project that might also impact performance, so it's much better to make use of the existing patterns if you can use them to do what you need.
The colorscale screenshot posted by @missBlueWhite is a linear mapping of 20 colors over the first ten-thousandth of the range, then everything above that is purple. That's exactly what zmin and zmax are for. To use this pattern, multiply all the fractions in your colorscale except the 1 at the end by 10000 (so instead of 0.00009595... use 0.9595...) and then set bounds like zmin=200, zmax=500 (ie zmin is your data minimum, and zmax is one ten-thousandth of the full range 200 + (3e6-200)/1e4)
@TBusan right, in principle this is a bug that at some point we should fix, but I suspect doing that would be a substantial project that might also impact performance, so it's much better to make use of the existing patterns if you can use them to do what you need.
The colorscale screenshot posted by @missBlueWhite is a linear mapping of 20 colors over the first ten-thousandth of the range, then everything above that is purple. That's exactly what
zminandzmaxare for. To use this pattern, multiply all the fractions in your colorscale except the1at the end by 10000 (so instead of0.00009595...use0.9595...) and then set bounds likezmin=200, zmax=500(iezminis your data minimum, andzmaxis one ten-thousandth of the full range200 + (3e6-200)/1e4)
thanks, but nn some cases, I don't want to use the zmin or zmax ,I want to render all of the data.
With zmin and zmax we still render all the data, but anything below zmin gets the min color and anything above zmax gets the max color. You're right that there are situations that this won't cover (a common one we'd like to support at some point, though I'm not seeing an issue for it ATM, is logarithmic colorscales), but it would work for the example you started this issue with, in which all the data from 0.000095 to 1 is already mapped to the same color.