Closed kcpevey closed 6 years ago
With HoloViews and GeoViews you can use either Matplotlib colormaps or Bokeh palettes with Bokeh; either one should be fine. Here, colors
is a valid Bokeh palette, so you can pass cmap=colors
instead of cmap='RdYlBu'
, which should work fine, but it won't respect your levels. You can write some Python to duplicate the given colors to cover the given levels (copy the last color 35 times, etc.), and the resulting list will be a valid Bokeh palette as well. But presumably there is some code already, maybe in Matplotlib, that will take separate levels and colors lists and turn it into a Matplotlib colormap? If so just use that and pass in the resulting object for the cmap.
So bokeh would just take colors
and divide it evenly over the range of the plotted data? Would that follow the original data or redim.range
?
presumably there is some code already, maybe in Matplotlib, that will take separate levels and colors lists and turn it into a Matplotlib colormap?
This is what I'm looking for. I'd prefer a utility that will fill out a continuous color spread for me. I'll see what matplotlib has available.
Actually for the levels example above, I need a discrete colorbar, but for others I need continuous. At any rate, a quick google search pointed me to some simple matplotlib applications for both of those.
https://matplotlib.org/tutorials/colors/colorbar_only.html
https://matplotlib.org/2.0.1/examples/pylab_examples/custom_cmap.html
Can I use bokeh as my backend and use a matplotlib colorbar?
So bokeh would just take colors and divide it evenly over the range of the plotted data? Would that follow the original data or redim.range?
Bokeh takes that list and divides it evenly over the range 0,255. Separately, whatever range is being plotted by HoloViews is mapped into the range 0, 255. By default, this range will be the data range, but it will be whatever range is in use at the time if you've told it something else.
I'd prefer a utility that will fill out a continuous color spread for me. I'll see what matplotlib has available.
The LinearSegmentedColormap from Matplotlib will interpolate between colors to give a continuous set of colors. I don't know of one to do discrete colors covering certain ranges, but there probably is one.
Can I use bokeh as my backend and use a matplotlib colorbar?
In HoloViews, yes, as long as you have both Bokeh and Matplotlib installed. And as long as you mean "colormap", i.e., the mapping from values to colors, and not "colorbar", i.e. the graphical display of that mapping. You'll need to use Bokeh's colorbars for a Bokeh plot, but HoloViews will convert a Matplotlib colormap into a Bokeh palette as needed (for convenience), so you can use a Matplotlib colormap wherever you like.
I haven't used it, but from the description, Matplotlib's from_levels_and_colors might be what you need for the discrete case.
Note that the from_levels_and_colors
returns both a colormap and a Normalize instance, I suspect you'd have to manually set the ranges specified by the normalize instance. We might want to add an example like that to the colormap or styling guides in holoviews.
Right; without trying it out I can't see whether the colormap alone that gets constructed is useful for this by itself, or whether it only works in conjunction with the separate normalizer. Definitely something that is worth covering in the hv userguide; there was just an SO issue about this today.
I'm planning to demo my workflow notebooks on our call tomorrow (and I can send a copy if need be). I can show you what I have so far (which is not currently working like I want) and you guys can see what it is I'm trying to achieve.
Can I get a link to the userguide when that becomes available?
It will be in the Custom color intervals
section of this user guide after the next release.
I tried a while back to create a custom colormap for use in a holoviews/geoviews drawing and I could never get it to work. I have ranges and colors:
I got confused on where the colormap generation is sitting. Is it in bokeh? Or is it in another package?
And then I suppose I'll implement it by setting it here in place of
RdYlBu
%%opts Path (cmap='RdYlBu') [color_index='Max_Wind_Speed', colorbar=True]
Can I get some direction?