how to plot multiple columns of a dataframe with charts.Bar?

Hello,

I can not get my head around how to plot multiple columns as bars, for instance using the autompg example data which looks like this:

mpg cyl displ hp weight accel yr origin name
0 18 8 307 130 3504 12.0 70 1 chevrolet chevelle malibu
1 15 8 350 165 3693 11.5 70 1 buick skylark 320
2 18 8 318 150 3436 11.0 70 1 plymouth satellite

How
to plot bars of cyl, mpg and accel for each car name (the groups would be cyl, mpg and accel with each car name inside these groups) on a single bar chart?

Code:

from bokeh.charts import Bar, output_file, show
from bokeh.sampledata.autompg import autompg as df

print(df.head())
df=df.iloc[:10, :]

how to modify this:

p = Bar(df, label=‘name’, values=[‘cyl’, ‘mpg’, ‘accel’], title=‘mpg cyl accel for each car name’)
output_file(“bar.html”)
show(p)

``

Thanks for any help in advance!
I am using bokeh 10.0.

If you wonder why would I want to compare cyl mpg accel, just assume that they are comparable (in my dataframe those columns are comparable)!
It really bugs me that I can not figure out how to just plot several columns as bars. Is not bar chart for that just plot and compare several 1D data?

With the code above I always get this error:

raise ValueError(“expected an element of either %s, got %r” % (nice_join(self.type_params), value))

ValueError: expected an element of either Column(Float) or Column(String), got array([[ 8., 16., 12.]])

How should I make it Column?

Just as a sidenote, when bokeh does the sorting on the dataframe:

df = df.sort(columns=columns)

I get this warning:

/anaconda3/lib/python3.5/site-packages/bokeh/charts/_attributes.py:78: FutureWarning: sort(columns=…) is deprecated, use sort_values(by=…)

Hi,

Bar chart in 0.10 already implements the new API that is basically consolidated in 0.11. It was the first implementation of the this new interface and we added lots of improvements since then. For this reason I really encourage you to try to use the new 0.11 dev build we released last week an migrate to the final 0.11 when we release it in a few weeks.

That said, the new charts API provides you the blend operator to let you spell what you need (if I’m understanding your use case correctly). It may be the case that in the future we support the syntax you’ve tried to use in your example (specifying an iterable of columns on the values parameter) by inferring the data type but it has many implications and we need to be sure we are doing “it right” and not hiding different use cases.

Here’s a working version that should compare to your example:

from bokeh.sampledata.autompg import autompg as df
from bokeh.charts import Bar
from bokeh.charts.operations import blend

df=df.iloc[:10, :]

how to modify this:

p = Bar(df, label=‘name’,
values=blend(‘cyl’, ‘mpg’, ‘accel’, name=‘values’, labels_name=‘vars’),
title=‘mpg cyl accel for each car name’)
show(p)

``

Thanks

Fabio

···

On Monday, December 14, 2015 at 6:44:54 AM UTC-6, László Molnár wrote:

If you wonder why would I want to compare cyl mpg accel, just assume that they are comparable (in my dataframe those columns are comparable)!
It really bugs me that I can not figure out how to just plot several columns as bars. Is not bar chart for that just plot and compare several 1D data?

With the code above I always get this error:

raise ValueError(“expected an element of either %s, got %r” % (nice_join(self.type_params), value))

ValueError: expected an element of either Column(Float) or Column(String), got array([[ 8., 16., 12.]])

How should I make it Column?

Just as a sidenote, when bokeh does the sorting on the dataframe:

df = df.sort(columns=columns)

I get this warning:

/anaconda3/lib/python3.5/site-packages/bokeh/charts/_attributes.py:78: FutureWarning: sort(columns=…) is deprecated, use sort_values(by=…)

Hello Fabio,

Thanks for the answer. I installed the latest dev version:

Python 3.4.1 |Anaconda 2.1.0 (64-bit)| (default, Sep 24 2014, 18:32:42) [MSC v.1600 64 bit (AMD64)] on win32

import bokeh

bokeh.version

‘0.11.0dev4’

And tried your suggestion with the blend:

So it summed up the cyl, mpg and accel values for each car name. Instead of that, I would like to achieve that it shows those as separate bars and the labels would be cyl, mpg, accel while the car names would be in a legend box. Could you tell me how to achieve this?

Many thanks,

Lazlo

···

On Monday, 14 December 2015 15:47:24 UTC+1, Fabio Pliger wrote:

Hi,

Bar chart in 0.10 already implements the new API that is basically consolidated in 0.11. It was the first implementation of the this new interface and we added lots of improvements since then. For this reason I really encourage you to try to use the new 0.11 dev build we released last week an migrate to the final 0.11 when we release it in a few weeks.

That said, the new charts API provides you the blend operator to let you spell what you need (if I’m understanding your use case correctly). It may be the case that in the future we support the syntax you’ve tried to use in your example (specifying an iterable of columns on the values parameter) by inferring the data type but it has many implications and we need to be sure we are doing “it right” and not hiding different use cases.

Here’s a working version that should compare to your example:

from bokeh.sampledata.autompg import autompg as df
from bokeh.charts import Bar
from bokeh.charts.operations import blend

df=df.iloc[:10, :]

how to modify this:

p = Bar(df, label=‘name’,
values=blend(‘cyl’, ‘mpg’, ‘accel’, name=‘values’, labels_name=‘vars’),
title=‘mpg cyl accel for each car name’)
show(p)

``

Thanks

Fabio

On Monday, December 14, 2015 at 6:44:54 AM UTC-6, László Molnár wrote:

If you wonder why would I want to compare cyl mpg accel, just assume that they are comparable (in my dataframe those columns are comparable)!
It really bugs me that I can not figure out how to just plot several columns as bars. Is not bar chart for that just plot and compare several 1D data?

With the code above I always get this error:

raise ValueError(“expected an element of either %s, got %r” % (nice_join(self.type_params), value))

ValueError: expected an element of either Column(Float) or Column(String), got array([[ 8., 16., 12.]])

How should I make it Column?

Just as a sidenote, when bokeh does the sorting on the dataframe:

df = df.sort(columns=columns)

I get this warning:

/anaconda3/lib/python3.5/site-packages/bokeh/charts/_attributes.py:78: FutureWarning: sort(columns=…) is deprecated, use sort_values(by=…)

Hi Lazlo,

Sorry, I’m not sure I get what you want when you say “the labels would be cyl, mpg, accel”, but here’s a working example to color the bars by car name and have their related legend:

from bokeh.sampledata.autompg import autompg as df

from bokeh.charts import Bar

from bokeh.charts.operations import blend

df=df.iloc[:10, :]

how to modify this:

p = Bar(df, label=‘name’,

values=blend(‘cyl’, ‘mpg’, ‘accel’, name=‘values’, labels_name=‘vars’),

title=‘mpg cyl accel for each car name’, color=‘name’, legend=True)

show(p)

``

Let me know if it helps.

Thanks

Fabio

···

On Friday, December 18, 2015 at 4:22:33 AM UTC-6, László Molnár wrote:

Hello Fabio,

Thanks for the answer. I installed the latest dev version:

Python 3.4.1 |Anaconda 2.1.0 (64-bit)| (default, Sep 24 2014, 18:32:42) [MSC v.1600 64 bit (AMD64)] on win32

import bokeh

bokeh.version

‘0.11.0dev4’

And tried your suggestion with the blend:

So it summed up the cyl, mpg and accel values for each car name. Instead of that, I would like to achieve that it shows those as separate bars and the labels would be cyl, mpg, accel while the car names would be in a legend box. Could you tell me how to achieve this?

Many thanks,

Lazlo

On Monday, 14 December 2015 15:47:24 UTC+1, Fabio Pliger wrote:

Hi,

Bar chart in 0.10 already implements the new API that is basically consolidated in 0.11. It was the first implementation of the this new interface and we added lots of improvements since then. For this reason I really encourage you to try to use the new 0.11 dev build we released last week an migrate to the final 0.11 when we release it in a few weeks.

That said, the new charts API provides you the blend operator to let you spell what you need (if I’m understanding your use case correctly). It may be the case that in the future we support the syntax you’ve tried to use in your example (specifying an iterable of columns on the values parameter) by inferring the data type but it has many implications and we need to be sure we are doing “it right” and not hiding different use cases.

Here’s a working version that should compare to your example:

from bokeh.sampledata.autompg import autompg as df
from bokeh.charts import Bar
from bokeh.charts.operations import blend

df=df.iloc[:10, :]

how to modify this:

p = Bar(df, label=‘name’,
values=blend(‘cyl’, ‘mpg’, ‘accel’, name=‘values’, labels_name=‘vars’),
title=‘mpg cyl accel for each car name’)
show(p)

``

Thanks

Fabio

On Monday, December 14, 2015 at 6:44:54 AM UTC-6, László Molnár wrote:

