1

I am using just the BokehJS part of Bokeh since i am building a more production oriented system. Unfortunately it seems that the actual BokehJS part of Bokeh is not documented that much, which makes it difficult to find the needed information, such as how to format data for the bokehJS object.

What I am trying to do is to make a simple line graph, however instead of having just one line i would like to have multiple lines, and the possibility of making a legend describing each line. Its a very basica plot, however i did not find any way to do this in bokehJS. In order to make a plot with a single line i execute the following javascript:

    Bokeh.Plotting.show(
        Bokeh.Plotting.make_plot({type:'line'}, {x:[1,2],y:[4,5]}, {})
        ,'.mydivcontainer');

How do i alter this so that i can have 5 lines in the same plot as well as a legend, basically similar to this which is written in standard bokeh:

from collections import OrderedDict import pandas as pd

AAPL = pd.read_csv("aapl.csv", parse_dates=["Date"])
MSFT = pd.read_csv( "msft.csv", parse_dates=["Date"])
IBM = pd.read_csv( "ibm.csv", parse_dates=["Date"])

xyvalues = OrderedDict(
    AAPL = AAPL[("Date", "Adj Close")],
    MSFT = MSFT[("Date", "Adj Close")],
    IBM  = IBM[("Date", "Adj Close")],
)
df = pd.concat(xyvalues, axis=1, names=["l0", "l1"])

from bokeh.charts import TimeSeries
ts = TimeSeries(
    df, title="timeseries, pd_input",
    filename="stocks_timeseries.html")
ts.legend("top_left").show()

(Taken from the release note: http://continuum.io/blog/bokeh-0.6 )

Thank you very much in advance for your help

2 Answers2

1

it's definitely true that the developing and documenting the JS interface has lagged behind the other interfaces (python mostly, but also scala and Julia and soon R). We plan to improve this, but as you can imagine there are lots of competing priorities.

But I will mention another option, in case it is useful to you. It is possible to create the plot JS from python, and then use the JS directly. That is you only use python to set things up, then you can throw the python away. You can use functions in bokeh.embed to turn your python plot object graph into JS that you can embed however you like.

With more recent version of Bokeh, you can also easily grab ahold of the plot objects (for instance data sources) to update the plot directly from JS. See, for instance:

https://github.com/bokeh/bokeh/blob/master/examples/embed/spectrogram/spectrogram.coffee#L187

bigreddot
  • 33,642
  • 5
  • 69
  • 122
  • hi, sorry for the late reply. First of all - i didnt get to say thank you for bokeh. Its a great product, and I have not been able to find anything like it on the market - so bokeh is really good and I believe there is a gap in the available plotting tools out there which bokeh may cover. I have been looking at creating a python-bokeh library as you suggested, but i am not much of a coffee script guy... and would be really great to actually do this in bokehJS. So is there no way to change the js code above to contain multiple lines in any way? eg. pass multiple lines in the data array? – Hille Bergman Dec 04 '14 at 18:48
0

ahhh now i have seemed to figure this one out. To enable multiple lines, it seems i can do like this:

Bokeh.Plotting.show(
      Bokeh.Plotting.make_plot([{type:'line'},{type:'line'}], [{x:[1,2],y:[4,5]},{x:[1,4],y:[2,5]}], {})
      ,'.mydivcontainer');

Great :)

  • FYI here is a GH issue you can track (or add to the discussion) about the JS interface: https://github.com/bokeh/bokeh/issues/1515 – bigreddot Dec 09 '14 at 17:15