Plotting time intervals with bokeh?

I was wondering how to plot pairs of timestamps in a simple graph such as the one in the picture.

What I have is a Python list such as:

[‘Friday 11 March 2016 08:43:07AM’, ‘Friday 11 March 2016 08:47:07AM’, ‘Friday 11 March 2016 08:52:08AM’, ‘Friday 11 March 2016 08:59:09AM’]

The first item of the list is the start time of the first interval, the second is the end time of the first interval, and so on there may be dozens of intervals in the list. I can also iterate through the list and export it to a pandas dataframe with a Start and an End column where each pair is stored as a dataframe row.

However, I have no idea how I could produce the following graph with bokeh.

Any idea?

A minimal example:

import pandas as pd

import numpy as np

setup range

rng = pd.date_range(start=‘3/11/16’, periods=48, freq=‘H’ )

td = pd.Series([ pd.Timedelta(minutes=i) for i in np.random.randint(0,59,48) ])

interval = pd.DataFrame({‘start’ : rng })

interval[‘end’] = interval[‘start’] + td

from bokeh.models import ColumnDataSource

from bokeh.plotting import figure, show, output_file

cds_df = ColumnDataSource(interval)

p = figure(x_axis_type=‘datetime’, plot_height=100, plot_width=500, responsive=True)

hide the toolbar

p.toolbar_location=None

formatting

p.yaxis.minor_tick_line_color = None

p.ygrid[0].ticker.desired_num_ticks = 1

y1 = p.quad(left=‘start’,right=‘end’,bottom=0, top=1, source=cds_df )

output_file(“time_interval.html”, mode=‘cdn’)

show(p)

···

On Fri, Mar 11, 2016 at 1:06 PM, [email protected] wrote:

I was wondering how to plot pairs of timestamps in a simple graph such as the one in the picture.

What I have is a Python list such as:

[‘Friday 11 March 2016 08:43:07AM’, ‘Friday 11 March 2016 08:47:07AM’, ‘Friday 11 March 2016 08:52:08AM’, ‘Friday 11 March 2016 08:59:09AM’]

The first item of the list is the start time of the first interval, the second is the end time of the first interval, and so on there may be dozens of intervals in the list. I can also iterate through the list and export it to a pandas dataframe with a Start and an End column where each pair is stored as a dataframe row.

However, I have no idea how I could produce the following graph with bokeh.

Any idea?

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/8d834890-af42-42db-afe5-832ff2859cb6%40continuum.io.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.

Jeff Harris
BridgeSpan Financial
1001 19th Street North
Suite 1200
Arlington, VA 22209
[email protected]
Company: (703) 341-5999
Cell: (703) 389-5867

  • you can now follow us on both Facebook and Twitter. Keyword: SAFESTART *

This electronic mail message and any associated files contain information that (a) is or may be LEGALLY PRIVILEGED, CONFIDENTIAL, PROPRIETARY IN NATURE, OR OTHERWISE PROTECTED BY LAW FROM DISCLOSURE, and (b) is intended only for the use of the Addressee(s) named herein. If you are not the intended recipient, an addressee, or the person responsible for delivering this to an addressee, you are hereby notified that reading, using, copying, or distributing all or any part of this message is strictly prohibited. If you have received this electronic mail message in error, please contact us immediately by replying to this message and taking the steps necessary to delete the message completely from your computer system.


I was wondering how to plot pairs of timestamps in a simple graph such as the one in the picture.

What I have is a Python list such as:

[‘Friday 11 March 2016 08:43:07AM’, ‘Friday 11 March 2016 08:47:07AM’, ‘Friday 11 March 2016 08:52:08AM’, ‘Friday 11 March 2016 08:59:09AM’]

The first item of the list is the start time of the first interval, the second is the end time of the first interval, and so on there may be dozens of intervals in the list. I can also iterate through the list and export it to a pandas dataframe with a Start and an End column where each pair is stored as a dataframe row.

However, I have no idea how I could produce the following graph with bokeh.

Any idea?

···

On Friday, March 11, 2016 at 2:06:47 PM UTC+1, A.S wrote:

Thanks a lot!

That’s elegant and it is working.

The only problem I am seeing is that if I allow a toolbar and then press the reset widget, the graph will squeeze and disappear.

Do you know why or if there is any solution to that?

···

On Friday, March 11, 2016 at 3:59:31 PM UTC+1, Jeff Harris wrote:

A minimal example:

import pandas as pd

import numpy as np

setup range

rng = pd.date_range(start=‘3/11/16’, periods=48, freq=‘H’ )

td = pd.Series([ pd.Timedelta(minutes=i) for i in np.random.randint(0,59,48) ])

interval = pd.DataFrame({‘start’ : rng })

interval[‘end’] = interval[‘start’] + td

from bokeh.models import ColumnDataSource

