dataformat for multiple lines in bokehjs

551 views Asked by At

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

There are 2 answers

1
bigreddot On

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

1
Hille Bergman On

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 :)