14

When I try to input my own ticker...

In an earlier cell...

ticker = FixedTicker(ticks=range(0, 10))

In the following cell...

%%opts HeatMap [colorbar=True colorbar_opts={'ticker': ticker}]

I get...

TypeError [Call holoviews.ipython.show_traceback() for details]
MetaModel object got multiple values for keyword argument 'ticker'

Here's the traceback...

  File "/Users/ahuang11/anaconda3/envs/tf/lib/python3.6/site-packages/holoviews/plotting/bokeh/element.py", line 757, in _init_glyphs
    renderer, glyph = self._init_glyph(plot, mapping, properties)

  File "/Users/ahuang11/anaconda3/envs/tf/lib/python3.6/site-packages/holoviews/plotting/bokeh/element.py", line 1201, in _init_glyph
    self._draw_colorbar(plot, self.handles['color_mapper'])

  File "/Users/ahuang11/anaconda3/envs/tf/lib/python3.6/site-packages/holoviews/plotting/bokeh/element.py", line 1100, in _draw_colorbar
    **dict(opts, **self.colorbar_opts))

TypeError: MetaModel object got multiple values for keyword argument 'ticker'
Andrew
  • 507
  • 5
  • 16

1 Answers1

11

The color range and all other ranges can be set on the Dimension objects of HoloViews Elements. When you declare a HeatMap three (or more) dimensions are created. The first two are the key dimensions (kdims) corresponding to the x- and y-axis of the HeatMap. Secondly there are two or more value dimensions (vdims) the first of which is mapped to the color range. Dimension ranges can be explicitly declared when constructing the object. Here we set the color of the 'z' Dimension, which should be the name of whatever column you are plotting:

hv.HeatMap(..., vdims=hv.Dimension('z', range=(0, 10)))

You can also use the redim interface to override the range after the fact. This will also work when you have a collection of objects, as it will set the range recursively on all objects which contain that dimension and return a new object. That looks something like this:

heatmap = hv.HeatMap(...)
redimensioned_heatmap = heatmap.redim.range(z=(0, 10))
philippjfr
  • 3,997
  • 14
  • 15
  • Thank you, that worked! Is there a way to adjust how many tick marks are shown? – Andrew Feb 07 '18 at 16:24
  • 3
    For hvplot users: The value dimension is not 'z', but whatever you have set in `C=??>`. You can check the name with `print(heatmap.vdims)`. Then, you can change the range with `heatmap.redim.range(my_col=(0, 10))` or `heatmap.redim.range(**{str(heatmap.vdims[0]):(0, 10)})`. This cost me a lot of time to figure out. – magum Apr 03 '19 at 13:02
  • Wow, @magnum, thanks so much, cost me a few hours as well. :/ – K.-Michael Aye Aug 12 '19 at 22:18
  • 9
    Nowadays, I think you can do `hv_obj.opts(clim=(0, 10))` – Andrew Aug 14 '19 at 14:39
  • I wish clim would work in all cases... "Unexpected option 'clim' for AdjointLayout type across all extensions. No similar options found." – K.-Michael Aye Jan 13 '20 at 04:13
  • 2
    @K.-MichaelAye You need to target the option to the correct type, if you're setting it on an AdjointLayout it's ambiguous which element you're trying to set it on. So if you're trying to target a HeatMap you should use `hv_obj.opts(hv.opts.HeatMap(clim=(0, 10)))` or if there are no overlays you can also use `hv_obj.apply.opts(clim=(0, 10)) – philippjfr Jan 13 '20 at 15:02
  • Thanks! I have a similar question: how do you set the center of a diverging colormap? for instance, if you wish to set 0 to white, negative values going to darker blue down to -10 and the positive values up to 5? In summary, I am looking for the parameters analogous to seaborn min, vmax and center: https://seaborn.pydata.org/generated/seaborn.heatmap.html – Maxime Beau Jun 23 '20 at 17:14
  • There is currently no center argument but that seems like a good feature request. – philippjfr Jun 24 '20 at 10:03