from bokeh.plotting import figure, show, output_file

cds_df = ColumnDataSource(interval)

p = figure(x_axis_type=‘datetime’, plot_height=100, plot_width=500, responsive=True)

hide the toolbar

p.toolbar_location=None

formatting

p.yaxis.minor_tick_line_color = None

p.ygrid[0].ticker.desired_num_ticks = 1

y1 = p.quad(left=‘start’,right=‘end’,bottom=0, top=1, source=cds_df )

output_file(“time_interval.html”, mode=‘cdn’)

show(p)

On Fri, Mar 11, 2016 at 1:06 PM, [email protected] wrote:

I was wondering how to plot pairs of timestamps in a simple graph such as the one in the picture.

What I have is a Python list such as:

[‘Friday 11 March 2016 08:43:07AM’, ‘Friday 11 March 2016 08:47:07AM’, ‘Friday 11 March 2016 08:52:08AM’, ‘Friday 11 March 2016 08:59:09AM’]

The first item of the list is the start time of the first interval, the second is the end time of the first interval, and so on there may be dozens of intervals in the list. I can also iterate through the list and export it to a pandas dataframe with a Start and an End column where each pair is stored as a dataframe row.

However, I have no idea how I could produce the following graph with bokeh.

Any idea?

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/8d834890-af42-42db-afe5-832ff2859cb6%40continuum.io.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.


Jeff Harris
BridgeSpan Financial
1001 19th Street North
Suite 1200
Arlington, VA 22209
[email protected]
Company: (703) 341-5999
Cell: (703) 389-5867

  • you can now follow us on both Facebook and Twitter. Keyword: SAFESTART *

This electronic mail message and any associated files contain information that (a) is or may be LEGALLY PRIVILEGED, CONFIDENTIAL, PROPRIETARY IN NATURE, OR OTHERWISE PROTECTED BY LAW FROM DISCLOSURE, and (b) is intended only for the use of the Addressee(s) named herein. If you are not the intended recipient, an addressee, or the person responsible for delivering this to an addressee, you are hereby notified that reading, using, copying, or distributing all or any part of this message is strictly prohibited. If you have received this electronic mail message in error, please contact us immediately by replying to this message and taking the steps necessary to delete the message completely from your computer system.


I'm not sure about the reset issue offhand, but I did also want to mention the recent BoxAnnotation as another possible option. You can tell it automatically span an entire dimension (e.g. all the way from bottom to top in this example) regardless of data bounds. See,

  http://bokeh.pydata.org/en/latest/docs/user_guide/plotting.html#box-annotations

Thanks,

Bryan

···

On Mar 12, 2016, at 1:31 PM, A.S <[email protected]> wrote:

Thanks a lot!

That's elegant and it is working.

The only problem I am seeing is that if I allow a toolbar and then press the reset widget, the graph will squeeze and disappear.

Do you know why or if there is any solution to that?

On Friday, March 11, 2016 at 3:59:31 PM UTC+1, Jeff Harris wrote:
A minimal example:

import pandas as pd
import numpy as np

# setup range
rng = pd.date_range(start='3/11/16', periods=48, freq='H' )
td = pd.Series([ pd.Timedelta(minutes=i) for i in np.random.randint(0,59,48) ])

interval = pd.DataFrame({'start' : rng })
interval['end'] = interval['start'] + td

from bokeh.models import ColumnDataSource
from bokeh.plotting import figure, show, output_file

cds_df = ColumnDataSource(interval)

p = figure(x_axis_type='datetime', plot_height=100, plot_width=500, responsive=True)

# hide the toolbar
p.toolbar_location=None

# formatting
p.yaxis.minor_tick_line_color = None
p.ygrid[0].ticker.desired_num_ticks = 1

y1 = p.quad(left='start',right='end',bottom=0, top=1, source=cds_df )

output_file("time_interval.html", mode='cdn')
show(p)

On Fri, Mar 11, 2016 at 1:06 PM, <[email protected]> wrote:
I was wondering how to plot pairs of timestamps in a simple graph such as the one in the picture.

What I have is a Python list such as:

['Friday 11 March 2016 08:43:07AM', 'Friday 11 March 2016 08:47:07AM', 'Friday 11 March 2016 08:52:08AM', 'Friday 11 March 2016 08:59:09AM']

The first item of the list is the start time of the first interval, the second is the end time of the first interval, and so on there may be dozens of intervals in the list. I can also iterate through the list and export it to a pandas dataframe with a Start and an End column where each pair is stored as a dataframe row.

However, I have no idea how I could produce the following graph with bokeh.

Any idea?

--
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 bokeh+un...@continuum.io.
To post to this group, send email to bo...@continuum.io.
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/8d834890-af42-42db-afe5-832ff2859cb6%40continuum.io\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.

