How Can I plot a Joyplot using Bokeh?

588 Views Asked by At

EDIT 2

I fixed one part of the code that was wrong, With that line of code, I add the category for every information (Axis X).

y = joy(cat, EveryTest[i].GPS)

After adding that line of code, the graph improved, but something is still failing. The graph starts with the 4th category (I mean 12:40:00), and it must start in the first (12:10:00), What I am doing wrong?

enter image description here

EDIT 1:

I Updated Bkoeh to 0.12.13, then the label problem was fixed. Now my problem is: I suppose the loop for (for i, cat in enumerate(reversed(cats)):) put every chart on the label, but do not happen that. I see the chart stuck in the 5th o 6th label. (12:30:00 or 12:50:00)

enter image description here

- Start of question -

I am trying to reproduce the example of joyplot. But I have trouble when I want to lot my own data. I dont want to plot an histogram, I want to plot some list in X and some list in Y. But I do not understand what I am doing wrong.

the code (Fixed):

from numpy import linspace
from scipy.stats.kde import gaussian_kde
from bokeh.io import output_file, show
from bokeh.models import ColumnDataSource, FixedTicker, PrintfTickFormatter
from bokeh.plotting import figure
#from bokeh.sampledata.perceptions import probly 
bokeh.BOKEH_RESOURCES='inline'
import colorcet as cc

output_file("joyplot.html")

def joy(category, data, scale=20):
    return list(zip([category]*len(data),data))

#Elements = 7

cats = ListOfTime #  list(reversed(probly.keys())) #list(['Pos_1','Pos_2']) #

print len(cats),' lengh of times'

palette = [cc.rainbow[i*15] for i in range(16)]
palette += palette
print len(palette),'lengh palette'
x = X # linspace(-20,110, 500) #Test.X #
print len(x),' lengh X'
source = ColumnDataSource(data=dict(x=x))

p = figure(y_range=cats, plot_width=900, x_range=(0, 1500), toolbar_location=None)

for i, cat in enumerate(reversed(cats)):
    y = joy(cat, EveryTest[i].GPS)
    #print cat
    source.add(y, cat)
    p.patch('x', cat, color=palette[i], alpha=0.6, line_color="black", source=source)
    #break
print source
p.outline_line_color = None
p.background_fill_color = "#efefef"

p.xaxis.ticker = FixedTicker(ticks=list(range(0, 1500, 100)))
#p.xaxis.formatter = PrintfTickFormatter(format="%d%%")

p.ygrid.grid_line_color = None
p.xgrid.grid_line_color = "#dddddd"
p.xgrid.ticker = p.xaxis[0].ticker

p.axis.minor_tick_line_color = None
p.axis.major_tick_line_color = None
p.axis.axis_line_color = None

#p.y_range.range_padding = 0.12
#p
show(p)

the variables are:

print X, type(X)
[ 3  6  9 12 15 18 21 24 27 30 33 36 39 42 45 48 51 54 57 60 63 66 69 72 75
 78 81 84 87 90 93 96 99] <type 'numpy.ndarray'>

and

print EveryTest[0].GPS, type(EveryTest[i].GPS)
0     2
1     2
2     2
3     2
4     2
5     2
6     2
7     2
8     2
9     2
10    2
11    2
12    2
13    2
14    2
15    2
16    2
17    2
18    2
19    2
20    2
21    2
22    2
23    2
24    2
25    2
26    2
27    2
28    2
29    2
30    2
31    2
32    2
Name: GPS, dtype: int64 <class 'pandas.core.series.Series'>

Following the example, the type of data its ok. But I get the next image: enter image description here

And I expected something like this: enter image description here

0

There are 0 best solutions below