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

Closed
maxalbert opened this Issue Jan 3, 2016 · 2 comments

Comments

Projects
None yet
2 participants
@maxalbert
Copy link
Contributor

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

np.random.seed(10)
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]
hv.Points(df)

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]
hv.Points(df)
Traceback (most recent call last):
  File "/Users/albert/code/holoviews/holoviews/ipython/display_hooks.py", line 101, in wrapped
    max_branches = OutputMagic.options['max_branches'])
  File "/Users/albert/code/holoviews/holoviews/ipython/display_hooks.py", line 143, in element_display
    return renderer.html(element, fmt=renderer.fig)
  File "/Users/albert/code/holoviews/holoviews/plotting/renderer.py", line 211, in html
    plot, fmt =  self._validate(obj, fmt)
  File "/Users/albert/code/holoviews/holoviews/plotting/renderer.py", line 171, in _validate
    plot = self.get_plot(obj)
  File "/Users/albert/code/holoviews/holoviews/plotting/renderer.py", line 157, in get_plot
    plot = self_or_cls.plotting_class(obj)(obj, **plot_opts)
  File "/Users/albert/code/holoviews/holoviews/plotting/mpl/chart.py", line 23, in __init__
    super(ChartPlot, self).__init__(data, **params)
  File "/Users/albert/code/holoviews/holoviews/plotting/mpl/element.py", line 111, in __init__
    super(ElementPlot, self).__init__(element, **params)
  File "/Users/albert/code/holoviews/holoviews/plotting/plot.py", line 440, in __init__
    **dict(params, **plot_opts))
  File "/Users/albert/code/holoviews/holoviews/plotting/mpl/plot.py", line 88, in __init__
    super(MPLPlot, self).__init__(**params)
  File "/Users/albert/code/holoviews/holoviews/plotting/plot.py", line 179, in __init__
    super(DimensionedPlot, self).__init__(**params)
  File "/Users/albert/miniconda3/lib/python3.4/site-packages/param/parameterized.py", line 1021, in __init__
    self._setup_params(**params)
  File "/Users/albert/miniconda3/lib/python3.4/site-packages/param/parameterized.py", line 958, in override_initialization
    fn(parameterized_instance,*args,**kw)
  File "/Users/albert/miniconda3/lib/python3.4/site-packages/param/parameterized.py", line 1411, in _setup_params
    setattr(self,name,val)
  File "/Users/albert/miniconda3/lib/python3.4/site-packages/param/__init__.py", line 563, in __set__
    if not callable(val): self._check_value(val)
  File "/Users/albert/miniconda3/lib/python3.4/site-packages/param/__init__.py", line 692, in _check_value
    raise ValueError("Parameter '%s' must be an integer."%self._attrib_name)
ValueError: Parameter 'color_index' must be an integer.
@philippjfr

This comment has been minimized.

Copy link
Contributor

philippjfr commented Jan 3, 2016

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

@philippjfr

This comment has been minimized.

Copy link
Contributor

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
You can’t perform that action at this time.