If you wonder why would I want to compare cyl mpg accel, just assume that they are comparable (in my dataframe those columns are comparable)!
It really bugs me that I can not figure out how to just plot several columns as bars. Is not bar chart for that just plot and compare several 1D data?

With the code above I always get this error:

raise ValueError(“expected an element of either %s, got %r” % (nice_join(self.type_params), value))

ValueError: expected an element of either Column(Float) or Column(String), got array([[ 8., 16., 12.]])

How should I make it Column?

Just as a sidenote, when bokeh does the sorting on the dataframe:

df = df.sort(columns=columns)

I get this warning:

/anaconda3/lib/python3.5/site-packages/bokeh/charts/_attributes.py:78: FutureWarning: sort(columns=…) is deprecated, use sort_values(by=…)

Hello Fabio,

It is not quite what I would like to achieve. Instead of summing up the mpg, cyl and accel values for each car I would like them as separate bars, like shown on this image:

Do you know how to do that?

Thanks and happy new year,

Laszlo

···

On Friday, 18 December 2015 16:27:26 UTC+1, Fabio Pliger wrote:

Hi Lazlo,

Sorry, I’m not sure I get what you want when you say “the labels would be cyl, mpg, accel”, but here’s a working example to color the bars by car name and have their related legend:

from bokeh.sampledata.autompg import autompg as df

from bokeh.charts import Bar

from bokeh.charts.operations import blend

df=df.iloc[:10, :]

how to modify this:

p = Bar(df, label=‘name’,

values=blend(‘cyl’, ‘mpg’, ‘accel’, name=‘values’, labels_name=‘vars’),

title=‘mpg cyl accel for each car name’, color=‘name’, legend=True)

show(p)

``

Let me know if it helps.

Thanks

Fabio

On Friday, December 18, 2015 at 4:22:33 AM UTC-6, László Molnár wrote:

Hello Fabio,

Thanks for the answer. I installed the latest dev version:

Python 3.4.1 |Anaconda 2.1.0 (64-bit)| (default, Sep 24 2014, 18:32:42) [MSC v.1600 64 bit (AMD64)] on win32

import bokeh

bokeh.version

‘0.11.0dev4’

And tried your suggestion with the blend:

So it summed up the cyl, mpg and accel values for each car name. Instead of that, I would like to achieve that it shows those as separate bars and the labels would be cyl, mpg, accel while the car names would be in a legend box. Could you tell me how to achieve this?

Many thanks,

Lazlo

On Monday, 14 December 2015 15:47:24 UTC+1, Fabio Pliger wrote:

Hi,

Bar chart in 0.10 already implements the new API that is basically consolidated in 0.11. It was the first implementation of the this new interface and we added lots of improvements since then. For this reason I really encourage you to try to use the new 0.11 dev build we released last week an migrate to the final 0.11 when we release it in a few weeks.

That said, the new charts API provides you the blend operator to let you spell what you need (if I’m understanding your use case correctly). It may be the case that in the future we support the syntax you’ve tried to use in your example (specifying an iterable of columns on the values parameter) by inferring the data type but it has many implications and we need to be sure we are doing “it right” and not hiding different use cases.

Here’s a working version that should compare to your example:

from bokeh.sampledata.autompg import autompg as df
from bokeh.charts import Bar
from bokeh.charts.operations import blend

df=df.iloc[:10, :]

how to modify this:

p = Bar(df, label=‘name’,
values=blend(‘cyl’, ‘mpg’, ‘accel’, name=‘values’, labels_name=‘vars’),
title=‘mpg cyl accel for each car name’)
show(p)

``

Thanks

Fabio

On Monday, December 14, 2015 at 6:44:54 AM UTC-6, László Molnár wrote:

If you wonder why would I want to compare cyl mpg accel, just assume that they are comparable (in my dataframe those columns are comparable)!
It really bugs me that I can not figure out how to just plot several columns as bars. Is not bar chart for that just plot and compare several 1D data?

With the code above I always get this error:

raise ValueError(“expected an element of either %s, got %r” % (nice_join(self.type_params), value))

ValueError: expected an element of either Column(Float) or Column(String), got array([[ 8., 16., 12.]])

How should I make it Column?

Just as a sidenote, when bokeh does the sorting on the dataframe:

df = df.sort(columns=columns)

I get this warning:

/anaconda3/lib/python3.5/site-packages/bokeh/charts/_attributes.py:78: FutureWarning: sort(columns=…) is deprecated, use sort_values(by=…)

Hi Laszlo,

Here’s a snippet that should do what you are looking for:

from bokeh.sampledata.autompg import autompg as df

from bokeh.charts import Bar

from bokeh.charts.operations import blend

from bokeh.io import show, output_file

output_file(“ml_bar_cars_issue.html”)

df=df.iloc[:10, :]

how to modify this:

p = Bar(df, label=‘vars’, group=“name”,

    values=blend('cyl', 'mpg', 'accel', name='values', labels_name='vars'),

    title='mpg cyl accel for each car name', color='name', legend=True)

show(p)

``

