How to set correct x axis with datetime index so that intervals are proper in the Bokeh plot?

I read csv having many columns including a Date column, as pandas dataframe called ‘breakageDf’.

Being ‘object’ type I convert the date column to string first then to datetime object

breakageDf["Date"] = breakageDf["Date"].astype("str")
breakageDf["Date"] = pd.to_datetime(breakageDf["Date"], format="%d-%m-%Y")

``

Then I set this Date column as index.

breakageDf = breakageDf.set_index("Date")

``

I wish to create a Bokeh line plot with Date as X axis and some other column values as Y axis.

p = figure(x_axis_type="datetime", width=w, height=h, tools=[hover, 'pan', 'wheel_zoom'])
p.line(breakageDf.index, breakageDf["BreakageValue"], color="#A6CEE3", legend="BreakageValue")

``

But the plot comes wrong. There is no spread on X axis at all.


Index when printed looks like

DatetimeIndex(['2015-03-05', '2015-03-07', '2015-03-10', '2015-03-11',
           '2015-03-12', '2015-03-12', '2015-03-15', '2015-03-15',
           '2015-03-15', '2015-03-20',
           ...
           '2016-02-21', '2016-02-23', '2016-02-26', '2016-02-27',
           '2016-02-28', '2016-03-08', '2016-03-14', '2016-03-15',
           '2016-03-17', '2016-03-18'],
          dtype='datetime64[ns]', name='Date', length=192, freq=None)

``

Is frequency being None, is the reason? Should it be Daily? How to set it programmatically? Or am I missing anything?

To get you to the point
of working (and then we can try and make this better):

  • try conv erting what you’re passing
    to x and y to pure python lists of datetimes and numbers

  • make SURE the l ists are the
    same length - this is a hard
    requirement for Bokeh which we try and check for
    but somet imes
    miss cases.

                                  Otherwise your
    

code looks right enough to me.

···

On 9/4/16 6:53 PM, Yogesh Kulkarni
wrote:

                  I read csv having many columns including a Date

column, as pandas dataframe called ‘breakageDf’.

                  Being 'object' type I convert the date column to

string first then to datetime object

breakageDf["Date"] = breakageDf["Date"].astype("str")
breakageDf["Date"] = pd.to_datetime(breakageDf["Date"], format="%d-%m-%Y")

``

                Then I set this Date column as index.
breakageDf = breakageDf.set_index("Date")

``

                  I wish to create a Bokeh line plot with Date as X

axis and some other column values as Y axis.

p = figure(x_axis_type="datetime", width=w, height=h, tools=[hover, 'pan', 'wheel_zoom'])
p.line(breakageDf.index, breakageDf["BreakageValue"], color="#A6CEE3", legend="BreakageValue")

``

                  But the plot comes wrong. There is no spread on X

axis at all.

[

                  ](https://lh3.googleusercontent.com/-fGheCf_-Tks/V8zPoUtMMuI/AAAAAAAAVPo/ENL0mP2SDv0yOL_MK5CSXPAvr5xKTKWzACLcB/s1600/ploterror.png)

Index when printed looks like

DatetimeIndex(['2015-03-05', '2015-03-07', '2015-03-10', '2015-03-11',
           '2015-03-12', '2015-03-12', '2015-03-15', '2015-03-15',
           '2015-03-15', '2015-03-20',
           ...
           '2016-02-21', '2016-02-23', '2016-02-26', '2016-02-27',
           '2016-02-28', '2016-03-08', '2016-03-14', '2016-03-15',
           '2016-03-17', '2016-03-18'],
          dtype='datetime64[ns]', name='Date', length=192, freq=None)

``

                  Is frequency being None, is the reason? Should it

be Daily? How to set it programmatically? Or am I
missing anything?

  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/b9328f2e-e47e-4fb6-bf2b-81295a674475%40continuum.io](https://groups.google.com/a/continuum.io/d/msgid/bokeh/b9328f2e-e47e-4fb6-bf2b-81295a674475%40continuum.io?utm_medium=email&utm_source=footer).

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


Sarah Bird
Developer, Bokeh

    [
      ![Continuum Analytics](http://docs.continuum.io/_static/img/ContinuumWordmark.png)
    ](http://continuum.io)

Thanks a lot.

Yes, further examination showed that one value was missing in the Date column. My bad. After correction the plot looked fine.

···

On Monday, September 5, 2016 at 10:04:13 AM UTC+5:30, Sarah Bird wrote:

To get you to the point
of working (and then we can try and make this better):

  • try conv erting what you’re passing
    to x and y to pure python lists of datetimes and numbers
  • make SURE the l ists are the
    same length - this is a hard
    requirement for Bokeh which we try and check for
    but somet imes
    miss cases.
                                Otherwise your

code looks right enough to me.

  On 9/4/16 6:53 PM, Yogesh Kulkarni > wrote:
                  I read csv having many columns including a Date

column, as pandas dataframe called ‘breakageDf’.

                  Being 'object' type I convert the date column to

string first then to datetime object

breakageDf["Date"] = breakageDf["Date"].astype("str")
breakageDf["Date"] = pd.to_datetime(breakageDf["Date"], format="%d-%m-%Y")

``

                Then I set this Date column as index.
breakageDf = breakageDf.set_index("Date")

``

                  I wish to create a Bokeh line plot with Date as X

axis and some other column values as Y axis.

p = figure(x_axis_type="datetime", width=w, height=h, tools=[hover, 'pan', 'wheel_zoom'])
p.line(breakageDf.index, breakageDf["BreakageValue"], color="#A6CEE3", legend="BreakageValue")

``

                  But the plot comes wrong. There is no spread on X

axis at all.

[

                  ](https://lh3.googleusercontent.com/-fGheCf_-Tks/V8zPoUtMMuI/AAAAAAAAVPo/ENL0mP2SDv0yOL_MK5CSXPAvr5xKTKWzACLcB/s1600/ploterror.png)

Index when printed looks like

DatetimeIndex(['2015-03-05', '2015-03-07', '2015-03-10', '2015-03-11',
           '2015-03-12', '2015-03-12', '2015-03-15', '2015-03-15',
           '2015-03-15', '2015-03-20',
           ...
           '2016-02-21', '2016-02-23', '2016-02-26', '2016-02-27',
           '2016-02-28', '2016-03-08', '2016-03-14', '2016-03-15',
           '2016-03-17', '2016-03-18'],
          dtype='datetime64[ns]', name='Date', length=192, freq=None)

``

                  Is frequency being None, is the reason? Should it

be Daily? How to set it programmatically? Or am I
missing anything?

  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/b9328f2e-e47e-4fb6-bf2b-81295a674475%40continuum.io](https://groups.google.com/a/continuum.io/d/msgid/bokeh/b9328f2e-e47e-4fb6-bf2b-81295a674475%40continuum.io?utm_medium=email&utm_source=footer).

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


Sarah Bird
Developer, Bokeh

    [
      <img alt="Continuum Analytics" src="https://lh6.googleusercontent.com/proxy/VYgVjggTk1hCXSN9wFkffE3I6kxTvJ51tT4KvDXOuKbs1WyFG66k7kt2-vkDimbyxfWtP-d1paJmstMYhPPnDYSUF4rLPoYM2GM2QFM=w5000-h5000" height="30px" width="150px">
    ](http://continuum.io)