Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

color_index and size_index should accept name of column in pandas DataFrame #391

maxalbert opened this issue Jan 3, 2016 · 2 comments


Copy link

@maxalbert maxalbert commented Jan 3, 2016

Here is a slightly tweaked version of the Points example where the Points element is initialised from a pandas DataFrame instead of a numpy array.

import numpy as np
import pandas as pd

df = pd.DataFrame(np.random.rand(100, 4), columns=['col1', 'col2', 'col3', 'col4'])

Using an integer for color_index and size_index (as in the Elements tutorial) works as expected:

%%opts Points [color_index=2 size_index=3 scaling_factor=50]

However, using the names of the data frame columns does not work (using latest master, e3a536d):

%%opts Points [color_index='col3' size_index='col4' scaling_factor=50]
Traceback (most recent call last):
  File "/Users/albert/code/holoviews/holoviews/ipython/", line 101, in wrapped
    max_branches = OutputMagic.options['max_branches'])
  File "/Users/albert/code/holoviews/holoviews/ipython/", line 143, in element_display
    return renderer.html(element, fmt=renderer.fig)
  File "/Users/albert/code/holoviews/holoviews/plotting/", line 211, in html
    plot, fmt =  self._validate(obj, fmt)
  File "/Users/albert/code/holoviews/holoviews/plotting/", line 171, in _validate
    plot = self.get_plot(obj)
  File "/Users/albert/code/holoviews/holoviews/plotting/", line 157, in get_plot
    plot = self_or_cls.plotting_class(obj)(obj, **plot_opts)
  File "/Users/albert/code/holoviews/holoviews/plotting/mpl/", line 23, in __init__
    super(ChartPlot, self).__init__(data, **params)
  File "/Users/albert/code/holoviews/holoviews/plotting/mpl/", line 111, in __init__
    super(ElementPlot, self).__init__(element, **params)
  File "/Users/albert/code/holoviews/holoviews/plotting/", line 440, in __init__
    **dict(params, **plot_opts))
  File "/Users/albert/code/holoviews/holoviews/plotting/mpl/", line 88, in __init__
    super(MPLPlot, self).__init__(**params)
  File "/Users/albert/code/holoviews/holoviews/plotting/", line 179, in __init__
    super(DimensionedPlot, self).__init__(**params)
  File "/Users/albert/miniconda3/lib/python3.4/site-packages/param/", line 1021, in __init__
  File "/Users/albert/miniconda3/lib/python3.4/site-packages/param/", line 958, in override_initialization
  File "/Users/albert/miniconda3/lib/python3.4/site-packages/param/", line 1411, in _setup_params
  File "/Users/albert/miniconda3/lib/python3.4/site-packages/param/", line 563, in __set__
    if not callable(val): self._check_value(val)
  File "/Users/albert/miniconda3/lib/python3.4/site-packages/param/", line 692, in _check_value
    raise ValueError("Parameter '%s' must be an integer."%self._attrib_name)
ValueError: Parameter 'color_index' must be an integer.
Copy link

@philippjfr philippjfr commented Jan 3, 2016

Agreed, I've been meaning to allow this for a while now, should be pretty straightforward.

Copy link

@philippjfr philippjfr commented Feb 6, 2016

Implemented this in #461, should now work for all size_index and color_index plot options. Closing.

@philippjfr philippjfr closed this Feb 6, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants