Building a stacked bar chart in 0.11. Need pointers on controlling label sort, color, hover, size

Hi Guys

Not sure if this is the appropriate forum to ask this type of question… But I thought I start here.

I produced a bar chart in Bokeh 0.11 w/ the following code:

from bokeh.palettes import Spectral10

from bokeh.charts import Bar, output_notebook, show

from bokeh.charts.attributes import AttrSpec, ColorAttr, MarkerAttr, CatAttr

pddf = sf2.to_dataframe()

#p = Bar(pddf, label=‘PdDistrict’, values=‘PdId’)

p = Bar(pddf, values = ‘PdId’,

agg=‘count’,

stack=‘Category’,

tools=“resize,hover,save”,

label=CatAttr(columns=[‘PdDistrict’], sort=True))

output_notebook()

show§

By and large, it looks like what I have in mind, but it’s far from release quality. But can’t figure out a few key issues. Hopefully you can give me some pointers.

Q1. How do you sort the plot? There are discussion threads #2924 and #2935, but it looks like nothing got resolved. The label=CatAttr(columns=[‘labels’], sort=True) approach only works w/ simple bar charts. It does not work for either stacked or grouped bar charts. Any suggestions?

Q2. How do you specify a different palette, eg. Spectral10 into ColorAttr for a chart? All a user wants is to have a color array longer than 6 elements, does he really have to go through all the steps just to get a deeper palette?

Q3. The size. How can I control the size of the plot as with figures? Right now, I enabled tools=“resize”, but I prefer the chart to come out a prespecified dimension without user intervention. It’s a simple operation, but I can’t find information anywhere.

Q4. Hover… I am sure this involves some JS programming… When I hover over a stack on a bar, I would like the tool tip to display the name of category, the count, and the percentage. How do I go about doing that?

Q5. How do display the total on top of each bar?

Thank you for your support. Your support will help build a complete example that will be released back to the community.

regards,

SH

Could you provide some sample data?

The examples are useful for scanning over and seeing what can be done and probably would cover most of your questions: https://github.com/bokeh/bokeh/tree/master/examples/charts/file

Q1. See: http://bokeh.pydata.org/en/latest/docs/gallery/stacked_bar_chart.html , which is a fairly complicated case. You may want to try pre-sorting the data then telling the chart not to sort for now as in the example. I think I have some changes that are pending that support each of these cases: https://notebooks.anaconda.org/nroth/deep-dive-attributes/iframe?version=#Altering-Attribute-Assignment-Order

Q2. You can pass a palette as a list of valid colors to any chart via palette= kwarg. This will change the palette of all attributes that can be colored. Or, you can pass in a colorattr with the palette defined separately for each attribute that can be colored.

Q3. Chart is a subclass of Plot, so you can pass any of those kwargs in. You can modify the chart you get back before showing it, or pass in width=X, height=X, or set the chart defaults if creating lots of charts. See examples.

Q4. All charts can have tooltips added by passing in a valid tooltips kwarg that references a column(s) in the resulting data source. See the previous stacked bar example.

Q5. For now, you will have to use the low level interface for this as bar doesn’t do this natively.

···

On Friday, January 8, 2016 at 12:06:16 PM UTC-6, SH Ho wrote:

Hi Guys

Not sure if this is the appropriate forum to ask this type of question… But I thought I start here.

I produced a bar chart in Bokeh 0.11 w/ the following code:

from bokeh.palettes import Spectral10

from bokeh.charts import Bar, output_notebook, show

from bokeh.charts.attributes import AttrSpec, ColorAttr, MarkerAttr, CatAttr

pddf = sf2.to_dataframe()

#p = Bar(pddf, label=‘PdDistrict’, values=‘PdId’)

p = Bar(pddf, values = ‘PdId’,

agg=‘count’,

stack=‘Category’,

tools=“resize,hover,save”,

label=CatAttr(columns=[‘PdDistrict’], sort=True))

output_notebook()

show§

By and large, it looks like what I have in mind, but it’s far from release quality. But can’t figure out a few key issues. Hopefully you can give me some pointers.

Q1. How do you sort the plot? There are discussion threads #2924 and #2935, but it looks like nothing got resolved. The label=CatAttr(columns=[‘labels’], sort=True) approach only works w/ simple bar charts. It does not work for either stacked or grouped bar charts. Any suggestions?

Q2. How do you specify a different palette, eg. Spectral10 into ColorAttr for a chart? All a user wants is to have a color array longer than 6 elements, does he really have to go through all the steps just to get a deeper palette?

Q3. The size. How can I control the size of the plot as with figures? Right now, I enabled tools=“resize”, but I prefer the chart to come out a prespecified dimension without user intervention. It’s a simple operation, but I can’t find information anywhere.

Q4. Hover… I am sure this involves some JS programming… When I hover over a stack on a bar, I would like the tool tip to display the name of category, the count, and the percentage. How do I go about doing that?

Q5. How do display the total on top of each bar?

Thank you for your support. Your support will help build a complete example that will be released back to the community.

regards,

SH

