Fixed tickers along a datetime axis

With the help from another thread, I was able to come up with the following code which generates a quad type of graph.

I was trying to control the ticks of the plot. I tried the FixedTicker method, but that doesn’t seem to be working for my datetime axis. It seems like FixedTicker accepts Floats only. Do you know any workaround to this?

Here is my code:

import datetime
from bokeh.plotting import figure, show, output_file
from bokeh.models import FixedTicker

df=pd.DataFrame({“Start”:[datetime.datetime(2016, 3, 17, 15, 46, 2, 763666),
datetime.datetime(2016, 3, 17, 15, 46, 8, 74970),
datetime.datetime(2016,3, 17, 15, 46, 11, 323156)],
“End”:[datetime.datetime(2016, 3, 17, 15, 46, 3, 371701),
datetime.datetime(2016, 3, 17, 15, 46, 8, 138974),
datetime.datetime(2016, 3, 17, 15, 46, 11, 723179)]})

times=[datetime.datetime(2016, 3, 17, 15, 46, 2, 763666),
datetime.datetime(2016, 3, 17, 15, 46, 3, 371701),
datetime.datetime(2016, 3, 17, 15, 46, 8, 74970),
datetime.datetime(2016, 3, 17, 15, 46, 8, 138974),
datetime.datetime(2016,3, 17, 15, 46, 11, 323156),
datetime.datetime(2016, 3, 17, 15, 46, 11, 723179)]

p = figure(x_axis_type=‘datetime’, plot_height=100, plot_width=500, responsive=True, title=“Motion graph”, tools=‘reset’)

p.yaxis.minor_tick_line_color = None
p.ygrid[0].ticker.desired_num_ticks = 1
p.xaxis[0].ticker=FixedTicker(ticks=times)

y1 = p.quad(left=df[‘Start’],right=df[‘End’],bottom=0, top=1 )

output_file(“time_interval.html”)
show(p)

``

Hi,

Ultimately all tick values are numbers, even datetimes. In the case of datetimes the numbers are "milliseconds since epoch", so if you want to use a FixedTicker to define specific tick locations, that should be fine, but you will need to convert your datetime objects into numbers (milliseconds since 1970) "by hand" first.

It's possible that FixedTicker could be made more flexible or could do this kind of conversion implicitly. That would be a reasonable feature for a new contributor to look at.

Thanks,

Bryan

···

On Mar 17, 2016, at 10:23 AM, A.S <[email protected]> wrote:

With the help from another thread, I was able to come up with the following code which generates a quad type of graph.

I was trying to control the ticks of the plot. I tried the FixedTicker method, but that doesn't seem to be working for my datetime axis. It seems like FixedTicker accepts Floats only. Do you know any workaround to this?

Here is my code:

import datetime
from bokeh.plotting import figure, show, output_file
from bokeh.models import FixedTicker

df=pd.DataFrame({"Start":[datetime.datetime(2016, 3, 17, 15, 46, 2, 763666),
                          datetime.datetime(2016, 3, 17, 15, 46, 8, 74970),
                          datetime.datetime(2016,3, 17, 15, 46, 11, 323156)],
                 "End":[datetime.datetime(2016, 3, 17, 15, 46, 3, 371701),
                        datetime.datetime(2016, 3, 17, 15, 46, 8, 138974),
                        datetime.datetime(2016, 3, 17, 15, 46, 11, 723179)]})

times=[datetime.datetime(2016, 3, 17, 15, 46, 2, 763666),
       datetime.datetime(2016, 3, 17, 15, 46, 3, 371701),
       datetime.datetime(2016, 3, 17, 15, 46, 8, 74970),
       datetime.datetime(2016, 3, 17, 15, 46, 8, 138974),
       datetime.datetime(2016,3, 17, 15, 46, 11, 323156),
       datetime.datetime(2016, 3, 17, 15, 46, 11, 723179)]

p = figure(x_axis_type='datetime', plot_height=100, plot_width=500, responsive=True, title="Motion graph", tools='reset')

p.yaxis.minor_tick_line_color = None
p.ygrid[0].ticker.desired_num_ticks = 1
p.xaxis[0].ticker=FixedTicker(ticks=times)

y1 = p.quad(left=df['Start'],right=df['End'],bottom=0, top=1 )

output_file("time_interval.html")
show(p)

--
You received this message because you are subscribed to the Google Groups "Bokeh Discussion - Public" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/c4a62482-531c-4cec-8d47-11854f04a9cf%40continuum.io\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.

Thanks, very helpful!

···

On Thursday, March 17, 2016 at 4:23:12 PM UTC+1, A.S wrote:

With the help from another thread, I was able to come up with the following code which generates a quad type of graph.

I was trying to control the ticks of the plot. I tried the FixedTicker method, but that doesn’t seem to be working for my datetime axis. It seems like FixedTicker accepts Floats only. Do you know any workaround to this?

Here is my code:

import datetime
from bokeh.plotting import figure, show, output_file
from bokeh.models import FixedTicker

df=pd.DataFrame({“Start”:[datetime.datetime(2016, 3, 17, 15, 46, 2, 763666),
datetime.datetime(2016, 3, 17, 15, 46, 8, 74970),
datetime.datetime(2016,3, 17, 15, 46, 11, 323156)],
“End”:[datetime.datetime(2016, 3, 17, 15, 46, 3, 371701),
datetime.datetime(2016, 3, 17, 15, 46, 8, 138974),
datetime.datetime(2016, 3, 17, 15, 46, 11, 723179)]})

times=[datetime.datetime(2016, 3, 17, 15, 46, 2, 763666),
datetime.datetime(2016, 3, 17, 15, 46, 3, 371701),
datetime.datetime(2016, 3, 17, 15, 46, 8, 74970),
datetime.datetime(2016, 3, 17, 15, 46, 8, 138974),
datetime.datetime(2016,3, 17, 15, 46, 11, 323156),
datetime.datetime(2016, 3, 17, 15, 46, 11, 723179)]

p = figure(x_axis_type=‘datetime’, plot_height=100, plot_width=500, responsive=True, title=“Motion graph”, tools=‘reset’)

p.yaxis.minor_tick_line_color = None
p.ygrid[0].ticker.desired_num_ticks = 1
p.xaxis[0].ticker=FixedTicker(ticks=times)

y1 = p.quad(left=df[‘Start’],right=df[‘End’],bottom=0, top=1 )

output_file(“time_interval.html”)
show(p)

``