0

I would like to .overlay on key dimension, but also use a gradient palette to color the Curve by the value of the key dimension.

So a simple overlay would be

%%opts Curve [show_legend=False]
hv.HoloMap({i:hv.Curve([i]*100) for i in range(10)}, ["i"]).overlay("i")

with horizontal lines.

How can I use matplotlib.cm.viridis colors with a gradient from i=0 blue to i=9 yellow?

Gere
  • 12,075
  • 18
  • 62
  • 94

1 Answers1

1

To draw multiple paths it is usually best to use the Path and Contours element. More specifically, if each curve you want to draw has a single value associated with it the Contours element is most appropriate. To do what you want you create a list of curves with x and y values along with the appropriate value of 'i' as dictionaries, which you can then pass to the Contours constructor. The final step is to declare 'i' as a value dimension (vdim) of the Contours and set color_index='i' and cmap:

curves = [{'x': np.arange(100), 'y': [i]*100, 'i': i} for i in range(10)]
hv.Contours(curves, vdims=['i']).options(color_index='i', cmap='viridis')

enter image description here

philippjfr
  • 3,997
  • 14
  • 15
  • Thanks a lot! Where could I find the documentation for `color_index`? Is there an easy way to convert between my HoloMap and the Contours version? I usually start with a HoloMap. – Gere Aug 07 '18 at 05:30
  • There is a section on the color_index here: http://holoviews.org/user_guide/Styling_Plots.html – philippjfr Aug 07 '18 at 14:28
  • I'll have a look! I was having trouble finding it in the official API, where I would usually expect to find everything. Is there a convenient way to get from HoloMap to this form? I assumed Holoviews suggests HoloMap as the starting point for everything - which also makes sense to me. Often I need individual curves, but sometimes I want to combine them, but label by continuous color. – Gere Aug 07 '18 at 19:19