Is there any way at the moment to add constant tooltips to a bokeh line plot in python? I did not find anything about it in the documention.
I am looking for a way to allow adding the tooltip interactively ala matlab. However, doing so via the code at first is acceptable.
thanks.
Currently (as of 0.8.1) the line glyph does not support hit testing, so it does not support a hover tool, either. However, if it suffices to have a hover tooltip on just the "points" of the line, then several people have uses a second set of transparent markers located at the same points as a workaround. Something like:
line(x, y)
circle(x, y, size=8, alpha=0)
There is an open issue for adding line hit testing, it should hopefully been in one of the next few releases.
Related
I learnt how to add text by using Label in Bokeh in this question.
However, I found that the text doesn't rescale as I zoom in and out.
The ideal behavior is something like Patches, which becomes larger as you zoom in.
How can I configure for this feature?
Related Questions
Selectively show text in Bokeh plot based on zoom level
As of Bokeh 2.3 scalable text is still an open issue:
https://github.com/bokeh/bokeh/issues/9407
There are some potential partial workarounds discussed there, but nothing that concretely works all the time. Depending on your use case, you could potentially use CustomJS callback on the plot ranges to update the text size that you care about in some way.
I am trying to get a better understanding about the column data source in Bokeh (for Python). I found this code, but I can't seem to find the documentation that explains some things I am looking for, For instance:
Where is the callback from the lasso_select tool? I want to see where the expected functionality is described.
How is the functionality of the lasso_select described in code? (What if I want to change it?)
What is happening to the column data source so that the circles outside the lasso-select region change appearance? (I want to know how I can use the column data source for more complex visualization than is shown by this demo. So I'd like to know what dictionary field is being manipulated, and how is it being manipulated. For example, is there a hidden "color" field or something like that, which isn't explicit in this code?)
What code causes the figure to be redrawn when a lasso_select action is made?
I have many more questions related to this and the CDSView, but I'll stop here for now.
from bokeh.io import output_file, show
from bokeh.layouts import gridplot
from bokeh.models import ColumnDataSource
from bokeh.plotting import figure
output_file("brushing.html")
x = list(range(-20, 21))
y0 = [abs(xx) for xx in x]
y1 = [xx**2 for xx in x]
# create a column data source for the plots to share
source = ColumnDataSource(data=dict(x=x, y0=y0, y1=y1))
TOOLS = "box_select,lasso_select,help"
# create a new plot and add a renderer
left = figure(tools=TOOLS, plot_width=300, plot_height=300, title=None)
left.circle('x', 'y0', source=source)
# create another new plot and add a renderer
right = figure(tools=TOOLS, plot_width=300, plot_height=300, title=None)
right.circle('x', 'y1', source=source)
p = gridplot([[left, right]])
show(p)
This is related to my previous question, where the only answer was very narrow in explaining for that specific question. However, I am really interested in what's going on under the hood to give the results that are seen. It would help my understanding a lot more if I could know some of those details.
1) There is no callback. The tool is responsible for defining a selection geometry, and and then hit-testing baed on that geometry. The hit test results are store in a selection property of the data source. Glyph renderers draw glyphs based on the selection property of their data source. If two glyph renderers (even on different plots) share the same data source, they will both draw the same set of selected/nonselected as a result.
2) If you mean the appearance of the normal vs selected vs non-selected objects, how to configure that is described in the docs here:
https://docs.bokeh.org/en/latest/docs/user_guide/styling.html#selected-and-unselected-glyphs
There are also a few properties on the LassoTool object itself, that control, e.g. whether a selection should be made on every mousemove, or only on mouseup, and what the selection overlay looks like. All of these are recorded in the ReferenceGuide. If you are asking how to change the implementation, as with msot everything in Bokeh, the real work is not done in Python, it is done in the JavaScript library BokehJS. The implementation of the LassoTool is here:
https://github.com/bokeh/bokeh/blob/master/bokehjs/src/lib/models/tools/gestures/lasso_select_tool.ts
If you want something fundamentally different you would need to implement your own custom model, including its JavaScript component. There is an entire User's Guide section about building custom extensions:
https://docs.bokeh.org/en/latest/docs/user_guide/extensions.html
3) The Plot is configured with various Renderers, one of which can be a GlyphRenderer. The GlyphRenderer itself does not draw anything, but it configures various sub-glyphs that are used to draw in specific situations:
glyph draws "normal" versions of glyphs (i.e. when there is no selection on the data source)
selected_glyph draws "selected" versions of glyphs (i.e. the ones inside a lasso or box tool when a selection is active)
nonselected_glyph draws the "non-selected" versions of glyphs (i.e. the ones outside a lasso or box tool when a selection is active) By default the non selection glyph is just a copy of the "normal" glyph with the alpha value set very low.
hover_glyph draws the "hovered" versions of glyphs (i.e. when a hover tool has inspected them)
You configure the appearance in the different situation by configuring properties on the glyphs that are used in each situation. There are sensible defaults for them, but they can be updated as described in the first link of 2)
4) BokehJS has an internal signal/slots event system that is used (among other things) to request canvas redraws whenever various properties change.
I'm plotting two lines, one solid, one dashed. At the initial zoom the lines appear as defined. However, when zooming into the plot the dashed line becomes solid. The pictures below illustrate the problem. Here is the code that defines the lines:
turbidity_stn3_plot1 = f.line(x='Datetime',y='Turbidity', y_range_name='default', color='olive',line_color='black', line_dash=[1,10], line_width=1, source=turbidity_stn_03_plot_01_source)
turbidity_stn1_plot1 = f.line(x='Datetime',y='Turbidity', y_range_name='default', color='olive',line_color='black', line_dash='solid', source=turbidity_stn_01_plot_01_source)
I already tried different 'line_dash' values, like 'dashed' and 'dotted' with the same result.
I noticed that, when increasing the distance between dashes (e.g. 'line_dash=[1,20]'), the closer I can zoom in before the line turns solid.
Does anybody know why this is and how to avoid it?
Should I report this as a bug on Bokeh Github?
This is a result of browser-dependent behavior of HTML canvas implementations. There is nothing that the Bokeh project can do about it (which is why the GH issue was eventually closed). If you are working in regimes where this issue shows up, the only alternative is to use other visual properties, e.g. width or color, instead of dashing.
I’ve been working on bokeh plots and I’m trying to plot a line graph taking values from a database. But the plot kind of traces back to the initial point and I don’t want that. I want a plot which starts at one point and stops at a certain point (and circle back). I’ve tried plotting it on other tools like SQLite browser and Excel and the plot seems ok which means I must be doing something wrong with the bokeh stuff and that the data points itself are not in error.
I’ve attached the images for reference and the line of code doing the line plot. Is there something I’ve missed?
>>> image = fig.line(“x”, “y”, color=color, source=something)
(Assume x and y are integer values and I’ve specified x and y ranges as DataRange1d(bounds=(0,None)))
Bokeh does not "auto-close" lines. You can see this is the case by looking at any number of examples in the docs and repository, but here is one in particular:
http://docs.bokeh.org/en/latest/docs/gallery/stocks.html
Bokeh's .line method will only "close up" if that is what is in the data (i.e., if the last point in the data is a repeat of the first point). I suggest you actually inspect the data values in source.data and I believe you will find this to be the case. Then the question is why is that the case and how to prevent it from doing that, but that is not really a Bokeh question.
I'm writing a program in Python. The first thing that happens is a window is displayed (I'm using wxPython) that has some buttons and text. When the user performs some actions, a plot is displayed in its own window. This plot is made with R, using rpy2. The problem is that the plot usually pops up on top of the main window, so the user has to move the plot to see the main window again. This is a big problem for the user, because he's lazy and good-for-nothing. He wants the plot to simply appear somewhere else, so he can see the main window and the plot at the same time, without having to lift a finger.
Two potential solutions to my problem are:
(1) display the plot within a wxPython frame (which I think I could control the location of), or
(2) be able to specify where on the screen the plot window appears.
I can't figure out how to do either.
Plot to a graphics file using jpeg(), png() or another device, then display that file on your wxWidget.
There are few lines about this in the documentation:
http://rpy.sourceforge.net/rpy2/doc-2.2/html/graphics.html
By default R plots to the "interactive" plotting device (X11). Specifying a non-interactive file-based device (jpeg, png, pdf - pdf being probably easier if rescaling or zooming is wished).
There is a very experimental feature in rpy2-2.2.0dev that would let one implement relatively easily new devices (e.g., plot into matplotlib canvases, or wxWindows panels), but unfortunately this is not complete, not documented, and probably not fully working.