1

I have a table as follows:

np.random.seed(42)
df = pd.DataFrame(np.random.randint(0, 1000, size=(24,53)))
df['hour'] = range(24)
for col in df.columns[:-1]:
    df.rename({col: str(col)}, axis=1, inplace=True)

which I want to plot. Columns (except hour) correspond to weeks of the year and rows to hours of the day. Directly using pandas it would be:

df[df.columns[:-1]].plot(legend=False);

yielding:

Plot using pandas

However, I want to add interactivity into the game. I thought of using bokeh but it changes so rapidly, I don't know how to do it now. I tried using holoviews:

import holoviews as hv
hv.extension('bokeh')
%%opts Curve [tools=['hover']]
lines = [hv.Curve((df['hour'], df[col]), label=col) for col in df.columns[:-1]]

from functools import reduce
reduce(lambda x, y: x*y, lines) # I'm not sure this is a clean way

yielding something like:

enter image description here

This is doing almost what I want. In particular, the hover tool, shows the x/y coordinates of the points under it. I want it to show the week of the corresponding curve. Lastly, is there a more pythonic way to do so? Maybe directly with bokeh?

1
  • 1
    Note that Bokeh is having a final few changes before a 1.0 release scheduled for next month (before SciPy 2018), and the API is set to be stable after that. What's currently being addressed shouldn't affect anything major, so Bokeh shouldn't be a moving target any more. Commented May 29, 2018 at 23:12

1 Answer 1

2

You could have a look at the new holoplot project which is meant to be (almost) a drop-in replacement for the pandas plotting API built on HoloViews and Bokeh. That will allow you do use the regular pandas API:

import holoplot.pandas
df[df.columns[:-1]].plot(legend=False)

enter image description here

Note that it is still in active development. Separately for the sake of completeness the simpler way to express your HoloViews code would be:

lines = [hv.Curve((df['hour'], df[col]), label=col) for col in df.columns[:-1]]
hv.Overlay(lines)
Sign up to request clarification or add additional context in comments.

5 Comments

Thanks! This is nice and seems to work. Do you know how to limit the scope of holoplot to a single plot? Now it seems like it highjacked the standard pandas plotting.
That's a good question, currently there's no way to do that but I definitely think there should be. Would you mind filing an issue on github.com/pyviz/holoplot to get discussion on that going?
Done. can you add some details on how to adjust the hover tool?
Could you elaborate? If you mean that you want the same hover tooltip as shown above, I'll be pushing a fix for that shortly and release a new version tomorrow.
I recall that in pure bokeh you can adjust the hover tool and configure what is the text, what is shown etc. Is it possible using holoplot?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.