In the specific case you want to blend the 3 columns in 1 categorical column that you can use for your label axis and then you must tell Bar to use this new labels_name column (in this case it’s called vars) . The Bar chart will already use the new name column (called "values here) for the bars computation. The last extra step here is to tell the Bar chart to use the “name” field for both the color and groupping.

Thanks

Fabio

···

On Monday, January 4, 2016 at 4:37:05 AM UTC-6, László Molnár wrote:

Hello Fabio,

It is not quite what I would like to achieve. Instead of summing up the mpg, cyl and accel values for each car I would like them as separate bars, like shown on this image:

Do you know how to do that?

Thanks and happy new year,

Laszlo

On Friday, 18 December 2015 16:27:26 UTC+1, Fabio Pliger wrote:

Hi Lazlo,

Sorry, I’m not sure I get what you want when you say “the labels would be cyl, mpg, accel”, but here’s a working example to color the bars by car name and have their related legend:

from bokeh.sampledata.autompg import autompg as df

from bokeh.charts import Bar

from bokeh.charts.operations import blend

df=df.iloc[:10, :]

how to modify this:

p = Bar(df, label=‘name’,

values=blend(‘cyl’, ‘mpg’, ‘accel’, name=‘values’, labels_name=‘vars’),

title=‘mpg cyl accel for each car name’, color=‘name’, legend=True)

show(p)

``

Let me know if it helps.

Thanks

Fabio

On Friday, December 18, 2015 at 4:22:33 AM UTC-6, László Molnár wrote:

Hello Fabio,

Thanks for the answer. I installed the latest dev version:

Python 3.4.1 |Anaconda 2.1.0 (64-bit)| (default, Sep 24 2014, 18:32:42) [MSC v.1600 64 bit (AMD64)] on win32

import bokeh

bokeh.version

‘0.11.0dev4’

And tried your suggestion with the blend:

So it summed up the cyl, mpg and accel values for each car name. Instead of that, I would like to achieve that it shows those as separate bars and the labels would be cyl, mpg, accel while the car names would be in a legend box. Could you tell me how to achieve this?

Many thanks,

Lazlo

On Monday, 14 December 2015 15:47:24 UTC+1, Fabio Pliger wrote:

Hi,

Bar chart in 0.10 already implements the new API that is basically consolidated in 0.11. It was the first implementation of the this new interface and we added lots of improvements since then. For this reason I really encourage you to try to use the new 0.11 dev build we released last week an migrate to the final 0.11 when we release it in a few weeks.

That said, the new charts API provides you the blend operator to let you spell what you need (if I’m understanding your use case correctly). It may be the case that in the future we support the syntax you’ve tried to use in your example (specifying an iterable of columns on the values parameter) by inferring the data type but it has many implications and we need to be sure we are doing “it right” and not hiding different use cases.

Here’s a working version that should compare to your example:

from bokeh.sampledata.autompg import autompg as df
from bokeh.charts import Bar
from bokeh.charts.operations import blend

df=df.iloc[:10, :]

how to modify this:

p = Bar(df, label=‘name’,
values=blend(‘cyl’, ‘mpg’, ‘accel’, name=‘values’, labels_name=‘vars’),
title=‘mpg cyl accel for each car name’)
show(p)

``

Thanks

Fabio

On Monday, December 14, 2015 at 6:44:54 AM UTC-6, László Molnár wrote:

If you wonder why would I want to compare cyl mpg accel, just assume that they are comparable (in my dataframe those columns are comparable)!
It really bugs me that I can not figure out how to just plot several columns as bars. Is not bar chart for that just plot and compare several 1D data?

With the code above I always get this error:

raise ValueError(“expected an element of either %s, got %r” % (nice_join(self.type_params), value))

ValueError: expected an element of either Column(Float) or Column(String), got array([[ 8., 16., 12.]])

How should I make it Column?

Just as a sidenote, when bokeh does the sorting on the dataframe:

df = df.sort(columns=columns)

I get this warning:

/anaconda3/lib/python3.5/site-packages/bokeh/charts/_attributes.py:78: FutureWarning: sort(columns=…) is deprecated, use sort_values(by=…)

Hi Fabio,

Great! I can start with the project to include such plotting to a plot server. I think I’ll come up with other questions later…

In fact I have a minor question already:

In the legend, the car names are in the same order as in the original dataframe, but on the plot itself they are in a different order:

I am not sure why the order is messed up, just have an idea that maybe when blend’s apply function is called it creates a copy and calls “stack_measures” then “_data” and somewhere in this process the order is changed.

Do you know how can I plot the bars to be in the same order as in the dataframe? Is there a way to sort the blend object?

Thanks,

Laszlo

···

On Wednesday, 13 January 2016 20:42:16 UTC+1, Fabio Pliger wrote:

Hi Laszlo,

Here’s a snippet that should do what you are looking for:

from bokeh.sampledata.autompg import autompg as df

from bokeh.charts import Bar

from bokeh.charts.operations import blend

from bokeh.io import show, output_file

output_file(“ml_bar_cars_issue.html”)

df=df.iloc[:10, :]

how to modify this:

p = Bar(df, label=‘vars’, group=“name”,

    values=blend('cyl', 'mpg', 'accel', name='values', labels_name='vars'),
    title='mpg cyl accel for each car name', color='name', legend=True)

show(p)

``

In the specific case you want to blend the 3 columns in 1 categorical column that you can use for your label axis and then you must tell Bar to use this new labels_name column (in this case it’s called vars) . The Bar chart will already use the new name column (called "values here) for the bars computation. The last extra step here is to tell the Bar chart to use the “name” field for both the color and groupping.

Thanks

Fabio

On Monday, January 4, 2016 at 4:37:05 AM UTC-6, László Molnár wrote:

Hello Fabio,

It is not quite what I would like to achieve. Instead of summing up the mpg, cyl and accel values for each car I would like them as separate bars, like shown on this image:

Do you know how to do that?

Thanks and happy new year,

Laszlo

On Friday, 18 December 2015 16:27:26 UTC+1, Fabio Pliger wrote:

Hi Lazlo,

Sorry, I’m not sure I get what you want when you say “the labels would be cyl, mpg, accel”, but here’s a working example to color the bars by car name and have their related legend:

from bokeh.sampledata.autompg import autompg as df

from bokeh.charts import Bar

from bokeh.charts.operations import blend

df=df.iloc[:10, :]

how to modify this:

p = Bar(df, label=‘name’,

values=blend(‘cyl’, ‘mpg’, ‘accel’, name=‘values’, labels_name=‘vars’),

title=‘mpg cyl accel for each car name’, color=‘name’, legend=True)

show(p)

``

Let me know if it helps.

Thanks

Fabio

On Friday, December 18, 2015 at 4:22:33 AM UTC-6, László Molnár wrote:

Hello Fabio,

Thanks for the answer. I installed the latest dev version:

Python 3.4.1 |Anaconda 2.1.0 (64-bit)| (default, Sep 24 2014, 18:32:42) [MSC v.1600 64 bit (AMD64)] on win32

import bokeh

bokeh.version

‘0.11.0dev4’

And tried your suggestion with the blend:

So it summed up the cyl, mpg and accel values for each car name. Instead of that, I would like to achieve that it shows those as separate bars and the labels would be cyl, mpg, accel while the car names would be in a legend box. Could you tell me how to achieve this?

Many thanks,

Lazlo

On Monday, 14 December 2015 15:47:24 UTC+1, Fabio Pliger wrote:

Hi,

Bar chart in 0.10 already implements the new API that is basically consolidated in 0.11. It was the first implementation of the this new interface and we added lots of improvements since then. For this reason I really encourage you to try to use the new 0.11 dev build we released last week an migrate to the final 0.11 when we release it in a few weeks.

That said, the new charts API provides you the blend operator to let you spell what you need (if I’m understanding your use case correctly). It may be the case that in the future we support the syntax you’ve tried to use in your example (specifying an iterable of columns on the values parameter) by inferring the data type but it has many implications and we need to be sure we are doing “it right” and not hiding different use cases.

Here’s a working version that should compare to your example:

from bokeh.sampledata.autompg import autompg as df
from bokeh.charts import Bar
from bokeh.charts.operations import blend

df=df.iloc[:10, :]

how to modify this:

p = Bar(df, label=‘name’,
values=blend(‘cyl’, ‘mpg’, ‘accel’, name=‘values’, labels_name=‘vars’),
title=‘mpg cyl accel for each car name’)
show(p)

``

Thanks

Fabio

On Monday, December 14, 2015 at 6:44:54 AM UTC-6, László Molnár wrote:

If you wonder why would I want to compare cyl mpg accel, just assume that they are comparable (in my dataframe those columns are comparable)!
It really bugs me that I can not figure out how to just plot several columns as bars. Is not bar chart for that just plot and compare several 1D data?

With the code above I always get this error:

raise ValueError(“expected an element of either %s, got %r” % (nice_join(self.type_params), value))

ValueError: expected an element of either Column(Float) or Column(String), got array([[ 8., 16., 12.]])

How should I make it Column?

Just as a sidenote, when bokeh does the sorting on the dataframe:

df = df.sort(columns=columns)

I get this warning:

/anaconda3/lib/python3.5/site-packages/bokeh/charts/_attributes.py:78: FutureWarning: sort(columns=…) is deprecated, use sort_values(by=…)

Hello,

so back again with the server implementation. I wanted to replicate the “data_tables_server.py” example just with a bar chart instead of Circle glyphs. Do I have to go back and create rectangle glyphs manually or can I use the high-level Bar class (with feeding ot with a ColumnDataSource or somehow)? See my script attached, but when I run it I get this message:

raise RuntimeError(“Models must be owned by only a single document, %r is already in a doc” % (self))

RuntimeError: Models must be owned by only a single document, <bokeh.models.renderers.GlyphRenderer object at 0x0000000007A8C0F0> is already in a doc

Is there a way to still add the Bar chart to the document?

Thanks in advance,

Laszlo

datatable_barchart_server.py (3.34 KB)

···

On Thursday, 14 January 2016 10:46:37 UTC+1, László Molnár wrote:

Hi Fabio,

Great! I can start with the project to include such plotting to a plot server. I think I’ll come up with other questions later…

In fact I have a minor question already:

In the legend, the car names are in the same order as in the original dataframe, but on the plot itself they are in a different order:

I am not sure why the order is messed up, just have an idea that maybe when blend’s apply function is called it creates a copy and calls “stack_measures” then “_data” and somewhere in this process the order is changed.

Do you know how can I plot the bars to be in the same order as in the dataframe? Is there a way to sort the blend object?

Thanks,

Laszlo

On Wednesday, 13 January 2016 20:42:16 UTC+1, Fabio Pliger wrote:

Hi Laszlo,

Here’s a snippet that should do what you are looking for:

from bokeh.sampledata.autompg import autompg as df

from bokeh.charts import Bar

from bokeh.charts.operations import blend

from bokeh.io import show, output_file

output_file(“ml_bar_cars_issue.html”)

df=df.iloc[:10, :]

how to modify this:

p = Bar(df, label=‘vars’, group=“name”,

    values=blend('cyl', 'mpg', 'accel', name='values', labels_name='vars'),
    title='mpg cyl accel for each car name', color='name', legend=True)

show(p)

``

In the specific case you want to blend the 3 columns in 1 categorical column that you can use for your label axis and then you must tell Bar to use this new labels_name column (in this case it’s called vars) . The Bar chart will already use the new name column (called "values here) for the bars computation. The last extra step here is to tell the Bar chart to use the “name” field for both the color and groupping.

Thanks

Fabio

On Monday, January 4, 2016 at 4:37:05 AM UTC-6, László Molnár wrote:

Hello Fabio,

It is not quite what I would like to achieve. Instead of summing up the mpg, cyl and accel values for each car I would like them as separate bars, like shown on this image:

Do you know how to do that?

Thanks and happy new year,

Laszlo

On Friday, 18 December 2015 16:27:26 UTC+1, Fabio Pliger wrote:

Hi Lazlo,

Sorry, I’m not sure I get what you want when you say “the labels would be cyl, mpg, accel”, but here’s a working example to color the bars by car name and have their related legend:

from bokeh.sampledata.autompg import autompg as df

from bokeh.charts import Bar

from bokeh.charts.operations import blend

df=df.iloc[:10, :]

how to modify this:

p = Bar(df, label=‘name’,

values=blend(‘cyl’, ‘mpg’, ‘accel’, name=‘values’, labels_name=‘vars’),

title=‘mpg cyl accel for each car name’, color=‘name’, legend=True)

show(p)

``

Let me know if it helps.

Thanks

Fabio

On Friday, December 18, 2015 at 4:22:33 AM UTC-6, László Molnár wrote:

Hello Fabio,

Thanks for the answer. I installed the latest dev version:

Python 3.4.1 |Anaconda 2.1.0 (64-bit)| (default, Sep 24 2014, 18:32:42) [MSC v.1600 64 bit (AMD64)] on win32

import bokeh

bokeh.version

‘0.11.0dev4’

And tried your suggestion with the blend:

So it summed up the cyl, mpg and accel values for each car name. Instead of that, I would like to achieve that it shows those as separate bars and the labels would be cyl, mpg, accel while the car names would be in a legend box. Could you tell me how to achieve this?

Many thanks,

Lazlo

On Monday, 14 December 2015 15:47:24 UTC+1, Fabio Pliger wrote:

Hi,

Bar chart in 0.10 already implements the new API that is basically consolidated in 0.11. It was the first implementation of the this new interface and we added lots of improvements since then. For this reason I really encourage you to try to use the new 0.11 dev build we released last week an migrate to the final 0.11 when we release it in a few weeks.

That said, the new charts API provides you the blend operator to let you spell what you need (if I’m understanding your use case correctly). It may be the case that in the future we support the syntax you’ve tried to use in your example (specifying an iterable of columns on the values parameter) by inferring the data type but it has many implications and we need to be sure we are doing “it right” and not hiding different use cases.

Here’s a working version that should compare to your example:

from bokeh.sampledata.autompg import autompg as df
from bokeh.charts import Bar
from bokeh.charts.operations import blend

df=df.iloc[:10, :]

how to modify this:

p = Bar(df, label=‘name’,
values=blend(‘cyl’, ‘mpg’, ‘accel’, name=‘values’, labels_name=‘vars’),
title=‘mpg cyl accel for each car name’)
show(p)

``

Thanks

Fabio

On Monday, December 14, 2015 at 6:44:54 AM UTC-6, László Molnár wrote:

If you wonder why would I want to compare cyl mpg accel, just assume that they are comparable (in my dataframe those columns are comparable)!
It really bugs me that I can not figure out how to just plot several columns as bars. Is not bar chart for that just plot and compare several 1D data?

With the code above I always get this error:

raise ValueError(“expected an element of either %s, got %r” % (nice_join(self.type_params), value))

ValueError: expected an element of either Column(Float) or Column(String), got array([[ 8., 16., 12.]])

How should I make it Column?

Just as a sidenote, when bokeh does the sorting on the dataframe:

df = df.sort(columns=columns)

I get this warning:

/anaconda3/lib/python3.5/site-packages/bokeh/charts/_attributes.py:78: FutureWarning: sort(columns=…) is deprecated, use sort_values(by=…)

For now you will need to recreate the entire plot, then replace the plot in the document when a callback fires that results in wanting to change the plot. I’m currently working on handling the updating of models so it doesn’t have to be recreated each time.

For the ordering issue, I found a bug with the ordering of the items being stacked/grouped: Fix issue with bar chart grouping/stacking order by rothnic · Pull Request #3778 · bokeh/bokeh · GitHub

···

On Thursday, January 28, 2016 at 9:43:05 AM UTC-6, László Molnár wrote:

Hello,

so back again with the server implementation. I wanted to replicate the “data_tables_server.py” example just with a bar chart instead of Circle glyphs. Do I have to go back and create rectangle glyphs manually or can I use the high-level Bar class (with feeding ot with a ColumnDataSource or somehow)? See my script attached, but when I run it I get this message:

raise RuntimeError(“Models must be owned by only a single document, %r is already in a doc” % (self))

RuntimeError: Models must be owned by only a single document, <bokeh.models.renderers.GlyphRenderer object at 0x0000000007A8C0F0> is already in a doc

Is there a way to still add the Bar chart to the document?

Thanks in advance,

Laszlo

On Thursday, 14 January 2016 10:46:37 UTC+1, László Molnár wrote:

Hi Fabio,

Great! I can start with the project to include such plotting to a plot server. I think I’ll come up with other questions later…

In fact I have a minor question already:

In the legend, the car names are in the same order as in the original dataframe, but on the plot itself they are in a different order:

I am not sure why the order is messed up, just have an idea that maybe when blend’s apply function is called it creates a copy and calls “stack_measures” then “_data” and somewhere in this process the order is changed.

Do you know how can I plot the bars to be in the same order as in the dataframe? Is there a way to sort the blend object?

Thanks,

Laszlo

On Wednesday, 13 January 2016 20:42:16 UTC+1, Fabio Pliger wrote:

Hi Laszlo,

Here’s a snippet that should do what you are looking for:

from bokeh.sampledata.autompg import autompg as df

from bokeh.charts import Bar

from bokeh.charts.operations import blend

from bokeh.io import show, output_file

output_file(“ml_bar_cars_issue.html”)

df=df.iloc[:10, :]

how to modify this:

p = Bar(df, label=‘vars’, group=“name”,

    values=blend('cyl', 'mpg', 'accel', name='values', labels_name='vars'),
    title='mpg cyl accel for each car name', color='name', legend=True)

show(p)

``

In the specific case you want to blend the 3 columns in 1 categorical column that you can use for your label axis and then you must tell Bar to use this new labels_name column (in this case it’s called vars) . The Bar chart will already use the new name column (called "values here) for the bars computation. The last extra step here is to tell the Bar chart to use the “name” field for both the color and groupping.

Thanks

Fabio

On Monday, January 4, 2016 at 4:37:05 AM UTC-6, László Molnár wrote:

Hello Fabio,

It is not quite what I would like to achieve. Instead of summing up the mpg, cyl and accel values for each car I would like them as separate bars, like shown on this image:

Do you know how to do that?

Thanks and happy new year,

Laszlo

On Friday, 18 December 2015 16:27:26 UTC+1, Fabio Pliger wrote:

Hi Lazlo,

Sorry, I’m not sure I get what you want when you say “the labels would be cyl, mpg, accel”, but here’s a working example to color the bars by car name and have their related legend:

from bokeh.sampledata.autompg import autompg as df

from bokeh.charts import Bar

from bokeh.charts.operations import blend

df=df.iloc[:10, :]

how to modify this:

p = Bar(df, label=‘name’,

values=blend(‘cyl’, ‘mpg’, ‘accel’, name=‘values’, labels_name=‘vars’),

title=‘mpg cyl accel for each car name’, color=‘name’, legend=True)

show(p)

``

Let me know if it helps.

Thanks

Fabio

On Friday, December 18, 2015 at 4:22:33 AM UTC-6, László Molnár wrote:

Hello Fabio,

Thanks for the answer. I installed the latest dev version:

Python 3.4.1 |Anaconda 2.1.0 (64-bit)| (default, Sep 24 2014, 18:32:42) [MSC v.1600 64 bit (AMD64)] on win32

import bokeh

bokeh.version

‘0.11.0dev4’

And tried your suggestion with the blend:

So it summed up the cyl, mpg and accel values for each car name. Instead of that, I would like to achieve that it shows those as separate bars and the labels would be cyl, mpg, accel while the car names would be in a legend box. Could you tell me how to achieve this?

Many thanks,

Lazlo

On Monday, 14 December 2015 15:47:24 UTC+1, Fabio Pliger wrote:

Hi,

Bar chart in 0.10 already implements the new API that is basically consolidated in 0.11. It was the first implementation of the this new interface and we added lots of improvements since then. For this reason I really encourage you to try to use the new 0.11 dev build we released last week an migrate to the final 0.11 when we release it in a few weeks.

That said, the new charts API provides you the blend operator to let you spell what you need (if I’m understanding your use case correctly). It may be the case that in the future we support the syntax you’ve tried to use in your example (specifying an iterable of columns on the values parameter) by inferring the data type but it has many implications and we need to be sure we are doing “it right” and not hiding different use cases.

Here’s a working version that should compare to your example:

from bokeh.sampledata.autompg import autompg as df
from bokeh.charts import Bar
from bokeh.charts.operations import blend

df=df.iloc[:10, :]

how to modify this:

p = Bar(df, label=‘name’,
values=blend(‘cyl’, ‘mpg’, ‘accel’, name=‘values’, labels_name=‘vars’),
title=‘mpg cyl accel for each car name’)
show(p)

``

Thanks

Fabio

On Monday, December 14, 2015 at 6:44:54 AM UTC-6, László Molnár wrote:

If you wonder why would I want to compare cyl mpg accel, just assume that they are comparable (in my dataframe those columns are comparable)!
It really bugs me that I can not figure out how to just plot several columns as bars. Is not bar chart for that just plot and compare several 1D data?

With the code above I always get this error:

raise ValueError(“expected an element of either %s, got %r” % (nice_join(self.type_params), value))

ValueError: expected an element of either Column(Float) or Column(String), got array([[ 8., 16., 12.]])

How should I make it Column?

Just as a sidenote, when bokeh does the sorting on the dataframe:

df = df.sort(columns=columns)

I get this warning:

/anaconda3/lib/python3.5/site-packages/bokeh/charts/_attributes.py:78: FutureWarning: sort(columns=…) is deprecated, use sort_values(by=…)

Hello Nick,

it is not totally clear for me what do you mean on recreating the plot? Do I have to create the bar chart with rectangle glyphs and then it will be updated just like the circles in the “data_tables_server.py” or can I still use the high-level Bar to create the bar chart (like I tried to do in the script I attached to my last message) and update it somehow? I guess you meant you are working on making the latter possible, right? In case yes, how much do I have to wait for it to be released? As it is not so urgent for me and then I might just wait till it lands in a next release.

Thanks,

Laszlo

···

On Thursday, 28 January 2016 17:04:05 UTC+1, Nick Roth wrote:

For now you will need to recreate the entire plot, then replace the plot in the document when a callback fires that results in wanting to change the plot. I’m currently working on handling the updating of models so it doesn’t have to be recreated each time.

For the ordering issue, I found a bug with the ordering of the items being stacked/grouped: https://github.com/bokeh/bokeh/pull/3778

On Thursday, January 28, 2016 at 9:43:05 AM UTC-6, László Molnár wrote:

Hello,

so back again with the server implementation. I wanted to replicate the “data_tables_server.py” example just with a bar chart instead of Circle glyphs. Do I have to go back and create rectangle glyphs manually or can I use the high-level Bar class (with feeding ot with a ColumnDataSource or somehow)? See my script attached, but when I run it I get this message:

raise RuntimeError(“Models must be owned by only a single document, %r is already in a doc” % (self))

RuntimeError: Models must be owned by only a single document, <bokeh.models.renderers.GlyphRenderer object at 0x0000000007A8C0F0> is already in a doc

Is there a way to still add the Bar chart to the document?

Thanks in advance,

Laszlo

On Thursday, 14 January 2016 10:46:37 UTC+1, László Molnár wrote:

Hi Fabio,

Great! I can start with the project to include such plotting to a plot server. I think I’ll come up with other questions later…

In fact I have a minor question already:

In the legend, the car names are in the same order as in the original dataframe, but on the plot itself they are in a different order:

I am not sure why the order is messed up, just have an idea that maybe when blend’s apply function is called it creates a copy and calls “stack_measures” then “_data” and somewhere in this process the order is changed.

Do you know how can I plot the bars to be in the same order as in the dataframe? Is there a way to sort the blend object?

Thanks,

Laszlo

On Wednesday, 13 January 2016 20:42:16 UTC+1, Fabio Pliger wrote:

Hi Laszlo,

Here’s a snippet that should do what you are looking for:

from bokeh.sampledata.autompg import autompg as df

from bokeh.charts import Bar

from bokeh.charts.operations import blend

from bokeh.io import show, output_file

output_file(“ml_bar_cars_issue.html”)

df=df.iloc[:10, :]

how to modify this:

p = Bar(df, label=‘vars’, group=“name”,

    values=blend('cyl', 'mpg', 'accel', name='values', labels_name='vars'),
    title='mpg cyl accel for each car name', color='name', legend=True)

show(p)

``

In the specific case you want to blend the 3 columns in 1 categorical column that you can use for your label axis and then you must tell Bar to use this new labels_name column (in this case it’s called vars) . The Bar chart will already use the new name column (called "values here) for the bars computation. The last extra step here is to tell the Bar chart to use the “name” field for both the color and groupping.

Thanks

Fabio

On Monday, January 4, 2016 at 4:37:05 AM UTC-6, László Molnár wrote:

Hello Fabio,

It is not quite what I would like to achieve. Instead of summing up the mpg, cyl and accel values for each car I would like them as separate bars, like shown on this image:

Do you know how to do that?

Thanks and happy new year,

Laszlo

On Friday, 18 December 2015 16:27:26 UTC+1, Fabio Pliger wrote:

Hi Lazlo,

Sorry, I’m not sure I get what you want when you say “the labels would be cyl, mpg, accel”, but here’s a working example to color the bars by car name and have their related legend:

from bokeh.sampledata.autompg import autompg as df

from bokeh.charts import Bar

from bokeh.charts.operations import blend

df=df.iloc[:10, :]

how to modify this:

p = Bar(df, label=‘name’,

values=blend(‘cyl’, ‘mpg’, ‘accel’, name=‘values’, labels_name=‘vars’),

title=‘mpg cyl accel for each car name’, color=‘name’, legend=True)

show(p)

``

Let me know if it helps.

Thanks

Fabio

On Friday, December 18, 2015 at 4:22:33 AM UTC-6, László Molnár wrote:

Hello Fabio,

Thanks for the answer. I installed the latest dev version:

Python 3.4.1 |Anaconda 2.1.0 (64-bit)| (default, Sep 24 2014, 18:32:42) [MSC v.1600 64 bit (AMD64)] on win32

import bokeh

bokeh.version

‘0.11.0dev4’

And tried your suggestion with the blend:

So it summed up the cyl, mpg and accel values for each car name. Instead of that, I would like to achieve that it shows those as separate bars and the labels would be cyl, mpg, accel while the car names would be in a legend box. Could you tell me how to achieve this?

Many thanks,

Lazlo

On Monday, 14 December 2015 15:47:24 UTC+1, Fabio Pliger wrote:

Hi,

Bar chart in 0.10 already implements the new API that is basically consolidated in 0.11. It was the first implementation of the this new interface and we added lots of improvements since then. For this reason I really encourage you to try to use the new 0.11 dev build we released last week an migrate to the final 0.11 when we release it in a few weeks.

That said, the new charts API provides you the blend operator to let you spell what you need (if I’m understanding your use case correctly). It may be the case that in the future we support the syntax you’ve tried to use in your example (specifying an iterable of columns on the values parameter) by inferring the data type but it has many implications and we need to be sure we are doing “it right” and not hiding different use cases.

Here’s a working version that should compare to your example:

from bokeh.sampledata.autompg import autompg as df
from bokeh.charts import Bar
from bokeh.charts.operations import blend

df=df.iloc[:10, :]

how to modify this:

p = Bar(df, label=‘name’,
values=blend(‘cyl’, ‘mpg’, ‘accel’, name=‘values’, labels_name=‘vars’),
title=‘mpg cyl accel for each car name’)
show(p)

``

Thanks

Fabio

On Monday, December 14, 2015 at 6:44:54 AM UTC-6, László Molnár wrote:

If you wonder why would I want to compare cyl mpg accel, just assume that they are comparable (in my dataframe those columns are comparable)!
It really bugs me that I can not figure out how to just plot several columns as bars. Is not bar chart for that just plot and compare several 1D data?

With the code above I always get this error:

raise ValueError(“expected an element of either %s, got %r” % (nice_join(self.type_params), value))

ValueError: expected an element of either Column(Float) or Column(String), got array([[ 8., 16., 12.]])

How should I make it Column?

Just as a sidenote, when bokeh does the sorting on the dataframe:

df = df.sort(columns=columns)

I get this warning:

/anaconda3/lib/python3.5/site-packages/bokeh/charts/_attributes.py:78: FutureWarning: sort(columns=…) is deprecated, use sort_values(by=…)

Hi,

RIght now you are passing a dataframe to your chart (self.df_mod) and when your update_data method gets called you replace this DataFrame with a new one.

With this approach your chart will not update since it is just a DataFrame consumer and does not keep any relation with the dataframe object it receives as an input. We are currently working on a new feature that will basically let you just update your Bar chart data to update the data inside the Bar chart. But this feature is not there yet.

What is possible to do with the charts interface at the moment is to fully recreate your chart object. This means that in this case you’d have recreate the chart and replace the old one with the new one in your app layout hierarchy. So your update_data method should look something like:

def update_data(self):

df = self.df

if self.name_filter:

df = df[df[‘name’] == self.name_filter]

self.source.data = ColumnDataSource.from_df(df)
self.df_mod = df.copy(deep=True)

new_p_bar = Bar(self.df_mod, label=‘vars’, group=‘name’,

values=blend(*bar_col_names, name=‘values’, labels_name=‘vars’),

title=‘mpg cyl accel for car name’, color=‘name’, legend=True)
self.layout.children[0][1] = new_p_bar

``

Please notice that for this to work you’d need to keep a reference to your layout thus you’d need to change your create_layout method last lines from:

layout = VBox(children=[plot_panel, data_table])

return layout

``

to something like:

self.layout = VBox(children=[plot_panel, data_table])

return self.layout

``

I haven’t tried to run this locally (so please don’t expect it to just work :slight_smile: but should give you an idea…

Thanks

Fabio

···

On Friday, January 29, 2016 at 2:32:15 AM UTC-6, László Molnár wrote:

Hello Nick,

it is not totally clear for me what do you mean on recreating the plot? Do I have to create the bar chart with rectangle glyphs and then it will be updated just like the circles in the “data_tables_server.py” or can I still use the high-level Bar to create the bar chart (like I tried to do in the script I attached to my last message) and update it somehow? I guess you meant you are working on making the latter possible, right? In case yes, how much do I have to wait for it to be released? As it is not so urgent for me and then I might just wait till it lands in a next release.

Thanks,

Laszlo

On Thursday, 28 January 2016 17:04:05 UTC+1, Nick Roth wrote:

For now you will need to recreate the entire plot, then replace the plot in the document when a callback fires that results in wanting to change the plot. I’m currently working on handling the updating of models so it doesn’t have to be recreated each time.

For the ordering issue, I found a bug with the ordering of the items being stacked/grouped: https://github.com/bokeh/bokeh/pull/3778

On Thursday, January 28, 2016 at 9:43:05 AM UTC-6, László Molnár wrote:

Hello,

so back again with the server implementation. I wanted to replicate the “data_tables_server.py” example just with a bar chart instead of Circle glyphs. Do I have to go back and create rectangle glyphs manually or can I use the high-level Bar class (with feeding ot with a ColumnDataSource or somehow)? See my script attached, but when I run it I get this message:

raise RuntimeError(“Models must be owned by only a single document, %r is already in a doc” % (self))

RuntimeError: Models must be owned by only a single document, <bokeh.models.renderers.GlyphRenderer object at 0x0000000007A8C0F0> is already in a doc

Is there a way to still add the Bar chart to the document?

Thanks in advance,

Laszlo

On Thursday, 14 January 2016 10:46:37 UTC+1, László Molnár wrote:

Hi Fabio,

Great! I can start with the project to include such plotting to a plot server. I think I’ll come up with other questions later…

In fact I have a minor question already:

In the legend, the car names are in the same order as in the original dataframe, but on the plot itself they are in a different order:

I am not sure why the order is messed up, just have an idea that maybe when blend’s apply function is called it creates a copy and calls “stack_measures” then “_data” and somewhere in this process the order is changed.

Do you know how can I plot the bars to be in the same order as in the dataframe? Is there a way to sort the blend object?

Thanks,

Laszlo

On Wednesday, 13 January 2016 20:42:16 UTC+1, Fabio Pliger wrote:

Hi Laszlo,

Here’s a snippet that should do what you are looking for:

from bokeh.sampledata.autompg import autompg as df

from bokeh.charts import Bar

from bokeh.charts.operations import blend

from bokeh.io import show, output_file

output_file(“ml_bar_cars_issue.html”)

df=df.iloc[:10, :]

how to modify this:

p = Bar(df, label=‘vars’, group=“name”,

    values=blend('cyl', 'mpg', 'accel', name='values', labels_name='vars'),
    title='mpg cyl accel for each car name', color='name', legend=True)

show(p)

``

In the specific case you want to blend the 3 columns in 1 categorical column that you can use for your label axis and then you must tell Bar to use this new labels_name column (in this case it’s called vars) . The Bar chart will already use the new name column (called "values here) for the bars computation. The last extra step here is to tell the Bar chart to use the “name” field for both the color and groupping.

Thanks

Fabio

On Monday, January 4, 2016 at 4:37:05 AM UTC-6, László Molnár wrote:

Hello Fabio,

It is not quite what I would like to achieve. Instead of summing up the mpg, cyl and accel values for each car I would like them as separate bars, like shown on this image:

Do you know how to do that?

Thanks and happy new year,

Laszlo

On Friday, 18 December 2015 16:27:26 UTC+1, Fabio Pliger wrote:

Hi Lazlo,

Sorry, I’m not sure I get what you want when you say “the labels would be cyl, mpg, accel”, but here’s a working example to color the bars by car name and have their related legend:

from bokeh.sampledata.autompg import autompg as df

from bokeh.charts import Bar

from bokeh.charts.operations import blend

df=df.iloc[:10, :]

how to modify this:

p = Bar(df, label=‘name’,

values=blend(‘cyl’, ‘mpg’, ‘accel’, name=‘values’, labels_name=‘vars’),

title=‘mpg cyl accel for each car name’, color=‘name’, legend=True)

show(p)

``

Let me know if it helps.

Thanks

Fabio

On Friday, December 18, 2015 at 4:22:33 AM UTC-6, László Molnár wrote:

Hello Fabio,

Thanks for the answer. I installed the latest dev version:

Python 3.4.1 |Anaconda 2.1.0 (64-bit)| (default, Sep 24 2014, 18:32:42) [MSC v.1600 64 bit (AMD64)] on win32

import bokeh

bokeh.version

‘0.11.0dev4’

And tried your suggestion with the blend:

So it summed up the cyl, mpg and accel values for each car name. Instead of that, I would like to achieve that it shows those as separate bars and the labels would be cyl, mpg, accel while the car names would be in a legend box. Could you tell me how to achieve this?

Many thanks,

Lazlo

On Monday, 14 December 2015 15:47:24 UTC+1, Fabio Pliger wrote:

Hi,

Bar chart in 0.10 already implements the new API that is basically consolidated in 0.11. It was the first implementation of the this new interface and we added lots of improvements since then. For this reason I really encourage you to try to use the new 0.11 dev build we released last week an migrate to the final 0.11 when we release it in a few weeks.

That said, the new charts API provides you the blend operator to let you spell what you need (if I’m understanding your use case correctly). It may be the case that in the future we support the syntax you’ve tried to use in your example (specifying an iterable of columns on the values parameter) by inferring the data type but it has many implications and we need to be sure we are doing “it right” and not hiding different use cases.

Here’s a working version that should compare to your example:

from bokeh.sampledata.autompg import autompg as df
from bokeh.charts import Bar
from bokeh.charts.operations import blend

df=df.iloc[:10, :]

how to modify this:

p = Bar(df, label=‘name’,
values=blend(‘cyl’, ‘mpg’, ‘accel’, name=‘values’, labels_name=‘vars’),
title=‘mpg cyl accel for each car name’)
show(p)

``

Thanks

Fabio

On Monday, December 14, 2015 at 6:44:54 AM UTC-6, László Molnár wrote:

If you wonder why would I want to compare cyl mpg accel, just assume that they are comparable (in my dataframe those columns are comparable)!
It really bugs me that I can not figure out how to just plot several columns as bars. Is not bar chart for that just plot and compare several 1D data?

With the code above I always get this error:

raise ValueError(“expected an element of either %s, got %r” % (nice_join(self.type_params), value))

ValueError: expected an element of either Column(Float) or Column(String), got array([[ 8., 16., 12.]])

How should I make it Column?

Just as a sidenote, when bokeh does the sorting on the dataframe:

df = df.sort(columns=columns)

I get this warning:

/anaconda3/lib/python3.5/site-packages/bokeh/charts/_attributes.py:78: FutureWarning: sort(columns=…) is deprecated, use sort_values(by=…)

Hello,

ahh ok I understand now, I have to recreate the bar chart but I can still use the simpler Bar class. Thanks Fabio for the suggestion too that I should update the bar chart with the update_data method too.

But my problem is still this error message I already wrote before:

raise RuntimeError(“Models must be owned by only a single document, %r is already in a doc” % (self))

RuntimeError: Models must be owned by only a single document, <bokeh.models.renderers.GlyphRenderer object at 0x0000000007A8C0F0> is already in a doc

``

How to embed a Bar chart to the layout?
I have also attached my updated script in case you wanna have a look.

Cheers,

Laszlo

datatable_barchart_server2.py (3.34 KB)

···

On Friday, 29 January 2016 16:03:29 UTC+1, Fabio Pliger wrote:

Hi,

RIght now you are passing a dataframe to your chart (self.df_mod) and when your update_data method gets called you replace this DataFrame with a new one.

With this approach your chart will not update since it is just a DataFrame consumer and does not keep any relation with the dataframe object it receives as an input. We are currently working on a new feature that will basically let you just update your Bar chart data to update the data inside the Bar chart. But this feature is not there yet.

What is possible to do with the charts interface at the moment is to fully recreate your chart object. This means that in this case you’d have recreate the chart and replace the old one with the new one in your app layout hierarchy. So your update_data method should look something like:

def update_data(self):

df = self.df

if self.name_filter:

df = df[df[‘name’] == self.name_filter]

self.source.data = ColumnDataSource.from_df(df)
self.df_mod = df.copy(deep=True)

new_p_bar = Bar(self.df_mod, label=‘vars’, group=‘name’,

values=blend(*bar_col_names, name=‘values’, labels_name=‘vars’),

title=‘mpg cyl accel for car name’, color=‘name’, legend=True)
self.layout.children[0][1] = new_p_bar

``

Please notice that for this to work you’d need to keep a reference to your layout thus you’d need to change your create_layout method last lines from:

layout = VBox(children=[plot_panel, data_table])

return layout

``

to something like:

self.layout = VBox(children=[plot_panel, data_table])

return self.layout

``

I haven’t tried to run this locally (so please don’t expect it to just work :slight_smile: but should give you an idea…

Thanks

Fabio

On Friday, January 29, 2016 at 2:32:15 AM UTC-6, László Molnár wrote:

Hello Nick,

it is not totally clear for me what do you mean on recreating the plot? Do I have to create the bar chart with rectangle glyphs and then it will be updated just like the circles in the “data_tables_server.py” or can I still use the high-level Bar to create the bar chart (like I tried to do in the script I attached to my last message) and update it somehow? I guess you meant you are working on making the latter possible, right? In case yes, how much do I have to wait for it to be released? As it is not so urgent for me and then I might just wait till it lands in a next release.

Thanks,

Laszlo

On Thursday, 28 January 2016 17:04:05 UTC+1, Nick Roth wrote:

For now you will need to recreate the entire plot, then replace the plot in the document when a callback fires that results in wanting to change the plot. I’m currently working on handling the updating of models so it doesn’t have to be recreated each time.

For the ordering issue, I found a bug with the ordering of the items being stacked/grouped: https://github.com/bokeh/bokeh/pull/3778

On Thursday, January 28, 2016 at 9:43:05 AM UTC-6, László Molnár wrote:

Hello,

so back again with the server implementation. I wanted to replicate the “data_tables_server.py” example just with a bar chart instead of Circle glyphs. Do I have to go back and create rectangle glyphs manually or can I use the high-level Bar class (with feeding ot with a ColumnDataSource or somehow)? See my script attached, but when I run it I get this message:

raise RuntimeError(“Models must be owned by only a single document, %r is already in a doc” % (self))

RuntimeError: Models must be owned by only a single document, <bokeh.models.renderers.GlyphRenderer object at 0x0000000007A8C0F0> is already in a doc

Is there a way to still add the Bar chart to the document?

Thanks in advance,

Laszlo

On Thursday, 14 January 2016 10:46:37 UTC+1, László Molnár wrote:

Hi Fabio,

Great! I can start with the project to include such plotting to a plot server. I think I’ll come up with other questions later…

In fact I have a minor question already:

In the legend, the car names are in the same order as in the original dataframe, but on the plot itself they are in a different order:

I am not sure why the order is messed up, just have an idea that maybe when blend’s apply function is called it creates a copy and calls “stack_measures” then “_data” and somewhere in this process the order is changed.

Do you know how can I plot the bars to be in the same order as in the dataframe? Is there a way to sort the blend object?

Thanks,

Laszlo

On Wednesday, 13 January 2016 20:42:16 UTC+1, Fabio Pliger wrote:

Hi Laszlo,

Here’s a snippet that should do what you are looking for:

from bokeh.sampledata.autompg import autompg as df

from bokeh.charts import Bar

from bokeh.charts.operations import blend

from bokeh.io import show, output_file

output_file(“ml_bar_cars_issue.html”)

df=df.iloc[:10, :]

how to modify this:

p = Bar(df, label=‘vars’, group=“name”,

    values=blend('cyl', 'mpg', 'accel', name='values', labels_name='vars'),
    title='mpg cyl accel for each car name', color='name', legend=True)

show(p)

``

In the specific case you want to blend the 3 columns in 1 categorical column that you can use for your label axis and then you must tell Bar to use this new labels_name column (in this case it’s called vars) . The Bar chart will already use the new name column (called "values here) for the bars computation. The last extra step here is to tell the Bar chart to use the “name” field for both the color and groupping.

Thanks

Fabio

On Monday, January 4, 2016 at 4:37:05 AM UTC-6, László Molnár wrote:

Hello Fabio,

It is not quite what I would like to achieve. Instead of summing up the mpg, cyl and accel values for each car I would like them as separate bars, like shown on this image:

Do you know how to do that?

Thanks and happy new year,

Laszlo

On Friday, 18 December 2015 16:27:26 UTC+1, Fabio Pliger wrote:

Hi Lazlo,

Sorry, I’m not sure I get what you want when you say “the labels would be cyl, mpg, accel”, but here’s a working example to color the bars by car name and have their related legend:

from bokeh.sampledata.autompg import autompg as df

from bokeh.charts import Bar

from bokeh.charts.operations import blend

df=df.iloc[:10, :]

how to modify this:

p = Bar(df, label=‘name’,

values=blend(‘cyl’, ‘mpg’, ‘accel’, name=‘values’, labels_name=‘vars’),

title=‘mpg cyl accel for each car name’, color=‘name’, legend=True)

show(p)

``

Let me know if it helps.

Thanks

Fabio

On Friday, December 18, 2015 at 4:22:33 AM UTC-6, László Molnár wrote:

Hello Fabio,

Thanks for the answer. I installed the latest dev version:

Python 3.4.1 |Anaconda 2.1.0 (64-bit)| (default, Sep 24 2014, 18:32:42) [MSC v.1600 64 bit (AMD64)] on win32

import bokeh

bokeh.version

‘0.11.0dev4’

And tried your suggestion with the blend:

So it summed up the cyl, mpg and accel values for each car name. Instead of that, I would like to achieve that it shows those as separate bars and the labels would be cyl, mpg, accel while the car names would be in a legend box. Could you tell me how to achieve this?

Many thanks,

Lazlo

On Monday, 14 December 2015 15:47:24 UTC+1, Fabio Pliger wrote:

Hi,

Bar chart in 0.10 already implements the new API that is basically consolidated in 0.11. It was the first implementation of the this new interface and we added lots of improvements since then. For this reason I really encourage you to try to use the new 0.11 dev build we released last week an migrate to the final 0.11 when we release it in a few weeks.

That said, the new charts API provides you the blend operator to let you spell what you need (if I’m understanding your use case correctly). It may be the case that in the future we support the syntax you’ve tried to use in your example (specifying an iterable of columns on the values parameter) by inferring the data type but it has many implications and we need to be sure we are doing “it right” and not hiding different use cases.

Here’s a working version that should compare to your example:

from bokeh.sampledata.autompg import autompg as df
from bokeh.charts import Bar
from bokeh.charts.operations import blend

df=df.iloc[:10, :]

how to modify this:

p = Bar(df, label=‘name’,
values=blend(‘cyl’, ‘mpg’, ‘accel’, name=‘values’, labels_name=‘vars’),
title=‘mpg cyl accel for each car name’)
show(p)

``

Thanks

Fabio

On Monday, December 14, 2015 at 6:44:54 AM UTC-6, László Molnár wrote:

If you wonder why would I want to compare cyl mpg accel, just assume that they are comparable (in my dataframe those columns are comparable)!
It really bugs me that I can not figure out how to just plot several columns as bars. Is not bar chart for that just plot and compare several 1D data?

With the code above I always get this error:

raise ValueError(“expected an element of either %s, got %r” % (nice_join(self.type_params), value))

ValueError: expected an element of either Column(Float) or Column(String), got array([[ 8., 16., 12.]])

How should I make it Column?

Just as a sidenote, when bokeh does the sorting on the dataframe:

df = df.sort(columns=columns)

I get this warning:

/anaconda3/lib/python3.5/site-packages/bokeh/charts/_attributes.py:78: FutureWarning: sort(columns=…) is deprecated, use sort_values(by=…)

Hello,

Firstly, thanks for all your efforts in developing Bokeh. A new release 0.12.7 has just arrived with many improvements.

I tried the example from this thread with this new version but does not work as expected.

My goal again is to recrete the data_table example but with a bar plot (not circle glyphs as in the example).

As I understand from the change log with the new bokeh version this should be possible, right?

So if you run the py file attached (preceded by bokeh serve). I see the following problems:

  1. bar plot does not appear, I just wanted to plot bar for the ‘mpg’ for each car ‘name’.

  2. When I select a car name with the selector, it does not filter the filtered rows but shows them with undefined in each cell. When I select All with the selector it only shows the previously selected car name. So there must be a problem with the on_name_change method.

Could you help me with the above issues? Any hints are welcome!

Thanks and best regards,

Lazlo

datatable_barchart_server_127.py (3.42 KB)

···

On Monday, 1 February 2016 14:05:28 UTC+1, László Molnár wrote:

Hello,

ahh ok I understand now, I have to recreate the bar chart but I can still use the simpler Bar class. Thanks Fabio for the suggestion too that I should update the bar chart with the update_data method too.

But my problem is still this error message I already wrote before:

raise RuntimeError(“Models must be owned by only a single document, %r is already in a doc” % (self))

RuntimeError: Models must be owned by only a single document, <bokeh.models.renderers.GlyphRenderer object at 0x0000000007A8C0F0> is already in a doc

``

How to embed a Bar chart to the layout?
I have also attached my updated script in case you wanna have a look.

Cheers,

Laszlo

On Friday, 29 January 2016 16:03:29 UTC+1, Fabio Pliger wrote:

Hi,

RIght now you are passing a dataframe to your chart (self.df_mod) and when your update_data method gets called you replace this DataFrame with a new one.

With this approach your chart will not update since it is just a DataFrame consumer and does not keep any relation with the dataframe object it receives as an input. We are currently working on a new feature that will basically let you just update your Bar chart data to update the data inside the Bar chart. But this feature is not there yet.

What is possible to do with the charts interface at the moment is to fully recreate your chart object. This means that in this case you’d have recreate the chart and replace the old one with the new one in your app layout hierarchy. So your update_data method should look something like:

def update_data(self):

df = self.df

if self.name_filter:

df = df[df[‘name’] == self.name_filter]

self.source.data = ColumnDataSource.from_df(df)
self.df_mod = df.copy(deep=True)

new_p_bar = Bar(self.df_mod, label=‘vars’, group=‘name’,

values=blend(*bar_col_names, name=‘values’, labels_name=‘vars’),

title=‘mpg cyl accel for car name’, color=‘name’, legend=True)
self.layout.children[0][1] = new_p_bar

``

Please notice that for this to work you’d need to keep a reference to your layout thus you’d need to change your create_layout method last lines from:

layout = VBox(children=[plot_panel, data_table])

return layout

``

to something like:

self.layout = VBox(children=[plot_panel, data_table])

return self.layout

``

I haven’t tried to run this locally (so please don’t expect it to just work :slight_smile: but should give you an idea…

Thanks

Fabio

On Friday, January 29, 2016 at 2:32:15 AM UTC-6, László Molnár wrote:

Hello Nick,

it is not totally clear for me what do you mean on recreating the plot? Do I have to create the bar chart with rectangle glyphs and then it will be updated just like the circles in the “data_tables_server.py” or can I still use the high-level Bar to create the bar chart (like I tried to do in the script I attached to my last message) and update it somehow? I guess you meant you are working on making the latter possible, right? In case yes, how much do I have to wait for it to be released? As it is not so urgent for me and then I might just wait till it lands in a next release.

Thanks,

Laszlo

On Thursday, 28 January 2016 17:04:05 UTC+1, Nick Roth wrote:

For now you will need to recreate the entire plot, then replace the plot in the document when a callback fires that results in wanting to change the plot. I’m currently working on handling the updating of models so it doesn’t have to be recreated each time.

For the ordering issue, I found a bug with the ordering of the items being stacked/grouped: https://github.com/bokeh/bokeh/pull/3778

On Thursday, January 28, 2016 at 9:43:05 AM UTC-6, László Molnár wrote:

Hello,

so back again with the server implementation. I wanted to replicate the “data_tables_server.py” example just with a bar chart instead of Circle glyphs. Do I have to go back and create rectangle glyphs manually or can I use the high-level Bar class (with feeding ot with a ColumnDataSource or somehow)? See my script attached, but when I run it I get this message:

raise RuntimeError(“Models must be owned by only a single document, %r is already in a doc” % (self))

RuntimeError: Models must be owned by only a single document, <bokeh.models.renderers.GlyphRenderer object at 0x0000000007A8C0F0> is already in a doc

Is there a way to still add the Bar chart to the document?

Thanks in advance,

Laszlo

On Thursday, 14 January 2016 10:46:37 UTC+1, László Molnár wrote:

Hi Fabio,

Great! I can start with the project to include such plotting to a plot server. I think I’ll come up with other questions later…

In fact I have a minor question already:

In the legend, the car names are in the same order as in the original dataframe, but on the plot itself they are in a different order:

I am not sure why the order is messed up, just have an idea that maybe when blend’s apply function is called it creates a copy and calls “stack_measures” then “_data” and somewhere in this process the order is changed.

Do you know how can I plot the bars to be in the same order as in the dataframe? Is there a way to sort the blend object?

Thanks,

Laszlo

On Wednesday, 13 January 2016 20:42:16 UTC+1, Fabio Pliger wrote:

Hi Laszlo,

Here’s a snippet that should do what you are looking for:

from bokeh.sampledata.autompg import autompg as df

from bokeh.charts import Bar

from bokeh.charts.operations import blend

from bokeh.io import show, output_file

output_file(“ml_bar_cars_issue.html”)

df=df.iloc[:10, :]

how to modify this:

p = Bar(df, label=‘vars’, group=“name”,

    values=blend('cyl', 'mpg', 'accel', name='values', labels_name='vars'),
    title='mpg cyl accel for each car name', color='name', legend=True)

show(p)

``

In the specific case you want to blend the 3 columns in 1 categorical column that you can use for your label axis and then you must tell Bar to use this new labels_name column (in this case it’s called vars) . The Bar chart will already use the new name column (called "values here) for the bars computation. The last extra step here is to tell the Bar chart to use the “name” field for both the color and groupping.

Thanks

Fabio

On Monday, January 4, 2016 at 4:37:05 AM UTC-6, László Molnár wrote:

Hello Fabio,

It is not quite what I would like to achieve. Instead of summing up the mpg, cyl and accel values for each car I would like them as separate bars, like shown on this image:

Do you know how to do that?

Thanks and happy new year,

Laszlo

On Friday, 18 December 2015 16:27:26 UTC+1, Fabio Pliger wrote:

Hi Lazlo,

Sorry, I’m not sure I get what you want when you say “the labels would be cyl, mpg, accel”, but here’s a working example to color the bars by car name and have their related legend:

from bokeh.sampledata.autompg import autompg as df

from bokeh.charts import Bar

from bokeh.charts.operations import blend

df=df.iloc[:10, :]

how to modify this:

p = Bar(df, label=‘name’,

values=blend(‘cyl’, ‘mpg’, ‘accel’, name=‘values’, labels_name=‘vars’),

title=‘mpg cyl accel for each car name’, color=‘name’, legend=True)

show(p)

``

Let me know if it helps.

Thanks

Fabio

On Friday, December 18, 2015 at 4:22:33 AM UTC-6, László Molnár wrote:

Hello Fabio,

Thanks for the answer. I installed the latest dev version:

Python 3.4.1 |Anaconda 2.1.0 (64-bit)| (default, Sep 24 2014, 18:32:42) [MSC v.1600 64 bit (AMD64)] on win32

import bokeh

bokeh.version

‘0.11.0dev4’

And tried your suggestion with the blend:

So it summed up the cyl, mpg and accel values for each car name. Instead of that, I would like to achieve that it shows those as separate bars and the labels would be cyl, mpg, accel while the car names would be in a legend box. Could you tell me how to achieve this?

Many thanks,

Lazlo

On Monday, 14 December 2015 15:47:24 UTC+1, Fabio Pliger wrote:

Hi,

Bar chart in 0.10 already implements the new API that is basically consolidated in 0.11. It was the first implementation of the this new interface and we added lots of improvements since then. For this reason I really encourage you to try to use the new 0.11 dev build we released last week an migrate to the final 0.11 when we release it in a few weeks.

That said, the new charts API provides you the blend operator to let you spell what you need (if I’m understanding your use case correctly). It may be the case that in the future we support the syntax you’ve tried to use in your example (specifying an iterable of columns on the values parameter) by inferring the data type but it has many implications and we need to be sure we are doing “it right” and not hiding different use cases.

Here’s a working version that should compare to your example:

from bokeh.sampledata.autompg import autompg as df
from bokeh.charts import Bar
from bokeh.charts.operations import blend

df=df.iloc[:10, :]

how to modify this:

p = Bar(df, label=‘name’,
values=blend(‘cyl’, ‘mpg’, ‘accel’, name=‘values’, labels_name=‘vars’),
title=‘mpg cyl accel for each car name’)
show(p)

``

Thanks

Fabio

On Monday, December 14, 2015 at 6:44:54 AM UTC-6, László Molnár wrote:

If you wonder why would I want to compare cyl mpg accel, just assume that they are comparable (in my dataframe those columns are comparable)!
It really bugs me that I can not figure out how to just plot several columns as bars. Is not bar chart for that just plot and compare several 1D data?

With the code above I always get this error:

raise ValueError(“expected an element of either %s, got %r” % (nice_join(self.type_params), value))

ValueError: expected an element of either Column(Float) or Column(String), got array([[ 8., 16., 12.]])

How should I make it Column?

Just as a sidenote, when bokeh does the sorting on the dataframe:

df = df.sort(columns=columns)

I get this warning:

/anaconda3/lib/python3.5/site-packages/bokeh/charts/_attributes.py:78: FutureWarning: sort(columns=…) is deprecated, use sort_values(by=…)