2

I'm making a trend graph with Bokeh, showing how the popularity of concepts came and went with time. I used the brewer example (https://docs.bokeh.org/en/latest/docs/gallery/stacked_area.html). Only the tooltip doesn't really display what I want it to.

I adapted the bottom 6 lines like this:

source = ColumnDataSource(data=dict( x=[x2] * len(areas), y=[areas[y] for y in categories], name=categories, )) timesteps = [str(x.date()) for x in pd.date_range('1950-01-01', '1951-07-01', freq='MS')] p = figure(x_range=FactorRange(factors=timesteps), y_range=(0, 800), tools="hover") p.xaxis.major_label_orientation = np.pi/4 p.grid.minor_grid_line_color = '#eeeeee' hover = p.select(dict(type=HoverTool)) hover.tooltips = [ ('Name', ' @name'), ('Time', ' $x'), ('Count', ' @count'), ] p.patches('x', 'y', source=source, color=colors, alpha=0.8, line_color=None) output_file("brewer.html", title="brewer.py example") show(p) 

The first two lines of the tooltip work, displaying the name (y0, y1, y2...) and the date; only the third line I can't figure out. I want to display the "height" of the data point at that time, i.e. if I had a dictionary like

{'y0': {'1950-01-01': '3', '1950-02-01': '5', '1950-03-01': '6'}, 'y1': {'1950-01-01': '10', '1950-02-01': '15', '1950-03-01': '14'}} 

and so on, I would like to display at each point the popularity of a y at a given point in time. That popularity is already displayed graphically, but to make it more obvious, I would also like to make the number that was plotted available - I only don't know how. I've tried building different dictionaries and lists, but only succeeded in displaying one number for every point in time for every concept, but that number didn't change.

2
  • Is this question related to/solved here: stackoverflow.com/questions/42402718/… ? Commented Feb 26, 2017 at 20:39
  • Unfortunately not. In the other example, there's a simpler assignment: A label (e.g. animal name) corresponds to a value (e.g. 4). In this example, I have two labels (date, category) which should correspond to a value (e.g. 4). If either date or category change, the value should change. So far, I've only succeeded making the value change with a category change, but not when moving horizontally and thereby switching between dates. Commented Feb 26, 2017 at 23:13

1 Answer 1

1

Unless I am mis-understanding something, could you simply not just change your hover tool to the following? :

hover.tooltips = [ ('Name', ' @name'), ("(Time, Height)", "($x, $y)"), ] 

That will vary the height as you move vertically or horizontally.

Sign up to request clarification or add additional context in comments.

8 Comments

True, that displays the height, but I would like to display the "absolute height". If it were e.g. a graph that shows how many percent something holds, I would like to always display 70%, no matter how high (vertically) the cursor is. With your solution I would have to move the cursor all the way up until it reaches the highest point, then it would display 70%.
Oh I think I understand now, you want for each category to display the peak value at each time. Then what you need to do is calculate the peak value at each time, put that into the data source and replace $y with $(max_height_category_i). If you cant get it to work I will do it when i get some spare time
Exactly! I already calculated this, but don't know which format it should be in. Should it be a long list of [max_category1_time1, max_category2_time1, max_category3_time1, ..., max_category1_time2, max-category2_time2, max_category3_time2, ...] or in nested lists or sorted some other way? I always get the warning that my data sources are not of the same length; and the values shown are not changing for the time step, only for the category.
So it should be in the exact same shape as y. Except now for each category in each time period all of the y values just equal the maximum.
Ok, so now I understand why this is so difficult. It is all fine to display the coordinates of the current position, as bokeh has this information from the plot essentially. However, if you want to take some data from the source it can only of length equal to the number of patches - and that means we cant store the required information. Perhaps we need to write a JS solution for this.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.