DateTimes at x-axis

Hi,

i searched in the internet for this issue however all answers did not work. Let us have a look on the following snip shoot from a program code in python written with the package Bokeh

import bokeh

newDicht = dict()

newDicht[q1] = range(1:120)#120 data points on the y axis for key q1

newDicht[q2] = range(3:123)#120 data points on the y axis for key q2
area_THW = Area(newDicht, title=“Test”, legend=“top_left”,stack=True, xlabel=‘Time Horizon’, ylabel=’#Qs’)

Each y-coordinate corresponds to one x-axis element between 1 to 120. However, x=1 should represent a secific date time, e.g. x=1=01.01.2017 and each increment on the x-coordinate corresponds to an increment of one month starting at 01.01.2017. For example, x=2 corresponds to the date 01.02.2017, x=3 to date 01.03.2017 and so on. I there any possibility to format the x-axis for the area figure in this way?

Thanks,

Markus

If you would like dates on the x-axis, you can use a datetime index in a pandas dataframe object. If you want the dates to have a specific format you can use a datetimetick formatter to make it look how you want on different zoom levels.

all series in the dict must have the same corresponding datetimeindex.(index must match)

import pandas as pd

import datetime as dt

from bokeh.charts import Area, show, output_file

output_file(“area.html”)

start = dt.datetime(year=2017, month=1, day = 1)

dates = pd.date_range(start, periods = 120, freq = ‘B’)

data1 = list(i/2 for i in range(3,123))

data2 = list(range(3,123)

dataset2 = pd.Series(data2,index = dates)

dataset1 = pd.Series(data1,index = dates)

data = dict(data1=dataset1, data2=dataset2)

tool = ‘hover, save, wheel_zoom’

x = Area(data=data, tools = tool)

show(x)

···

On Monday, February 27, 2017 at 1:09:10 PM UTC-5, Mar kus wrote:

Hi,

i searched in the internet for this issue however all answers did not work. Let us have a look on the following snip shoot from a program code in python written with the package Bokeh

import bokeh

newDicht = dict()

newDicht[q1] = range(1:120)#120 data points on the y axis for key q1

newDicht[q2] = range(3:123)#120 data points on the y axis for key q2
area_THW = Area(newDicht, title=“Test”, legend=“top_left”,stack=True, xlabel=‘Time Horizon’, ylabel=‘#Qs’)

Each y-coordinate corresponds to one x-axis element between 1 to 120. However, x=1 should represent a secific date time, e.g. x=1=01.01.2017 and each increment on the x-coordinate corresponds to an increment of one month starting at 01.01.2017. For example, x=2 corresponds to the date 01.02.2017, x=3 to date 01.03.2017 and so on. I there any possibility to format the x-axis for the area figure in this way?

Thanks,

Markus

To format the dates
use:

from bokeh.models import DatetimeTickFormatter

``

and add:

formats = DatetimeTickFormatter(years= “%d.%m.%Y”, months = “%d.%m.%Y”, days = “%d.%m.%Y” )
x.xaxis[0].formatter =formats

``

···

On Monday, February 27, 2017 at 1:09:10 PM UTC-5, Mar kus wrote:

Hi,

i searched in the internet for this issue however all answers did not work. Let us have a look on the following snip shoot from a program code in python written with the package Bokeh

import bokeh

newDicht = dict()

newDicht[q1] = range(1:120)#120 data points on the y axis for key q1

newDicht[q2] = range(3:123)#120 data points on the y axis for key q2
area_THW = Area(newDicht, title=“Test”, legend=“top_left”,stack=True, xlabel=‘Time Horizon’, ylabel=‘#Qs’)

Each y-coordinate corresponds to one x-axis element between 1 to 120. However, x=1 should represent a secific date time, e.g. x=1=01.01.2017 and each increment on the x-coordinate corresponds to an increment of one month starting at 01.01.2017. For example, x=2 corresponds to the date 01.02.2017, x=3 to date 01.03.2017 and so on. I there any possibility to format the x-axis for the area figure in this way?

Thanks,

Markus