--
Jeff Harris
BridgeSpan Financial
1001 19th Street North
Suite 1200
Arlington, VA 22209
jeff....@bridge-span.com
Company: (703) 341-5999
Cell: (703) 389-5867

* you can now follow us on both Facebook and Twitter. Keyword: SAFESTART *

----------

This electronic mail message and any associated files contain information that (a) is or may be LEGALLY PRIVILEGED, CONFIDENTIAL, PROPRIETARY IN NATURE, OR OTHERWISE PROTECTED BY LAW FROM DISCLOSURE, and (b) is intended only for the use of the Addressee(s) named herein. If you are not the intended recipient, an addressee, or the person responsible for delivering this to an addressee, you are hereby notified that reading, using, copying, or distributing all or any part of this message is strictly prohibited. If you have received this electronic mail message in error, please contact us immediately by replying to this message and taking the steps necessary to delete the message completely from your computer system.

----------

--
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/da3291d9-6b5e-4de2-b843-bc3b51452139%40continuum.io\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.

The disappearing chart issue seems to be related to the explicit plot_height and plot_width sizes passed to figure(), along with responsive=True.

First: if you remove responsive=True (which scales the chart to the container size), you’ll see that the explicit height I used wasn’t tall enough to display the chart.

The quick fix – just pick explicit sizes that work. E.g.:

p = figure(x_axis_type=‘datetime’, plot_height=120, plot_width=500, y_range=(0,1))

Second – this is a question for Bryan and the dev’s:

The ‘reset’ tool seems to override the responsive flag if it was passed, and resets the chart to plot_height & plot_width (if passed). By design, or bug?

···

On Sat, Mar 12, 2016 at 8:13 PM, Bryan Van de Ven [email protected] wrote:

