How to use index values in bokeh.charts?

I use DataFrames with custom index values, e.g.:

  a

10 0
20 1
30 2
40 3

When I use bokeh.charts I get:

The index is labeled from 0 to 3 instead from 10 to 40.

Is there any way to use the index values?

My test code:

if name == ‘main’:

from bokeh.io import show, output_file

from bokeh.charts import Line

import pandas

import subprocess

import time

a test DataFrame

d = {‘a’: [0,1,2,3]}

index = [10,20,30,40]

df = pandas.DataFrame(data=d, index=index)

print(df)

starting the bokeh server

args = [‘python’, ‘-m’, ‘bokeh’, ‘serve’]

p = subprocess.Popen(args)

time.sleep(1) #waiting for the bokeh server to initialize

output_file(‘test.html’)

plot_w = 500

plot_h = 300

p = Line(df,

title=“Test”,

plot_width = plot_w,

plot_height = plot_h,

)

show(p)

``

Hi Daniel,

I don’t see a simple way to indicate to Line that you want to use the index values of the dataframe as the x values. There may be a design decision not to automatically use the index of the dataframe.

One way to work around this is to add the index as a column and tell Line to use that.

p = Line(data=df.assign(x=df.index), x=‘x’, y=‘a’, title=“Test”, plot_width=500, plot_height=300)

``

Hope this helps.

Dennis

···

On Sunday, April 17, 2016 at 9:00:27 AM UTC-7, Daniel Krause wrote:

I use DataFrames with custom index values, e.g.:

  a

10 0
20 1
30 2
40 3

When I use bokeh.charts I get:

The index is labeled from 0 to 3 instead from 10 to 40.

Is there any way to use the index values?

My test code:

if name == ‘main’:

from bokeh.io import show, output_file

from bokeh.charts import Line

import pandas

import subprocess

import time

a test DataFrame

d = {‘a’: [0,1,2,3]}

index = [10,20,30,40]

df = pandas.DataFrame(data=d, index=index)

print(df)

starting the bokeh server

args = [‘python’, ‘-m’, ‘bokeh’, ‘serve’]

p = subprocess.Popen(args)

time.sleep(1) #waiting for the bokeh server to initialize

output_file(‘test.html’)

plot_w = 500

plot_h = 300

p = Line(df,

title=“Test”,

plot_width = plot_w,

plot_height = plot_h,

)

show(p)

``

If there's not currently a way to use the index, it might be worth opening an issue to discuss adding that capability.

Bryan

···

On Apr 18, 2016, at 12:27 AM, Dennis O'Brien <[email protected]> wrote:

Hi Daniel,

I don't see a simple way to indicate to Line that you want to use the index values of the dataframe as the x values. There may be a design decision not to automatically use the index of the dataframe.

One way to work around this is to add the index as a column and tell Line to use that.
p = Line(data=df.assign(x=df.index), x='x', y='a', title="Test", plot_width=500, plot_height=300)

Hope this helps.
Dennis

On Sunday, April 17, 2016 at 9:00:27 AM UTC-7, Daniel Krause wrote:
I use DataFrames with custom index values, e.g.:

      a
10 0
20 1
30 2
40 3

When I use bokeh.charts I get:

The index is labeled from 0 to 3 instead from 10 to 40.

Is there any way to use the index values?

My test code:

if __name__ == '__main__':
    from bokeh.io import show, output_file
    from bokeh.charts import Line
    import pandas
    import subprocess
    import time
    
    # a test DataFrame
    d = {'a': [0,1,2,3]}
    index = [10,20,30,40]
    df = pandas.DataFrame(data=d, index=index)
    print(df)
    
    # starting the bokeh server
    args = ['python', '-m', 'bokeh', 'serve']
    p = subprocess.Popen(args)
    time.sleep(1) #waiting for the bokeh server to initialize
     
    output_file('test.html')
    
    plot_w = 500
    plot_h = 300

    p = Line(df,
              title="Test",
              plot_width = plot_w,
              plot_height = plot_h,
              )
    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/93a1929b-9260-4c16-abc7-00c748e5df83%40continuum.io\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.