Actually you should pass plot_width and plot_height and not width and
height. (see https://github.com/bokeh/bokeh/issues/3578 for reference)

···

On Fri, Jan 8, 2016 at 12:37 PM, Nick Roth <[email protected]> wrote:

Could you provide some sample data?

The examples are useful for scanning over and seeing what can be done and
probably would cover most of your questions:
https://github.com/bokeh/bokeh/tree/master/examples/charts/file

Q1. See:
http://bokeh.pydata.org/en/latest/docs/gallery/stacked_bar_chart.html ,
which is a fairly complicated case. You may want to try pre-sorting the
data then telling the chart not to sort for now as in the example. I think
I have some changes that are pending that support each of these cases:
https://notebooks.anaconda.org/nroth/deep-dive-attributes/iframe?version=#Altering-Attribute-Assignment-Order

Q2. You can pass a palette as a list of valid colors to any chart via
palette= kwarg. This will change the palette of all attributes that can be
colored. Or, you can pass in a colorattr with the palette defined
separately for each attribute that can be colored.

Q3. Chart is a subclass of Plot, so you can pass any of those kwargs in.
You can modify the chart you get back before showing it, or pass in
width=X, height=X, or set the chart defaults if creating lots of charts.
See examples.

--
*Fabio Pliger*
*Senior Software Engineer, Bokeh*

Finally!!! Thanks guys, couldn’t have possibly done it without your help. You either get the syntax or you don’t. Simple as that. The new example bar is what I have been looking for all this time. I searched Bokeh doc and github left and right but I never saw that one.

A couple feedback/questions.

  1. if I set the name and labels_name to be the same in blend, it raises an error: AttributeError: ‘DataFrame’ object has no attribute ‘tolist’… It’s rather difficult trying to correlate that to the cause. It took me forever to figure it out.

  2. Is there an obvious way to display the value of a segment on a stacked bar when hover? Getting the coordinate and column name is easy, but if I want to find out the “count” of a segment… Since each segment obtains the input from different columns, not sure if the current hover syntax can support it. I guess a CallBack is needed?

Ok, this is the chart the kicked my ass… Now it’s finally tamed. Thanks again!

SH

FYI.

from bokeh.charts import Bar, output_notebook, show

from bokeh.charts.attributes import cat, color

from bokeh.charts.operations import blend

from bokeh.palettes import Spectral10

import pandas as pd

bar = Bar(df_topcrimes,

values=blend(‘OTHER OFFENSES’,‘VEHICLE THEFT’, ‘ASSAULT’, ‘NON-CRIMINAL’, ‘SUSPICIOUS OCC’, ‘LARCENY/THEFT’, ‘DRUG/NARCOTIC’, ‘MISSING PERSON’, ‘WARRANTS’, name=‘Incidents’, labels_name=‘Incident’),

label=cat(columns=‘PdDistrict’, sort=False),

stack=cat(columns=‘Incident’, sort=False),

color=color(columns=‘Incident’, palette=Spectral10, sort=False),

legend=‘top_right’,

title=“Crime Indident by PdDistrict”,

tooltips=[('Type: ‘, ‘@Incident’), (’#: ', ‘$y’)],

plot_width = 900, plot_height=600

)

output_notebook()

show(bar)

PdDistrict

TOTAL

OTHER OFFENSES

VEHICLE THEFT

ASSAULT

NON-CRIMINAL

SUSPICIOUS OCC

LARCENY/THEFT

DRUG/NARCOTIC

MISSING PERSON

WARRANTS

2

SOUTHERN

5739

904

161

528

639

213

2562

242

159

331

6

MISSION

3700

959

306

459

345

165

671

217

297

281

5

NORTHERN

3589

627

202

297

347

149

1499

174

101

193

8

CENTRAL

3513

615

146

277

431

131

1574

91

86

162

9

BAYVIEW

2725

765

245

359

203

171

481

111

141

249

7

INGLESIDE

2378

552

382

292

189

93

548

81

131

110

0

TENDERLOIN

2257

503

34

324

216

125

481

284

53

237

1

TARAVAL

1853

420

222

147

210

104

547

31

107

65

4

PARK

1693

283

150

118

193

60

576

63

141

109

3

RICHMOND

1546

335

118

81

250

89

527

51

50

45

···

On Friday, January 8, 2016 at 10:06:16 AM UTC-8, SH Ho wrote:

Hi Guys

Not sure if this is the appropriate forum to ask this type of question… But I thought I start here.

I produced a bar chart in Bokeh 0.11 w/ the following code:

from bokeh.palettes import Spectral10

from bokeh.charts import Bar, output_notebook, show

from bokeh.charts.attributes import AttrSpec, ColorAttr, MarkerAttr, CatAttr

pddf = sf2.to_dataframe()

#p = Bar(pddf, label=‘PdDistrict’, values=‘PdId’)

p = Bar(pddf, values = ‘PdId’,

agg=‘count’,

stack=‘Category’,

tools=“resize,hover,save”,

label=CatAttr(columns=[‘PdDistrict’], sort=True))

output_notebook()

show§

By and large, it looks like what I have in mind, but it’s far from release quality. But can’t figure out a few key issues. Hopefully you can give me some pointers.

Q1. How do you sort the plot? There are discussion threads #2924 and #2935, but it looks like nothing got resolved. The label=CatAttr(columns=[‘labels’], sort=True) approach only works w/ simple bar charts. It does not work for either stacked or grouped bar charts. Any suggestions?

Q2. How do you specify a different palette, eg. Spectral10 into ColorAttr for a chart? All a user wants is to have a color array longer than 6 elements, does he really have to go through all the steps just to get a deeper palette?

Q3. The size. How can I control the size of the plot as with figures? Right now, I enabled tools=“resize”, but I prefer the chart to come out a prespecified dimension without user intervention. It’s a simple operation, but I can’t find information anywhere.

Q4. Hover… I am sure this involves some JS programming… When I hover over a stack on a bar, I would like the tool tip to display the name of category, the count, and the percentage. How do I go about doing that?

Q5. How do display the total on top of each bar?

Thank you for your support. Your support will help build a complete example that will be released back to the community.

regards,

SH

Hi,

I’m very glad you got it working! Nice! Your feedback is very important to us since we are really really eager in keeping improving our documentation and resources better and more discoverable. It be very useful if you could provide your experience and/or suggestions about how we could have made it easier to find the information you needed.

···

On Fri, Jan 8, 2016 at 8:44 PM, SH Ho [email protected] wrote:

Finally!!! Thanks guys, couldn’t have possibly done it without your help. You either get the syntax or you don’t. Simple as that. The new example bar is what I have been looking for all this time. I searched Bokeh doc and github left and right but I never saw that one.

A couple feedback/questions.

  1. if I set the name and labels_name to be the same in blend, it raises an error: AttributeError: ‘DataFrame’ object has no attribute ‘tolist’… It’s rather difficult trying to correlate that to the cause. It took me forever to figure it out.

Right, you should not name thes to be the same. They really mean different things. You should think the blend function as a pandas melt function. You can see more info here: http://pandas.pydata.org/pandas-docs/stable/reshaping.html#reshaping-by-melt and here http://pandas.pydata.org/pandas-docs/stable/generated/pandas.melt.html

  1. Is there an obvious way to display the value of a segment on a stacked bar when hover? Getting the coordinate and column name is easy, but if I want to find out the “count” of a segment… Since each segment obtains the input from different columns, not sure if the current hover syntax can support it. I guess a CallBack is needed?

For now you can use the columns names you have used on your plot bar plot (so for instance you could use Incident, Incidents, PdDistrict, …). I suggest you to try it and add issue asking for this feature (adding ways to spell other types of hover features).

Ok, this is the chart the kicked my ass… Now it’s finally tamed. Thanks again!

Thanks for the feedback again. And yes, the new charts semantics has changed a bit from the previous old charts and may require some time to be understood but definitely offer way more flexibility and functionality once you understand how to use it.

Best

Fabio

SH

FYI.

from bokeh.charts import Bar, output_notebook, show

from bokeh.charts.attributes import cat, color

from bokeh.charts.operations import blend

from bokeh.palettes import Spectral10

import pandas as pd

bar = Bar(df_topcrimes,

values=blend(‘OTHER OFFENSES’,‘VEHICLE THEFT’, ‘ASSAULT’, ‘NON-CRIMINAL’, ‘SUSPICIOUS OCC’, ‘LARCENY/THEFT’, ‘DRUG/NARCOTIC’, ‘MISSING PERSON’, ‘WARRANTS’, name=‘Incidents’, labels_name=‘Incident’),

label=cat(columns=‘PdDistrict’, sort=False),

stack=cat(columns=‘Incident’, sort=False),

color=color(columns=‘Incident’, palette=Spectral10, sort=False),

legend=‘top_right’,

title=“Crime Indident by PdDistrict”,

tooltips=[('Type: ‘, ‘@Incident’), (’#: ', ‘$y’)],

plot_width = 900, plot_height=600

)

output_notebook()

show(bar)

PdDistrict

TOTAL

OTHER OFFENSES

VEHICLE THEFT

ASSAULT

NON-CRIMINAL

SUSPICIOUS OCC

LARCENY/THEFT

DRUG/NARCOTIC

MISSING PERSON

WARRANTS

2

SOUTHERN

5739

904

161

528

639

213

2562

242

159

331

6

MISSION

3700

959

306

459

345

165

671

217

297

281

5

NORTHERN

3589

627

202

297

347

149

1499

174

101

193

8

CENTRAL

3513

615

146

277

431

131

1574

91

86

162

9

BAYVIEW

2725

765

245

359

203

171

481

111

141

249

7

INGLESIDE

2378

552

382

292

189

93

548

81

131

110

0

TENDERLOIN

2257

503

34

324

216

125

481

284

53

237

1

TARAVAL

1853

420

222

147

210

104

547

31

107

65

4

PARK

1693

283

150

118

193

60

576

63

141

109

3

RICHMOND

1546

335

118

81

250

89

527

51

50

45

On Friday, January 8, 2016 at 10:06:16 AM UTC-8, SH Ho wrote:

Hi Guys

Not sure if this is the appropriate forum to ask this type of question… But I thought I start here.

I produced a bar chart in Bokeh 0.11 w/ the following code:

from bokeh.palettes import Spectral10

from bokeh.charts import Bar, output_notebook, show

from bokeh.charts.attributes import AttrSpec, ColorAttr, MarkerAttr, CatAttr

pddf = sf2.to_dataframe()

#p = Bar(pddf, label=‘PdDistrict’, values=‘PdId’)

p = Bar(pddf, values = ‘PdId’,

agg=‘count’,

stack=‘Category’,

tools=“resize,hover,save”,

label=CatAttr(columns=[‘PdDistrict’], sort=True))

output_notebook()

show§

By and large, it looks like what I have in mind, but it’s far from release quality. But can’t figure out a few key issues. Hopefully you can give me some pointers.

Q1. How do you sort the plot? There are discussion threads #2924 and #2935, but it looks like nothing got resolved. The label=CatAttr(columns=[‘labels’], sort=True) approach only works w/ simple bar charts. It does not work for either stacked or grouped bar charts. Any suggestions?

Q2. How do you specify a different palette, eg. Spectral10 into ColorAttr for a chart? All a user wants is to have a color array longer than 6 elements, does he really have to go through all the steps just to get a deeper palette?

Q3. The size. How can I control the size of the plot as with figures? Right now, I enabled tools=“resize”, but I prefer the chart to come out a prespecified dimension without user intervention. It’s a simple operation, but I can’t find information anywhere.

Q4. Hover… I am sure this involves some JS programming… When I hover over a stack on a bar, I would like the tool tip to display the name of category, the count, and the percentage. How do I go about doing that?

Q5. How do display the total on top of each bar?

Thank you for your support. Your support will help build a complete example that will be released back to the community.

regards,

SH

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/0ba01f41-f5a8-4460-9a05-08196b520c47%40continuum.io.

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

Fabio Pliger

Senior Software Engineer, Bokeh

Hi Fabio

It is always difficult for newcomers to find out which examples to even use. There are at least three different bar chart examples, but it’s the last one you sent me the one that really matters. And that’s the one that the community should reference going forward… How exactly, not sure. Hopefully once it warms up, it’ll get propped higher on google.

For me, learning to use a plotting package is all about utilizing reference examples. Give the users super rich reference, and let them see and replicate the possibilities - it’s much easier to subtract than to add. So with your support, I like to create plots that are as feature rich as possible and let the community leverage that for their own work.

Thanks and stay tuned for more!

SH

···

On Fri, Jan 8, 2016 at 8:44 PM, SH Ho [email protected] wrote:

Finally!!! Thanks guys, couldn’t have possibly done it without your help. You either get the syntax or you don’t. Simple as that. The new example bar is what I have been looking for all this time. I searched Bokeh doc and github left and right but I never saw that one.

A couple feedback/questions.

  1. if I set the name and labels_name to be the same in blend, it raises an error: AttributeError: ‘DataFrame’ object has no attribute ‘tolist’… It’s rather difficult trying to correlate that to the cause. It took me forever to figure it out.

Right, you should not name thes to be the same. They really mean different things. You should think the blend function as a pandas melt function. You can see more info here: http://pandas.pydata.org/pandas-docs/stable/reshaping.html#reshaping-by-melt and here http://pandas.pydata.org/pandas-docs/stable/generated/pandas.melt.html

  1. Is there an obvious way to display the value of a segment on a stacked bar when hover? Getting the coordinate and column name is easy, but if I want to find out the “count” of a segment… Since each segment obtains the input from different columns, not sure if the current hover syntax can support it. I guess a CallBack is needed?

For now you can use the columns names you have used on your plot bar plot (so for instance you could use Incident, Incidents, PdDistrict, …). I suggest you to try it and add issue asking for this feature (adding ways to spell other types of hover features).

Ok, this is the chart the kicked my ass… Now it’s finally tamed. Thanks again!

Thanks for the feedback again. And yes, the new charts semantics has changed a bit from the previous old charts and may require some time to be understood but definitely offer way more flexibility and functionality once you understand how to use it.

Best

Fabio

SH

FYI.

from bokeh.charts import Bar, output_notebook, show

from bokeh.charts.attributes import cat, color

from bokeh.charts.operations import blend

from bokeh.palettes import Spectral10

import pandas as pd

bar = Bar(df_topcrimes,

values=blend(‘OTHER OFFENSES’,‘VEHICLE THEFT’, ‘ASSAULT’, ‘NON-CRIMINAL’, ‘SUSPICIOUS OCC’, ‘LARCENY/THEFT’, ‘DRUG/NARCOTIC’, ‘MISSING PERSON’, ‘WARRANTS’, name=‘Incidents’, labels_name=‘Incident’),

label=cat(columns=‘PdDistrict’, sort=False),

stack=cat(columns=‘Incident’, sort=False),

color=color(columns=‘Incident’, palette=Spectral10, sort=False),

legend=‘top_right’,

title=“Crime Indident by PdDistrict”,

tooltips=[('Type: ‘, ‘@Incident’), (’#: ', ‘$y’)],

plot_width = 900, plot_height=600

)

output_notebook()

show(bar)

PdDistrict

TOTAL

OTHER OFFENSES

VEHICLE THEFT

ASSAULT

NON-CRIMINAL

SUSPICIOUS OCC

LARCENY/THEFT

DRUG/NARCOTIC

MISSING PERSON

WARRANTS

2

SOUTHERN

5739

904

161

528

639

213

2562

242

159

331

6

MISSION

3700

959

306

459

345

165

671

217

297

281

5

NORTHERN

3589

627

202

297

347

149

1499

174

101

193

8

CENTRAL

3513

615

146

277

431

131

1574

91

86

162

9

BAYVIEW

2725

765

245

359

203

171

481

111

141

249

7

INGLESIDE

2378

552

382

292

189

93

548

81

131

110

0

TENDERLOIN

2257

503

34

324

216

125

481

284

53

237

1

TARAVAL

1853

420

222

147

210

104

547

31

107

65

4

PARK

1693

283

150

118

193

60

576

63

141

109

3

RICHMOND

1546

335

118

81

250

89

527

51

50

45

On Friday, January 8, 2016 at 10:06:16 AM UTC-8, SH Ho wrote:

Hi Guys

Not sure if this is the appropriate forum to ask this type of question… But I thought I start here.

I produced a bar chart in Bokeh 0.11 w/ the following code:

from bokeh.palettes import Spectral10

from bokeh.charts import Bar, output_notebook, show

from bokeh.charts.attributes import AttrSpec, ColorAttr, MarkerAttr, CatAttr

pddf = sf2.to_dataframe()

#p = Bar(pddf, label=‘PdDistrict’, values=‘PdId’)

p = Bar(pddf, values = ‘PdId’,

agg=‘count’,

stack=‘Category’,

tools=“resize,hover,save”,

label=CatAttr(columns=[‘PdDistrict’], sort=True))

output_notebook()

show§

By and large, it looks like what I have in mind, but it’s far from release quality. But can’t figure out a few key issues. Hopefully you can give me some pointers.

Q1. How do you sort the plot? There are discussion threads #2924 and #2935, but it looks like nothing got resolved. The label=CatAttr(columns=[‘labels’], sort=True) approach only works w/ simple bar charts. It does not work for either stacked or grouped bar charts. Any suggestions?

Q2. How do you specify a different palette, eg. Spectral10 into ColorAttr for a chart? All a user wants is to have a color array longer than 6 elements, does he really have to go through all the steps just to get a deeper palette?

Q3. The size. How can I control the size of the plot as with figures? Right now, I enabled tools=“resize”, but I prefer the chart to come out a prespecified dimension without user intervention. It’s a simple operation, but I can’t find information anywhere.

Q4. Hover… I am sure this involves some JS programming… When I hover over a stack on a bar, I would like the tool tip to display the name of category, the count, and the percentage. How do I go about doing that?

Q5. How do display the total on top of each bar?

Thank you for your support. Your support will help build a complete example that will be released back to the community.

regards,

SH


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/0ba01f41-f5a8-4460-9a05-08196b520c47%40continuum.io.

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

Fabio Pliger

Senior Software Engineer, Bokeh

I agree that having a rich set of reference examples is extremely helpful. One thing I might add based on my own experience is that sometimes the contents and format of the data used in the example are not clear, which makes it very difficult to understand the example. It would be helpful to at least do something like df.head() in the example to give the reader an idea about what the data looks like (at least for the situation in which dataframes are used).

Greg

···

On Friday, January 8, 2016 at 11:27:32 PM UTC-7, SH Ho wrote:

Hi Fabio

It is always difficult for newcomers to find out which examples to even use. There are at least three different bar chart examples, but it’s the last one you sent me the one that really matters. And that’s the one that the community should reference going forward… How exactly, not sure. Hopefully once it warms up, it’ll get propped higher on google.

For me, learning to use a plotting package is all about utilizing reference examples. Give the users super rich reference, and let them see and replicate the possibilities - it’s much easier to subtract than to add. So with your support, I like to create plots that are as feature rich as possible and let the community leverage that for their own work.

Thanks and stay tuned for more!

SH

On Jan 8, 2016, at 7:40 PM, Fabio Pliger [email protected] wrote:

Hi,

I’m very glad you got it working! Nice! Your feedback is very important to us since we are really really eager in keeping improving our documentation and resources better and more discoverable. It be very useful if you could provide your experience and/or suggestions about how we could have made it easier to find the information you needed.

Finally!!! Thanks guys, couldn’t have possibly done it without your help. You either get the syntax or you don’t. Simple as that. The new example bar is what I have been looking for all this time. I searched Bokeh doc and github left and right but I never saw that one.

A couple feedback/questions.

  1. if I set the name and labels_name to be the same in blend, it raises an error: AttributeError: ‘DataFrame’ object has no attribute ‘tolist’… It’s rather difficult trying to correlate that to the cause. It took me forever to figure it out.

Right, you should not name thes to be the same. They really mean different things. You should think the blend function as a pandas melt function. You can see more info here: http://pandas.pydata.org/pandas-docs/stable/reshaping.html#reshaping-by-melt and here http://pandas.pydata.org/pandas-docs/stable/generated/pandas.melt.html

  1. Is there an obvious way to display the value of a segment on a stacked bar when hover? Getting the coordinate and column name is easy, but if I want to find out the “count” of a segment… Since each segment obtains the input from different columns, not sure if the current hover syntax can support it. I guess a CallBack is needed?

For now you can use the columns names you have used on your plot bar plot (so for instance you could use Incident, Incidents, PdDistrict, …). I suggest you to try it and add issue asking for this feature (adding ways to spell other types of hover features).

Ok, this is the chart the kicked my ass… Now it’s finally tamed. Thanks again!

Thanks for the feedback again. And yes, the new charts semantics has changed a bit from the previous old charts and may require some time to be understood but definitely offer way more flexibility and functionality once you understand how to use it.

Best

Fabio

SH

FYI.

from bokeh.charts import Bar, output_notebook, show

from bokeh.charts.attributes import cat, color

from bokeh.charts.operations import blend

from bokeh.palettes import Spectral10

import pandas as pd

bar = Bar(df_topcrimes,

values=blend(‘OTHER OFFENSES’,‘VEHICLE THEFT’, ‘ASSAULT’, ‘NON-CRIMINAL’, ‘SUSPICIOUS OCC’, ‘LARCENY/THEFT’, ‘DRUG/NARCOTIC’, ‘MISSING PERSON’, ‘WARRANTS’, name=‘Incidents’, labels_name=‘Incident’),

label=cat(columns=‘PdDistrict’, sort=False),

stack=cat(columns=‘Incident’, sort=False),

color=color(columns=‘Incident’, palette=Spectral10, sort=False),

legend=‘top_right’,

title=“Crime Indident by PdDistrict”,

tooltips=[('Type: ‘, ‘@Incident’), (’#: ', ‘$y’)],

plot_width = 900, plot_height=600

)

output_notebook()

show(bar)

PdDistrict

TOTAL

OTHER OFFENSES

VEHICLE THEFT

ASSAULT

NON-CRIMINAL

SUSPICIOUS OCC

LARCENY/THEFT

DRUG/NARCOTIC

MISSING PERSON

WARRANTS

2

SOUTHERN

5739

904

161

528

639

213

2562

242

159

331

6

MISSION

3700

959

306

459

345

165

671

217

297

281

5

NORTHERN

3589

627

202

297

347

149

1499

174

101

193

8

CENTRAL

3513

615

146

277

431

131

1574

91

86

162

9

BAYVIEW

2725

765

245

359

203

171

481

111

141

249

7

INGLESIDE

2378

552

382

292

189

93

548

81

131

110

0

TENDERLOIN

2257

503

34

324

216

125

481

284

53

237

1

TARAVAL

1853

420

222

147

210

104

547

31

107

65

4

PARK

1693

283

150

118

193

60

576

63

141

109

3

RICHMOND

1546

335

118

81

250

89

527

51

50

45

On Friday, January 8, 2016 at 10:06:16 AM UTC-8, SH Ho wrote:

Hi Guys

Not sure if this is the appropriate forum to ask this type of question… But I thought I start here.

I produced a bar chart in Bokeh 0.11 w/ the following code:

from bokeh.palettes import Spectral10

from bokeh.charts import Bar, output_notebook, show

from bokeh.charts.attributes import AttrSpec, ColorAttr, MarkerAttr, CatAttr

pddf = sf2.to_dataframe()

#p = Bar(pddf, label=‘PdDistrict’, values=‘PdId’)

p = Bar(pddf, values = ‘PdId’,

agg=‘count’,

stack=‘Category’,

tools=“resize,hover,save”,

label=CatAttr(columns=[‘PdDistrict’], sort=True))

output_notebook()

show§

By and large, it looks like what I have in mind, but it’s far from release quality. But can’t figure out a few key issues. Hopefully you can give me some pointers.

Q1. How do you sort the plot? There are discussion threads #2924 and #2935, but it looks like nothing got resolved. The label=CatAttr(columns=[‘labels’], sort=True) approach only works w/ simple bar charts. It does not work for either stacked or grouped bar charts. Any suggestions?

Q2. How do you specify a different palette, eg. Spectral10 into ColorAttr for a chart? All a user wants is to have a color array longer than 6 elements, does he really have to go through all the steps just to get a deeper palette?

Q3. The size. How can I control the size of the plot as with figures? Right now, I enabled tools=“resize”, but I prefer the chart to come out a prespecified dimension without user intervention. It’s a simple operation, but I can’t find information anywhere.

Q4. Hover… I am sure this involves some JS programming… When I hover over a stack on a bar, I would like the tool tip to display the name of category, the count, and the percentage. How do I go about doing that?

Q5. How do display the total on top of each bar?

Thank you for your support. Your support will help build a complete example that will be released back to the community.

regards,

SH


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/0ba01f41-f5a8-4460-9a05-08196b520c47%40continuum.io.

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

On Fri, Jan 8, 2016 at 8:44 PM, SH Ho [email protected] wrote:


Fabio Pliger

Senior Software Engineer, Bokeh


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/CAPVmnqApCm9TrYevi3LoUk17%3DCoxRc8_DUo_W_Xe_DHdx%3DcyDA%40mail.gmail.com.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.

Thank SH and Greg for your feedback. It’s really valuable. I agree that specially charts needs more and better detailed documentation. We have already improved a lot but it’s definitely not enough and we are working on it. The main problem is that charts really do a lot in figuring out and transforming the different types and shapes of input users may ingest.

There are ongoing efforts to do this and one idea is also to have dedicated notebooks to cover in details aspects of the API (like operators, grouping arguments, specs, etc…) and have the linked to the documentation related sections.

Also, I’d also encourage users in general to send more suggestions here or through issues and/or contribution PRs. All are very welcome! :slight_smile:

Thanks!!!

···

On Sat, Jan 9, 2016 at 12:36 AM, Greg Nordin [email protected] wrote:

I agree that having a rich set of reference examples is extremely helpful. One thing I might add based on my own experience is that sometimes the contents and format of the data used in the example are not clear, which makes it very difficult to understand the example. It would be helpful to at least do something like df.head() in the example to give the reader an idea about what the data looks like (at least for the situation in which dataframes are used).

Greg

On Friday, January 8, 2016 at 11:27:32 PM UTC-7, SH Ho wrote:

Hi Fabio

It is always difficult for newcomers to find out which examples to even use. There are at least three different bar chart examples, but it’s the last one you sent me the one that really matters. And that’s the one that the community should reference going forward… How exactly, not sure. Hopefully once it warms up, it’ll get propped higher on google.

For me, learning to use a plotting package is all about utilizing reference examples. Give the users super rich reference, and let them see and replicate the possibilities - it’s much easier to subtract than to add. So with your support, I like to create plots that are as feature rich as possible and let the community leverage that for their own work.

Thanks and stay tuned for more!

SH

On Jan 8, 2016, at 7:40 PM, Fabio Pliger [email protected] wrote:

Hi,

I’m very glad you got it working! Nice! Your feedback is very important to us since we are really really eager in keeping improving our documentation and resources better and more discoverable. It be very useful if you could provide your experience and/or suggestions about how we could have made it easier to find the information you needed.

On Fri, Jan 8, 2016 at 8:44 PM, SH Ho [email protected] wrote:

Finally!!! Thanks guys, couldn’t have possibly done it without your help. You either get the syntax or you don’t. Simple as that. The new example bar is what I have been looking for all this time. I searched Bokeh doc and github left and right but I never saw that one.

A couple feedback/questions.

  1. if I set the name and labels_name to be the same in blend, it raises an error: AttributeError: ‘DataFrame’ object has no attribute ‘tolist’… It’s rather difficult trying to correlate that to the cause. It took me forever to figure it out.

Right, you should not name thes to be the same. They really mean different things. You should think the blend function as a pandas melt function. You can see more info here: http://pandas.pydata.org/pandas-docs/stable/reshaping.html#reshaping-by-melt and here http://pandas.pydata.org/pandas-docs/stable/generated/pandas.melt.html

  1. Is there an obvious way to display the value of a segment on a stacked bar when hover? Getting the coordinate and column name is easy, but if I want to find out the “count” of a segment… Since each segment obtains the input from different columns, not sure if the current hover syntax can support it. I guess a CallBack is needed?

For now you can use the columns names you have used on your plot bar plot (so for instance you could use Incident, Incidents, PdDistrict, …). I suggest you to try it and add issue asking for this feature (adding ways to spell other types of hover features).

Ok, this is the chart the kicked my ass… Now it’s finally tamed. Thanks again!

Thanks for the feedback again. And yes, the new charts semantics has changed a bit from the previous old charts and may require some time to be understood but definitely offer way more flexibility and functionality once you understand how to use it.

Best

Fabio

SH

FYI.

from bokeh.charts import Bar, output_notebook, show

from bokeh.charts.attributes import cat, color

from bokeh.charts.operations import blend

from bokeh.palettes import Spectral10

import pandas as pd

bar = Bar(df_topcrimes,

values=blend(‘OTHER OFFENSES’,‘VEHICLE THEFT’, ‘ASSAULT’, ‘NON-CRIMINAL’, ‘SUSPICIOUS OCC’, ‘LARCENY/THEFT’, ‘DRUG/NARCOTIC’, ‘MISSING PERSON’, ‘WARRANTS’, name=‘Incidents’, labels_name=‘Incident’),

label=cat(columns=‘PdDistrict’, sort=False),

stack=cat(columns=‘Incident’, sort=False),

color=color(columns=‘Incident’, palette=Spectral10, sort=False),

legend=‘top_right’,

title=“Crime Indident by PdDistrict”,

tooltips=[('Type: ‘, ‘@Incident’), (’#: ', ‘$y’)],

plot_width = 900, plot_height=600

)

output_notebook()

show(bar)

PdDistrict

TOTAL

OTHER OFFENSES

VEHICLE THEFT

ASSAULT

NON-CRIMINAL

SUSPICIOUS OCC

LARCENY/THEFT

DRUG/NARCOTIC

MISSING PERSON

WARRANTS

2

SOUTHERN

5739

904

161

528

639

213

2562

242

159

331

6

MISSION

3700

959

306

459

345

165

671

217

297

281

5

NORTHERN

3589

627

202

297

347

149

1499

174

101

193

8

CENTRAL

3513

615

146

277

431

131

1574

91

86

162

9

BAYVIEW

2725

765

245

359

203

171

481

111

141

249

7

INGLESIDE

2378

552

382

292

189

93

548

81

131

110

0

TENDERLOIN

2257

503

34

324

216

125

481

284

53

237

1

TARAVAL

1853

420

222

147

210

104

547

31

107

65

4

PARK

1693

283

150

118

193

60

576

63

141

109

3

RICHMOND

1546

335

118

81

250

89

527

51

50

45

On Friday, January 8, 2016 at 10:06:16 AM UTC-8, SH Ho wrote:

Hi Guys

Not sure if this is the appropriate forum to ask this type of question… But I thought I start here.

I produced a bar chart in Bokeh 0.11 w/ the following code:

from bokeh.palettes import Spectral10

from bokeh.charts import Bar, output_notebook, show

from bokeh.charts.attributes import AttrSpec, ColorAttr, MarkerAttr, CatAttr

pddf = sf2.to_dataframe()

#p = Bar(pddf, label=‘PdDistrict’, values=‘PdId’)

p = Bar(pddf, values = ‘PdId’,

agg=‘count’,

stack=‘Category’,

tools=“resize,hover,save”,

label=CatAttr(columns=[‘PdDistrict’], sort=True))

output_notebook()

show§

By and large, it looks like what I have in mind, but it’s far from release quality. But can’t figure out a few key issues. Hopefully you can give me some pointers.

Q1. How do you sort the plot? There are discussion threads #2924 and #2935, but it looks like nothing got resolved. The label=CatAttr(columns=[‘labels’], sort=True) approach only works w/ simple bar charts. It does not work for either stacked or grouped bar charts. Any suggestions?

Q2. How do you specify a different palette, eg. Spectral10 into ColorAttr for a chart? All a user wants is to have a color array longer than 6 elements, does he really have to go through all the steps just to get a deeper palette?

Q3. The size. How can I control the size of the plot as with figures? Right now, I enabled tools=“resize”, but I prefer the chart to come out a prespecified dimension without user intervention. It’s a simple operation, but I can’t find information anywhere.

Q4. Hover… I am sure this involves some JS programming… When I hover over a stack on a bar, I would like the tool tip to display the name of category, the count, and the percentage. How do I go about doing that?

Q5. How do display the total on top of each bar?

Thank you for your support. Your support will help build a complete example that will be released back to the community.

regards,

SH


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/0ba01f41-f5a8-4460-9a05-08196b520c47%40continuum.io.

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


Fabio Pliger

Senior Software Engineer, Bokeh


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/CAPVmnqApCm9TrYevi3LoUk17%3DCoxRc8_DUo_W_Xe_DHdx%3DcyDA%40mail.gmail.com.
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/d15a61f9-b65a-4f59-ab2c-d3afd76f8e71%40continuum.io.

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

Fabio Pliger

Senior Software Engineer, Bokeh

Hi Fabio,

I think that’s a great idea to have dedicated notebooks to go through the details of setting up a chart. I re-read the Key Concepts and Bar Charts sections of http://bokeh.pydata.org/en/latest/docs/user_guide/charts.html this morning after having looked at the layout of the dataset bokeh.sampledata.autompg and now the instructions and explanations make a lot more sense. Last night I was having a very hard time wrapping my head around what was going on since I wasn’t familiar with the dataset and a first look didn’t do it for me.

As I become familiar with Bokeh I have begun to realize a particular use case that wasn’t originally apparent to me: when I want to communicate data and interactive graphics with faculty colleagues it would be so cool to just email them a static html file they can open in a browser and have respond to their manipulation of widgets. This would also be great for sharing interactive demonstrations with students in my classes. Of course, such files could also be served with a static server (I’m really liking a new open source server, Caddy). I guess it’s taken me awhile to catch on to the power of static html files with interactive capabilities, but I’m really liking this! Now if I could just do this with animations (i.e., using periodic callbacks in the html file) in a static notebook (no connection to a server), that would cover 99% of my use cases.

Thanks for all of your great work and timely feedback!

Greg

···

On Saturday, January 9, 2016 at 10:09:16 AM UTC-7, Fabio Pliger wrote:

Thank SH and Greg for your feedback. It’s really valuable. I agree that specially charts needs more and better detailed documentation. We have already improved a lot but it’s definitely not enough and we are working on it. The main problem is that charts really do a lot in figuring out and transforming the different types and shapes of input users may ingest.

There are ongoing efforts to do this and one idea is also to have dedicated notebooks to cover in details aspects of the API (like operators, grouping arguments, specs, etc…) and have the linked to the documentation related sections.

Also, I’d also encourage users in general to send more suggestions here or through issues and/or contribution PRs. All are very welcome! :slight_smile:

Thanks!!!

On Sat, Jan 9, 2016 at 12:36 AM, Greg Nordin [email protected] wrote:

I agree that having a rich set of reference examples is extremely helpful. One thing I might add based on my own experience is that sometimes the contents and format of the data used in the example are not clear, which makes it very difficult to understand the example. It would be helpful to at least do something like df.head() in the example to give the reader an idea about what the data looks like (at least for the situation in which dataframes are used).

Greg

On Friday, January 8, 2016 at 11:27:32 PM UTC-7, SH Ho wrote:

Hi Fabio

It is always difficult for newcomers to find out which examples to even use. There are at least three different bar chart examples, but it’s the last one you sent me the one that really matters. And that’s the one that the community should reference going forward… How exactly, not sure. Hopefully once it warms up, it’ll get propped higher on google.

For me, learning to use a plotting package is all about utilizing reference examples. Give the users super rich reference, and let them see and replicate the possibilities - it’s much easier to subtract than to add. So with your support, I like to create plots that are as feature rich as possible and let the community leverage that for their own work.

Thanks and stay tuned for more!

SH

On Jan 8, 2016, at 7:40 PM, Fabio Pliger [email protected] wrote:

Hi,

I’m very glad you got it working! Nice! Your feedback is very important to us since we are really really eager in keeping improving our documentation and resources better and more discoverable. It be very useful if you could provide your experience and/or suggestions about how we could have made it easier to find the information you needed.

On Fri, Jan 8, 2016 at 8:44 PM, SH Ho [email protected] wrote:

Finally!!! Thanks guys, couldn’t have possibly done it without your help. You either get the syntax or you don’t. Simple as that. The new example bar is what I have been looking for all this time. I searched Bokeh doc and github left and right but I never saw that one.

A couple feedback/questions.

  1. if I set the name and labels_name to be the same in blend, it raises an error: AttributeError: ‘DataFrame’ object has no attribute ‘tolist’… It’s rather difficult trying to correlate that to the cause. It took me forever to figure it out.

Right, you should not name thes to be the same. They really mean different things. You should think the blend function as a pandas melt function. You can see more info here: http://pandas.pydata.org/pandas-docs/stable/reshaping.html#reshaping-by-melt and here http://pandas.pydata.org/pandas-docs/stable/generated/pandas.melt.html

  1. Is there an obvious way to display the value of a segment on a stacked bar when hover? Getting the coordinate and column name is easy, but if I want to find out the “count” of a segment… Since each segment obtains the input from different columns, not sure if the current hover syntax can support it. I guess a CallBack is needed?

For now you can use the columns names you have used on your plot bar plot (so for instance you could use Incident, Incidents, PdDistrict, …). I suggest you to try it and add issue asking for this feature (adding ways to spell other types of hover features).

Ok, this is the chart the kicked my ass… Now it’s finally tamed. Thanks again!

Thanks for the feedback again. And yes, the new charts semantics has changed a bit from the previous old charts and may require some time to be understood but definitely offer way more flexibility and functionality once you understand how to use it.

Best

Fabio

SH

FYI.

from bokeh.charts import Bar, output_notebook, show

from bokeh.charts.attributes import cat, color

from bokeh.charts.operations import blend

from bokeh.palettes import Spectral10

import pandas as pd

bar = Bar(df_topcrimes,

values=blend(‘OTHER OFFENSES’,‘VEHICLE THEFT’, ‘ASSAULT’, ‘NON-CRIMINAL’, ‘SUSPICIOUS OCC’, ‘LARCENY/THEFT’, ‘DRUG/NARCOTIC’, ‘MISSING PERSON’, ‘WARRANTS’, name=‘Incidents’, labels_name=‘Incident’),

label=cat(columns=‘PdDistrict’, sort=False),

stack=cat(columns=‘Incident’, sort=False),

color=color(columns=‘Incident’, palette=Spectral10, sort=False),

legend=‘top_right’,

title=“Crime Indident by PdDistrict”,

tooltips=[('Type: ‘, ‘@Incident’), (’#: ', ‘$y’)],

plot_width = 900, plot_height=600

)

output_notebook()

show(bar)

PdDistrict

TOTAL

OTHER OFFENSES

VEHICLE THEFT

ASSAULT

NON-CRIMINAL

SUSPICIOUS OCC

LARCENY/THEFT

DRUG/NARCOTIC

MISSING PERSON

WARRANTS

2

SOUTHERN

5739

904

161

528

639

213

2562

242

159

331

6

MISSION

3700

959

306

459

345

165

671

217

297

281

5

NORTHERN

3589

627

202

297

347

149

1499

174

101

193

8

CENTRAL

3513

615

146

277

431

131

1574

91

86

162

9

BAYVIEW

2725

765

245

359

203

171

481

111

141

249

7

INGLESIDE

2378

552

382

292

189

93

548

81

131

110

0

TENDERLOIN

2257

503

34

324

216

125

481

284

53

237

1

TARAVAL

1853

420

222

147

210

104

547

31

107

65

4

PARK

1693

283

150

118

193

60

576

63

141

109

3

RICHMOND

1546

335

118

81

250

89

527

51

50

45

On Friday, January 8, 2016 at 10:06:16 AM UTC-8, SH Ho wrote:

Hi Guys

Not sure if this is the appropriate forum to ask this type of question… But I thought I start here.

I produced a bar chart in Bokeh 0.11 w/ the following code:

from bokeh.palettes import Spectral10

from bokeh.charts import Bar, output_notebook, show

from bokeh.charts.attributes import AttrSpec, ColorAttr, MarkerAttr, CatAttr

pddf = sf2.to_dataframe()

#p = Bar(pddf, label=‘PdDistrict’, values=‘PdId’)

p = Bar(pddf, values = ‘PdId’,

agg=‘count’,

stack=‘Category’,

tools=“resize,hover,save”,

label=CatAttr(columns=[‘PdDistrict’], sort=True))

output_notebook()

show§

By and large, it looks like what I have in mind, but it’s far from release quality. But can’t figure out a few key issues. Hopefully you can give me some pointers.

Q1. How do you sort the plot? There are discussion threads #2924 and #2935, but it looks like nothing got resolved. The label=CatAttr(columns=[‘labels’], sort=True) approach only works w/ simple bar charts. It does not work for either stacked or grouped bar charts. Any suggestions?

Q2. How do you specify a different palette, eg. Spectral10 into ColorAttr for a chart? All a user wants is to have a color array longer than 6 elements, does he really have to go through all the steps just to get a deeper palette?

Q3. The size. How can I control the size of the plot as with figures? Right now, I enabled tools=“resize”, but I prefer the chart to come out a prespecified dimension without user intervention. It’s a simple operation, but I can’t find information anywhere.

Q4. Hover… I am sure this involves some JS programming… When I hover over a stack on a bar, I would like the tool tip to display the name of category, the count, and the percentage. How do I go about doing that?

Q5. How do display the total on top of each bar?

Thank you for your support. Your support will help build a complete example that will be released back to the community.

regards,

SH


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/0ba01f41-f5a8-4460-9a05-08196b520c47%40continuum.io.

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


Fabio Pliger

Senior Software Engineer, Bokeh


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/CAPVmnqApCm9TrYevi3LoUk17%3DCoxRc8_DUo_W_Xe_DHdx%3DcyDA%40mail.gmail.com.
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/d15a61f9-b65a-4f59-ab2c-d3afd76f8e71%40continuum.io.

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


Fabio Pliger

Senior Software Engineer, Bokeh

Hello,

I created a sorted bar chart using the bokeh.charts interface (bokeh 0.11) folowing this example: http://bokeh.pydata.org/en/latest/docs/gallery/stacked_bar_chart.html but the Hover Tool does not seem to work properly:

import pandas as pd

from bokeh.charts import Bar

from bokeh.io import output_file, show

from bokeh.charts.attributes import cat

#Creating the DataFrame for chart 1: Filtering/Grouping/Sorting

df_chart1 = df_rolling[df_rolling.SCRAP>0]

df_chart1 = df_chart1.groupby(by=‘MATERIAL_GROUP’,

as_index=False)[‘SCRAP’].sum()

df_chart1 = df_chart1.sort_values(by=‘SCRAP’,ascending=False)

#Calculating the Scrap in tons

df_chart1[‘SCRAP_tn’] = df_chart1.SCRAP/1000

df_chart1[‘SCRAP_tn’] = df_chart1[‘SCRAP_tn’].astype(object)

#Plotting chart 1

chart1 = Bar(df_chart1,values=‘SCRAP_tn’,

label=cat(columns=‘MATERIAL_GROUP’,sort=False),

title=‘Rolling Factory: Scrap(tons) per Material Group’,

ylabel=‘Scrap(tons)’,xlabel=‘Material Group’,

bar_width=0.6,xgrid=True,color=‘RoyalBlue’,

tooltips=[(‘Material’,’@MATERIAL_GROUP’),(‘Scrap’,’@SCRAP_tn’)])

chart1.title_text_font_size = ‘20pt’

chart1.background_fill_color = “whitesmoke”

chart1.plot_width=900

output_file(‘DMSY_November_2015.html’)

show(chart1)

The result is the attached picture. I should be able to see the amount of scrap in tons (e.g. “165.4”) but all I see is “???”

Does anyone have any idea how to help me?

Thanking you in advance for your input,

PZ

···

On Friday, 8 January 2016 20:06:16 UTC+2, SH Ho wrote:

Hi Guys

Not sure if this is the appropriate forum to ask this type of question… But I thought I start here.

I produced a bar chart in Bokeh 0.11 w/ the following code:

from bokeh.palettes import Spectral10

from bokeh.charts import Bar, output_notebook, show

from bokeh.charts.attributes import AttrSpec, ColorAttr, MarkerAttr, CatAttr

pddf = sf2.to_dataframe()

#p = Bar(pddf, label=‘PdDistrict’, values=‘PdId’)

p = Bar(pddf, values = ‘PdId’,

agg=‘count’,

stack=‘Category’,

tools=“resize,hover,save”,

label=CatAttr(columns=[‘PdDistrict’], sort=True))

output_notebook()

show§

By and large, it looks like what I have in mind, but it’s far from release quality. But can’t figure out a few key issues. Hopefully you can give me some pointers.

Q1. How do you sort the plot? There are discussion threads #2924 and #2935, but it looks like nothing got resolved. The label=CatAttr(columns=[‘labels’], sort=True) approach only works w/ simple bar charts. It does not work for either stacked or grouped bar charts. Any suggestions?

Q2. How do you specify a different palette, eg. Spectral10 into ColorAttr for a chart? All a user wants is to have a color array longer than 6 elements, does he really have to go through all the steps just to get a deeper palette?

Q3. The size. How can I control the size of the plot as with figures? Right now, I enabled tools=“resize”, but I prefer the chart to come out a prespecified dimension without user intervention. It’s a simple operation, but I can’t find information anywhere.

Q4. Hover… I am sure this involves some JS programming… When I hover over a stack on a bar, I would like the tool tip to display the name of category, the count, and the percentage. How do I go about doing that?

Q5. How do display the total on top of each bar?

Thank you for your support. Your support will help build a complete example that will be released back to the community.

regards,

SH