I’m not sure about the reset issue offhand, but I did also want to mention the recent BoxAnnotation as another possible option. You can tell it automatically span an entire dimension (e.g. all the way from bottom to top in this example) regardless of data bounds. See,

    [http://bokeh.pydata.org/en/latest/docs/user_guide/plotting.html#box-annotations](http://bokeh.pydata.org/en/latest/docs/user_guide/plotting.html#box-annotations)

Thanks,

Bryan

On Mar 12, 2016, at 1:31 PM, A.S [email protected] wrote:

Thanks a lot!

That’s elegant and it is working.

The only problem I am seeing is that if I allow a toolbar and then press the reset widget, the graph will squeeze and disappear.

Do you know why or if there is any solution to that?

On Friday, March 11, 2016 at 3:59:31 PM UTC+1, Jeff Harris wrote:

A minimal example:

import pandas as pd

import numpy as np

setup range

rng = pd.date_range(start=‘3/11/16’, periods=48, freq=‘H’ )

td = pd.Series([ pd.Timedelta(minutes=i) for i in np.random.randint(0,59,48) ])

interval = pd.DataFrame({‘start’ : rng })

interval[‘end’] = interval[‘start’] + td

from bokeh.models import ColumnDataSource

from bokeh.plotting import figure, show, output_file

cds_df = ColumnDataSource(interval)

p = figure(x_axis_type=‘datetime’, plot_height=100, plot_width=500, responsive=True)

hide the toolbar

p.toolbar_location=None

formatting

p.yaxis.minor_tick_line_color = None

p.ygrid[0].ticker.desired_num_ticks = 1

y1 = p.quad(left=‘start’,right=‘end’,bottom=0, top=1, source=cds_df )

output_file(“time_interval.html”, mode=‘cdn’)

show(p)

On Fri, Mar 11, 2016 at 1:06 PM, [email protected] wrote:

I was wondering how to plot pairs of timestamps in a simple graph such as the one in the picture.

What I have is a Python list such as:

[‘Friday 11 March 2016 08:43:07AM’, ‘Friday 11 March 2016 08:47:07AM’, ‘Friday 11 March 2016 08:52:08AM’, ‘Friday 11 March 2016 08:59:09AM’]

The first item of the list is the start time of the first interval, the second is the end time of the first interval, and so on there may be dozens of intervals in the list. I can also iterate through the list and export it to a pandas dataframe with a Start and an End column where each pair is stored as a dataframe row.

However, I have no idea how I could produce the following graph with bokeh.

Any idea?

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/8d834890-af42-42db-afe5-832ff2859cb6%40continuum.io.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.

Jeff Harris

BridgeSpan Financial

1001 19th Street North

Suite 1200

Arlington, VA 22209

[email protected]

Company: (703) 341-5999

Cell: (703) 389-5867

  • you can now follow us on both Facebook and Twitter. Keyword: SAFESTART *

This electronic mail message and any associated files contain information that (a) is or may be LEGALLY PRIVILEGED, CONFIDENTIAL, PROPRIETARY IN NATURE, OR OTHERWISE PROTECTED BY LAW FROM DISCLOSURE, and (b) is intended only for the use of the Addressee(s) named herein. If you are not the intended recipient, an addressee, or the person responsible for delivering this to an addressee, you are hereby notified that reading, using, copying, or distributing all or any part of this message is strictly prohibited. If you have received this electronic mail message in error, please contact us immediately by replying to this message and taking the steps necessary to delete the message completely from your computer system.


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/da3291d9-6b5e-4de2-b843-bc3b51452139%40continuum.io.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.

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/78BA9C8C-EC05-46F4-ADE4-6A732017D4E4%40continuum.io.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.

Jeff Harris
BridgeSpan Financial
1001 19th Street North
Suite 1200
Arlington, VA 22209
[email protected]
Company: (703) 341-5999
Cell: (703) 389-5867

  • you can now follow us on both Facebook and Twitter. Keyword: SAFESTART *

This electronic mail message and any associated files contain information that (a) is or may be LEGALLY PRIVILEGED, CONFIDENTIAL, PROPRIETARY IN NATURE, OR OTHERWISE PROTECTED BY LAW FROM DISCLOSURE, and (b) is intended only for the use of the Addressee(s) named herein. If you are not the intended recipient, an addressee, or the person responsible for delivering this to an addressee, you are hereby notified that reading, using, copying, or distributing all or any part of this message is strictly prohibited. If you have received this electronic mail message in error, please contact us immediately by replying to this message and taking the steps necessary to delete the message completely from your computer system.


I also use quad to a plot like yours.
In my case I use it on auxilary plot linked with the main.

The only addition I see in my code is the following:

aux_plot.x_range.bounds = ‘auto’

aux_plot.y_range.bounds = ‘auto’

And it fully works as expected.

Regards,

Dmitry

···

On Saturday, March 12, 2016 at 10:31:14 PM UTC+3, A.S wrote:

Thanks a lot!

That’s elegant and it is working.

The only problem I am seeing is that if I allow a toolbar and then press the reset widget, the graph will squeeze and disappear.

Do you know why or if there is any solution to that?

On Friday, March 11, 2016 at 3:59:31 PM UTC+1, Jeff Harris wrote:

A minimal example:

import pandas as pd

import numpy as np

setup range

rng = pd.date_range(start=‘3/11/16’, periods=48, freq=‘H’ )

td = pd.Series([ pd.Timedelta(minutes=i) for i in np.random.randint(0,59,48) ])

interval = pd.DataFrame({‘start’ : rng })

interval[‘end’] = interval[‘start’] + td

from bokeh.models import ColumnDataSource

from bokeh.plotting import figure, show, output_file

cds_df = ColumnDataSource(interval)

p = figure(x_axis_type=‘datetime’, plot_height=100, plot_width=500, responsive=True)

hide the toolbar

p.toolbar_location=None

formatting

p.yaxis.minor_tick_line_color = None

p.ygrid[0].ticker.desired_num_ticks = 1

y1 = p.quad(left=‘start’,right=‘end’,bottom=0, top=1, source=cds_df )

output_file(“time_interval.html”, mode=‘cdn’)

show(p)

On Fri, Mar 11, 2016 at 1:06 PM, [email protected] wrote:

I was wondering how to plot pairs of timestamps in a simple graph such as the one in the picture.

What I have is a Python list such as:

[‘Friday 11 March 2016 08:43:07AM’, ‘Friday 11 March 2016 08:47:07AM’, ‘Friday 11 March 2016 08:52:08AM’, ‘Friday 11 March 2016 08:59:09AM’]

The first item of the list is the start time of the first interval, the second is the end time of the first interval, and so on there may be dozens of intervals in the list. I can also iterate through the list and export it to a pandas dataframe with a Start and an End column where each pair is stored as a dataframe row.

However, I have no idea how I could produce the following graph with bokeh.

Any idea?

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/8d834890-af42-42db-afe5-832ff2859cb6%40continuum.io.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.


Jeff Harris
BridgeSpan Financial
1001 19th Street North
Suite 1200
Arlington, VA 22209
[email protected]
Company: (703) 341-5999
Cell: (703) 389-5867

  • you can now follow us on both Facebook and Twitter. Keyword: SAFESTART *

This electronic mail message and any associated files contain information that (a) is or may be LEGALLY PRIVILEGED, CONFIDENTIAL, PROPRIETARY IN NATURE, OR OTHERWISE PROTECTED BY LAW FROM DISCLOSURE, and (b) is intended only for the use of the Addressee(s) named herein. If you are not the intended recipient, an addressee, or the person responsible for delivering this to an addressee, you are hereby notified that reading, using, copying, or distributing all or any part of this message is strictly prohibited. If you have received this electronic mail message in error, please contact us immediately by replying to this message and taking the steps necessary to delete the message completely from your computer system.