Added this issue: https://github.com/bokeh/bokeh/issues/4183

···

On Sun, Apr 17, 2016 at 10:35 PM Bryan Van de Ven [email protected] wrote:

If there’s not currently a way to use the index, it might be worth opening an issue to discuss adding that capability.

Bryan

On Apr 18, 2016, at 12:27 AM, Dennis O’Brien [email protected] wrote:

Hi Daniel,

I don’t see a simple way to indicate to Line that you want to use the index values of the dataframe as the x values. There may be a design decision not to automatically use the index of the dataframe.

One way to work around this is to add the index as a column and tell Line to use that.

p = Line(data=df.assign(x=df.index), x=‘x’, y=‘a’, title=“Test”, plot_width=500, plot_height=300)

Hope this helps.

Dennis

On Sunday, April 17, 2016 at 9:00:27 AM UTC-7, Daniel Krause wrote:

I use DataFrames with custom index values, e.g.:

  a

10 0

20 1

30 2

40 3

When I use bokeh.charts I get:

The index is labeled from 0 to 3 instead from 10 to 40.

Is there any way to use the index values?

My test code:

if name == ‘main’:

from [bokeh.io](http://bokeh.io) import show, output_file
from bokeh.charts import Line
import pandas
import subprocess
import time
# a test DataFrame
d = {'a': [0,1,2,3]}
index = [10,20,30,40]
df = pandas.DataFrame(data=d, index=index)
print(df)
# starting the bokeh server
args = ['python', '-m', 'bokeh', 'serve']
p = subprocess.Popen(args)
time.sleep(1) #waiting for the bokeh server to initialize
output_file('test.html')
plot_w = 500
plot_h = 300
p = Line(df,
          title="Test",
          plot_width = plot_w,
          plot_height = plot_h,
          )
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/93a1929b-9260-4c16-abc7-00c748e5df83%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/8D76EEB9-70FE-4A25-A540-CC36B65D9CDE%40continuum.io.

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

Thanks Dennis for your workaraound and for opening an issue.

The test DataFrame was deliberately small.

Normally I have DataFrames with many (>>100) columns like this:

d = {‘a’: [0,1,2,3],

‘b’: [4,5,6,7]

…,

‘z’: [96,97,98,99]}

``

Is there a way to change

p = Line(data=df.assign(x=df.index), x='x', y='a', title="Test", plot_width=500, plot_height=300)

``

to something like this

p = Line([...], y=<every column except 'x'>, [...])

``

without having to name every column explicitly?

Thanks

Daniel

···

Am Montag, 18. April 2016 08:33:34 UTC+2 schrieb Dennis O’Brien:

Added this issue: https://github.com/bokeh/bokeh/issues/4183

On Sun, Apr 17, 2016 at 10:35 PM Bryan Van de Ven [email protected] wrote:

If there’s not currently a way to use the index, it might be worth opening an issue to discuss adding that capability.

Bryan

On Apr 18, 2016, at 12:27 AM, Dennis O’Brien [email protected] wrote:

Hi Daniel,

I don’t see a simple way to indicate to Line that you want to use the index values of the dataframe as the x values. There may be a design decision not to automatically use the index of the dataframe.

One way to work around this is to add the index as a column and tell Line to use that.

p = Line(data=df.assign(x=df.index), x=‘x’, y=‘a’, title=“Test”, plot_width=500, plot_height=300)

Hope this helps.

Dennis

On Sunday, April 17, 2016 at 9:00:27 AM UTC-7, Daniel Krause wrote:

I use DataFrames with custom index values, e.g.:

  a

10 0

20 1

30 2

40 3

When I use bokeh.charts I get:

The index is labeled from 0 to 3 instead from 10 to 40.

Is there any way to use the index values?

My test code:

if name == ‘main’:

from [bokeh.io](http://bokeh.io) import show, output_file
from bokeh.charts import Line
import pandas
import subprocess
import time
# a test DataFrame
d = {'a': [0,1,2,3]}
index = [10,20,30,40]
df = pandas.DataFrame(data=d, index=index)
print(df)
# starting the bokeh server
args = ['python', '-m', 'bokeh', 'serve']
p = subprocess.Popen(args)
time.sleep(1) #waiting for the bokeh server to initialize
output_file('test.html')
plot_w = 500
plot_h = 300
p = Line(df,
          title="Test",
          plot_width = plot_w,
          plot_height = plot_h,
          )
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/93a1929b-9260-4c16-abc7-00c748e5df83%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/8D76EEB9-70FE-4A25-A540-CC36B65D9CDE%40continuum.io.

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

I found an answer to my question:

a test DataFrame

d = {‘a’: [0,1,2,3],

‘b’: [4,5,6,7]}

index = [10,20,30,40]

df = pandas.DataFrame(data=d, index=index)

adding the index as column

df = df.assign(x=df.index)
columns = df.columns.values.tolist()

columns.remove(‘x’)

p = Line(data=df,

x=‘x’, y=columns,

title=“Test”,

plot_width=500, plot_height=300)

``

···

Am Dienstag, 19. April 2016 21:23:35 UTC+2 schrieb Daniel Krause:

Thanks Dennis for your workaraound and for opening an issue.

The test DataFrame was deliberately small.

Normally I have DataFrames with many (>>100) columns like this:

d = {‘a’: [0,1,2,3],

‘b’: [4,5,6,7]

…,

‘z’: [96,97,98,99]}

``

Is there a way to change

p = Line(data=df.assign(x=df.index), x='x', y='a', title="Test", plot_width=500, plot_height=300)

``

to something like this

p = Line([...], y=<every column except 'x'>, [...])

``

without having to name every column explicitly?

Thanks

Daniel

Am Montag, 18. April 2016 08:33:34 UTC+2 schrieb Dennis O’Brien:

Added this issue: https://github.com/bokeh/bokeh/issues/4183

On Sun, Apr 17, 2016 at 10:35 PM Bryan Van de Ven [email protected] wrote:

If there’s not currently a way to use the index, it might be worth opening an issue to discuss adding that capability.

Bryan

On Apr 18, 2016, at 12:27 AM, Dennis O’Brien [email protected] wrote:

Hi Daniel,

I don’t see a simple way to indicate to Line that you want to use the index values of the dataframe as the x values. There may be a design decision not to automatically use the index of the dataframe.

One way to work around this is to add the index as a column and tell Line to use that.

p = Line(data=df.assign(x=df.index), x=‘x’, y=‘a’, title=“Test”, plot_width=500, plot_height=300)

Hope this helps.

Dennis

On Sunday, April 17, 2016 at 9:00:27 AM UTC-7, Daniel Krause wrote:

I use DataFrames with custom index values, e.g.:

  a

10 0

20 1

30 2

40 3

When I use bokeh.charts I get:

The index is labeled from 0 to 3 instead from 10 to 40.

Is there any way to use the index values?

My test code:

if name == ‘main’:

from [bokeh.io](http://bokeh.io) import show, output_file
from bokeh.charts import Line
import pandas
import subprocess
import time
# a test DataFrame
d = {'a': [0,1,2,3]}
index = [10,20,30,40]
df = pandas.DataFrame(data=d, index=index)
print(df)
# starting the bokeh server
args = ['python', '-m', 'bokeh', 'serve']
p = subprocess.Popen(args)
time.sleep(1) #waiting for the bokeh server to initialize
output_file('test.html')
plot_w = 500
plot_h = 300
p = Line(df,
          title="Test",
          plot_width = plot_w,
          plot_height = plot_h,
          )
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/93a1929b-9260-4c16-abc7-00c748e5df83%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/8D76EEB9-70FE-4A25-A540-CC36B65D9CDE%40continuum.io.

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