Grouped categories graph from an updating ColumnDataSource

Working with Bokeh server, I have an updating ColumnDataSource with data of the following structure:

Winter
Spring
Summer
Autumn
0
34.331625
38.795715
45.929808
45.012135
1
34.317697
39.102616
46.327440
43.712549
2
35.937087
38.637403
46.879502
42.152996
3
35.120408
38.195147
47.275160
41.734490
4
33.805244
35.815556
47.550663
41.155371
5
35.334733
37.654497
47.634063
44.799259
6
35.743624
38.012639
48.044815
45.249237

The structure is constant however the data may change.

I am trying to create a grouped bar table, where the X axis is the index (representing days of the week) and the y axis is the different values. Each day should have 4 bars within: winter, spring, summer and autumn.

How do I achieve this? I tried following the Grouped / Nested tutorial in the documentation however that keep taking me to a ‘Expected top to reference fields in the supplied data source’ error.

    index = ['0', '1', '2', '3', '4', '5', '6']
    columns = ['Winter', 'Spring', 'Summer', 'Autumn']
    x = [(i, season) for i in index for season in columns]
    n = sum(zip(rb.SDCM_src.data['Winter'].tolist(),
                rb.SDCM_src.data['Spring'].tolist(),
                rb.SDCM_src.data['Summer'].tolist(),
                rb.SDCM_src.data['Autumn'].tolist()), ())
   
    self.bf2 = figure(x_range = FactorRange(*x), plot_height=250)
    self.bf2.vbar(x='x', top=n, width=0.2, source = self.SDCM_src)

``

I can probably extract the data into an intermediate set of variables, however I don’t think the graph would then update with the changing data.

Hi,

You need to put *all* the data in the source self.SDCM_src. You should not mix passing in both a column name "x" and a literal list of data n. In fact there should be getting a very loud warning about doing this. Offhand,

  self.SDCM_src.data['n] = n

and

  self.bf2.vbar(x='x', top='n, ...)

Should work but you will have to change to whatever is most appropriate for your situation.

Thanks

···

On May 2, 2019, at 10:35 AM, [email protected] wrote:

Working with Bokeh server, I have an updating ColumnDataSource with data of the following structure:

Winter Spring Summer Autumn
0 34.331625 38.795715 45.929808 45.012135
1 34.317697 39.102616 46.327440 43.712549
2 35.937087 38.637403 46.879502 42.152996
3 35.120408 38.195147 47.275160 41.734490
4 33.805244 35.815556 47.550663 41.155371
5 35.334733 37.654497 47.634063 44.799259
6 35.743624 38.012639 48.044815 45.249237

The structure is constant however the data may change.

I am trying to create a grouped bar table, where the X axis is the index (representing days of the week) and the y axis is the different values. Each day should have 4 bars within: winter, spring, summer and autumn.

How do I achieve this? I tried following the Grouped / Nested tutorial in the documentation however that keep taking me to a 'Expected top to reference fields in the supplied data source' error.

        index = ['0', '1', '2', '3', '4', '5', '6']
        columns = ['Winter', 'Spring', 'Summer', 'Autumn']
        x = [(i, season) for i in index for season in columns]
        n = sum(zip(rb.SDCM_src.data['Winter'].tolist(),
                    rb.SDCM_src.data['Spring'].tolist(),
                    rb.SDCM_src.data['Summer'].tolist(),
                    rb.SDCM_src.data['Autumn'].tolist()), ())
        
        self.bf2 = figure(x_range = FactorRange(*x), plot_height=250)
        self.bf2.vbar(x='x', top=n, width=0.2, source = self.SDCM_src)

I can probably extract the data into an intermediate set of variables, however I don't think the graph would then update with the changing data.

--
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/f486ed98-3019-4ed4-8762-7d9d90edc6ae%40continuum.io\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.

Thanks Bryan this works:
(data is the dataframe in the discussion above)

colorPallete = Spectral4[0:4]

data = rb.SDCM

cds = ColumnDataSource()

index = [‘Mon’, ‘Tue’, ‘Wed’, ‘Thu’, ‘Fri’, ‘Sat’, ‘Sun’]

columns = [‘Winter’, ‘Spring’, ‘Summer’, ‘Autumn’]

x = [(i, season) for i in index for season in columns]

n = sum(zip(data[‘Winter’].tolist(),

data[‘Spring’].tolist(),

data[‘Summer’].tolist(),

data[‘Autumn’].tolist()), ())

cds.data[‘n’] = n

cds.data[‘x’] = x

p = figure(x_range = FactorRange(*x), plot_height=250)

p.vbar (x=‘x’, top=‘n’, width = 0.5, source = cds,

line_color=‘white’,

fill_color=factor_cmap(‘x’, palette=colorPallete, factors=columns, start=1, end=2))

p.xaxis.major_label_orientation = 1.58

show(p)

``

···

On Thursday, May 2, 2019 at 4:21:43 PM UTC+1, Bryan Van de Ven wrote:

Hi,

You need to put all the data in the source self.SDCM_src. You should not mix passing in both a column name “x” and a literal list of data n. In fact there should be getting a very loud warning about doing this. Offhand,

    self.SDCM_src.data['n] = n

and

    self.bf2.vbar(x='x', top='n, ...)

Should work but you will have to change to whatever is most appropriate for your situation.

Thanks

On May 2, 2019, at 10:35 AM, [email protected] wrote:

Working with Bokeh server, I have an updating ColumnDataSource with data of the following structure:

Winter Spring Summer Autumn

0 34.331625 38.795715 45.929808 45.012135

1 34.317697 39.102616 46.327440 43.712549

2 35.937087 38.637403 46.879502 42.152996

3 35.120408 38.195147 47.275160 41.734490

4 33.805244 35.815556 47.550663 41.155371

5 35.334733 37.654497 47.634063 44.799259

6 35.743624 38.012639 48.044815 45.249237

The structure is constant however the data may change.

I am trying to create a grouped bar table, where the X axis is the index (representing days of the week) and the y axis is the different values. Each day should have 4 bars within: winter, spring, summer and autumn.

How do I achieve this? I tried following the Grouped / Nested tutorial in the documentation however that keep taking me to a ‘Expected top to reference fields in the supplied data source’ error.

    index = ['0', '1', '2', '3', '4', '5', '6']
    columns = ['Winter', 'Spring', 'Summer', 'Autumn']
    x = [(i, season) for i in index for season in columns]
    n = sum(zip(rb.SDCM_src.data['Winter'].tolist(),
                rb.SDCM_src.data['Spring'].tolist(),
                rb.SDCM_src.data['Summer'].tolist(),
                rb.SDCM_src.data['Autumn'].tolist()), ())
    self.bf2 = figure(x_range = FactorRange(*x), plot_height=250)
    self.bf2.vbar(x='x', top=n, width=0.2, source = self.SDCM_src)

I can probably extract the data into an intermediate set of variables, however I don’t think the graph would then update with the changing data.


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/f486ed98-3019-4ed4-8762-7d9d90edc6ae%40continuum.io.

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

Seems like creating an index here is tricky however :
legend = value(x) for x in columns

``

triggers:

TypeError: StringSpec convenience list values must have length 1

it is possible to go around this by defining the legend as part of the ColumnDataSource:

cds.data[‘legend’] = columns

legend = ‘legend’

however then a non-fatal UserWarning is triggered:

BokehUserWarning: ColumnDataSource’s columns must be of the same length. Current lengths: (‘legend’, 4), (‘n’, 28), (‘x’, 28)

···

On Thursday, May 9, 2019 at 10:29:59 AM UTC+1, Noam Naveh wrote:

Thanks Bryan this works:
(data is the dataframe in the discussion above)

colorPallete = Spectral4[0:4]

data = rb.SDCM

cds = ColumnDataSource()

index = [‘Mon’, ‘Tue’, ‘Wed’, ‘Thu’, ‘Fri’, ‘Sat’, ‘Sun’]

columns = [‘Winter’, ‘Spring’, ‘Summer’, ‘Autumn’]

x = [(i, season) for i in index for season in columns]

n = sum(zip(data[‘Winter’].tolist(),

data[‘Spring’].tolist(),

data[‘Summer’].tolist(),

data[‘Autumn’].tolist()), ())

cds.data[‘n’] = n

cds.data[‘x’] = x

p = figure(x_range = FactorRange(*x), plot_height=250)

p.vbar (x=‘x’, top=‘n’, width = 0.5, source = cds,

line_color=‘white’,

fill_color=factor_cmap(‘x’, palette=colorPallete, factors=columns, start=1, end=2))

p.xaxis.major_label_orientation = 1.58

show(p)

``

On Thursday, May 2, 2019 at 4:21:43 PM UTC+1, Bryan Van de Ven wrote:

Hi,

You need to put all the data in the source self.SDCM_src. You should not mix passing in both a column name “x” and a literal list of data n. In fact there should be getting a very loud warning about doing this. Offhand,

    self.SDCM_src.data['n] = n

and

    self.bf2.vbar(x='x', top='n, ...)

Should work but you will have to change to whatever is most appropriate for your situation.

Thanks

On May 2, 2019, at 10:35 AM, [email protected] wrote:

Working with Bokeh server, I have an updating ColumnDataSource with data of the following structure:

Winter Spring Summer Autumn

0 34.331625 38.795715 45.929808 45.012135

1 34.317697 39.102616 46.327440 43.712549

2 35.937087 38.637403 46.879502 42.152996

3 35.120408 38.195147 47.275160 41.734490

4 33.805244 35.815556 47.550663 41.155371

5 35.334733 37.654497 47.634063 44.799259

6 35.743624 38.012639 48.044815 45.249237

The structure is constant however the data may change.

I am trying to create a grouped bar table, where the X axis is the index (representing days of the week) and the y axis is the different values. Each day should have 4 bars within: winter, spring, summer and autumn.

How do I achieve this? I tried following the Grouped / Nested tutorial in the documentation however that keep taking me to a ‘Expected top to reference fields in the supplied data source’ error.

    index = ['0', '1', '2', '3', '4', '5', '6']
    columns = ['Winter', 'Spring', 'Summer', 'Autumn']
    x = [(i, season) for i in index for season in columns]
    n = sum(zip(rb.SDCM_src.data['Winter'].tolist(),
                rb.SDCM_src.data['Spring'].tolist(),
                rb.SDCM_src.data['Summer'].tolist(),
                rb.SDCM_src.data['Autumn'].tolist()), ())
    self.bf2 = figure(x_range = FactorRange(*x), plot_height=250)
    self.bf2.vbar(x='x', top=n, width=0.2, source = self.SDCM_src)

I can probably extract the data into an intermediate set of variables, however I don’t think the graph would then update with the changing data.


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/f486ed98-3019-4ed4-8762-7d9d90edc6ae%40continuum.io.

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

Hi,

It's unclear to me what you are trying to accomplish. The value of the legend parameter should only ever be single string level, or a single value(label) if yo need to make it clear the legend is not referring to a column name to group by.

Thanks,

Bryan

···

On May 9, 2019, at 3:23 AM, [email protected] wrote:

Seems like creating an index here is tricky however :
legend = value(x) for x in columns
triggers:
TypeError: StringSpec convenience list values must have length 1

it is possible to go around this by defining the legend as part of the ColumnDataSource:
cds.data['legend'] = columns
...
legend = 'legend'
however then a non-fatal UserWarning is triggered:
BokehUserWarning: ColumnDataSource's columns must be of the same length. Current lengths: ('legend', 4), ('n', 28), ('x', 28)

On Thursday, May 9, 2019 at 10:29:59 AM UTC+1, Noam Naveh wrote:
Thanks Bryan this works:
(data is the dataframe in the discussion above)

colorPallete = Spectral4[0:4]
data = rb.SDCM
cds = ColumnDataSource()

index = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
columns = ['Winter', 'Spring', 'Summer', 'Autumn']
x = [(i, season) for i in index for season in columns]

n = sum(zip(data['Winter'].tolist(),
            data['Spring'].tolist(),
            data['Summer'].tolist(),
            data['Autumn'].tolist()), ())
cds.data['n'] = n
cds.data['x'] = x

p = figure(x_range = FactorRange(*x), plot_height=250)
p.vbar (x='x', top='n', width = 0.5, source = cds,
        line_color='white',
        fill_color=factor_cmap('x', palette=colorPallete, factors=columns, start=1, end=2))
p.xaxis.major_label_orientation = 1.58
show(p)

On Thursday, May 2, 2019 at 4:21:43 PM UTC+1, Bryan Van de Ven wrote:
Hi,

You need to put *all* the data in the source self.SDCM_src. You should not mix passing in both a column name "x" and a literal list of data n. In fact there should be getting a very loud warning about doing this. Offhand,

        self.SDCM_src.data['n] = n

and

        self.bf2.vbar(x='x', top='n, ...)

Should work but you will have to change to whatever is most appropriate for your situation.

Thanks

> On May 2, 2019, at 10:35 AM, noa...@gmail.com wrote:
>
> Working with Bokeh server, I have an updating ColumnDataSource with data of the following structure:
>
> Winter Spring Summer Autumn
> 0 34.331625 38.795715 45.929808 45.012135
> 1 34.317697 39.102616 46.327440 43.712549
> 2 35.937087 38.637403 46.879502 42.152996
> 3 35.120408 38.195147 47.275160 41.734490
> 4 33.805244 35.815556 47.550663 41.155371
> 5 35.334733 37.654497 47.634063 44.799259
> 6 35.743624 38.012639 48.044815 45.249237
>
> The structure is constant however the data may change.
>
> I am trying to create a grouped bar table, where the X axis is the index (representing days of the week) and the y axis is the different values. Each day should have 4 bars within: winter, spring, summer and autumn.
>
>
> How do I achieve this? I tried following the Grouped / Nested tutorial in the documentation however that keep taking me to a 'Expected top to reference fields in the supplied data source' error.
>
> index = ['0', '1', '2', '3', '4', '5', '6']
> columns = ['Winter', 'Spring', 'Summer', 'Autumn']
> x = [(i, season) for i in index for season in columns]
> n = sum(zip(rb.SDCM_src.data['Winter'].tolist(),
> rb.SDCM_src.data['Spring'].tolist(),
> rb.SDCM_src.data['Summer'].tolist(),
> rb.SDCM_src.data['Autumn'].tolist()), ())
>
> self.bf2 = figure(x_range = FactorRange(*x), plot_height=250)
> self.bf2.vbar(x='x', top=n, width=0.2, source = self.SDCM_src)
>
> I can probably extract the data into an intermediate set of variables, however I don't think the graph would then update with the changing data.
>
>
>
> --
> 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 bo...@continuum.io.
> To post to this group, send email to bo...@continuum.io.
> To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/f486ed98-3019-4ed4-8762-7d9d90edc6ae%40continuum.io\.
> For more options, visit https://groups.google.com/a/continuum.io/d/optout\.

--
You received this message because you are subscribed to the Google Groups "Bokeh Discussion - Public" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/b1e378cd-2e32-41ae-985a-f2e0de92a534%40continuum.io\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.

That should read: single string *label*

···

On May 9, 2019, at 7:16 AM, Bryan Van de Ven <[email protected]> wrote:

Hi,

It's unclear to me what you are trying to accomplish. The value of the legend parameter should only ever be single string level, or a single value(label) if yo need to make it clear the legend is not referring to a column name to group by.

Thanks,

Bryan

On May 9, 2019, at 3:23 AM, [email protected] wrote:

Seems like creating an index here is tricky however :
legend = value(x) for x in columns
triggers:
TypeError: StringSpec convenience list values must have length 1

it is possible to go around this by defining the legend as part of the ColumnDataSource:
cds.data['legend'] = columns
...
legend = 'legend'
however then a non-fatal UserWarning is triggered:
BokehUserWarning: ColumnDataSource's columns must be of the same length. Current lengths: ('legend', 4), ('n', 28), ('x', 28)

On Thursday, May 9, 2019 at 10:29:59 AM UTC+1, Noam Naveh wrote:
Thanks Bryan this works:
(data is the dataframe in the discussion above)

colorPallete = Spectral4[0:4]
data = rb.SDCM
cds = ColumnDataSource()

index = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
columns = ['Winter', 'Spring', 'Summer', 'Autumn']
x = [(i, season) for i in index for season in columns]

n = sum(zip(data['Winter'].tolist(),
           data['Spring'].tolist(),
           data['Summer'].tolist(),
           data['Autumn'].tolist()), ())
cds.data['n'] = n
cds.data['x'] = x

p = figure(x_range = FactorRange(*x), plot_height=250)
p.vbar (x='x', top='n', width = 0.5, source = cds,
       line_color='white',
       fill_color=factor_cmap('x', palette=colorPallete, factors=columns, start=1, end=2))
p.xaxis.major_label_orientation = 1.58
show(p)

On Thursday, May 2, 2019 at 4:21:43 PM UTC+1, Bryan Van de Ven wrote:
Hi,

You need to put *all* the data in the source self.SDCM_src. You should not mix passing in both a column name "x" and a literal list of data n. In fact there should be getting a very loud warning about doing this. Offhand,

       self.SDCM_src.data['n] = n

and

       self.bf2.vbar(x='x', top='n, ...)

Should work but you will have to change to whatever is most appropriate for your situation.

Thanks

On May 2, 2019, at 10:35 AM, noa...@gmail.com wrote:

Working with Bokeh server, I have an updating ColumnDataSource with data of the following structure:

Winter Spring Summer Autumn
0 34.331625 38.795715 45.929808 45.012135
1 34.317697 39.102616 46.327440 43.712549
2 35.937087 38.637403 46.879502 42.152996
3 35.120408 38.195147 47.275160 41.734490
4 33.805244 35.815556 47.550663 41.155371
5 35.334733 37.654497 47.634063 44.799259
6 35.743624 38.012639 48.044815 45.249237

The structure is constant however the data may change.

I am trying to create a grouped bar table, where the X axis is the index (representing days of the week) and the y axis is the different values. Each day should have 4 bars within: winter, spring, summer and autumn.

How do I achieve this? I tried following the Grouped / Nested tutorial in the documentation however that keep taking me to a 'Expected top to reference fields in the supplied data source' error.

       index = ['0', '1', '2', '3', '4', '5', '6']
       columns = ['Winter', 'Spring', 'Summer', 'Autumn']
       x = [(i, season) for i in index for season in columns]
       n = sum(zip(rb.SDCM_src.data['Winter'].tolist(),
                   rb.SDCM_src.data['Spring'].tolist(),
                   rb.SDCM_src.data['Summer'].tolist(),
                   rb.SDCM_src.data['Autumn'].tolist()), ())

       self.bf2 = figure(x_range = FactorRange(*x), plot_height=250)
       self.bf2.vbar(x='x', top=n, width=0.2, source = self.SDCM_src)

I can probably extract the data into an intermediate set of variables, however I don't think the graph would then update with the changing data.

--
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 bo...@continuum.io.
To post to this group, send email to bo...@continuum.io.
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/f486ed98-3019-4ed4-8762-7d9d90edc6ae%40continuum.io\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.

--
You received this message because you are subscribed to the Google Groups "Bokeh Discussion - Public" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/b1e378cd-2e32-41ae-985a-f2e0de92a534%40continuum.io\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.

I am trying to create a legend for this table by following this example from the documentation, where it shows:

p.vbar_stack(years, x='fruits', width=0.9, color=colors, source=data,
             legend=[value(x) for x in years])

However this triggers a TypeError:

self.barFig.vbar (x=‘x’, top=‘n’, width = 0.5, source = self.SDCM_barFig_src,
legend = [value(x) for x in columns],
line_color=‘white’,
fill_color=factor_cmap(‘x’, palette=colorPallete, factors=[“Winter”, “Spring”, “Summer”, “Autumn”], start=1, end=2))

``

···

On Thursday, May 9, 2019 at 3:17:55 PM UTC+1, Bryan Van de Ven wrote:

That should read: single string label

On May 9, 2019, at 7:16 AM, Bryan Van de Ven [email protected] wrote:

Hi,

It’s unclear to me what you are trying to accomplish. The value of the legend parameter should only ever be single string level, or a single value(label) if yo need to make it clear the legend is not referring to a column name to group by.

Thanks,

Bryan

On May 9, 2019, at 3:23 AM, [email protected] wrote:

Seems like creating an index here is tricky however :

legend = value(x) for x in columns

triggers:

TypeError: StringSpec convenience list values must have length 1

it is possible to go around this by defining the legend as part of the ColumnDataSource:

cds.data[‘legend’] = columns

legend = ‘legend’

however then a non-fatal UserWarning is triggered:

BokehUserWarning: ColumnDataSource’s columns must be of the same length. Current lengths: (‘legend’, 4), (‘n’, 28), (‘x’, 28)

On Thursday, May 9, 2019 at 10:29:59 AM UTC+1, Noam Naveh wrote:

Thanks Bryan this works:

(data is the dataframe in the discussion above)

colorPallete = Spectral4[0:4]

data = rb.SDCM

cds = ColumnDataSource()

index = [‘Mon’, ‘Tue’, ‘Wed’, ‘Thu’, ‘Fri’, ‘Sat’, ‘Sun’]

columns = [‘Winter’, ‘Spring’, ‘Summer’, ‘Autumn’]

x = [(i, season) for i in index for season in columns]

n = sum(zip(data[‘Winter’].tolist(),

       data['Spring'].tolist(),
       data['Summer'].tolist(),
       data['Autumn'].tolist()), ())

cds.data[‘n’] = n

cds.data[‘x’] = x

p = figure(x_range = FactorRange(*x), plot_height=250)

p.vbar (x=‘x’, top=‘n’, width = 0.5, source = cds,

   line_color='white',
   fill_color=factor_cmap('x', palette=colorPallete, factors=columns, start=1, end=2))

p.xaxis.major_label_orientation = 1.58

show(p)

On Thursday, May 2, 2019 at 4:21:43 PM UTC+1, Bryan Van de Ven wrote:

Hi,

You need to put all the data in the source self.SDCM_src. You should not mix passing in both a column name “x” and a literal list of data n. In fact there should be getting a very loud warning about doing this. Offhand,

   self.SDCM_src.data['n] = n

and

   self.bf2.vbar(x='x', top='n, ...)

Should work but you will have to change to whatever is most appropriate for your situation.

Thanks

On May 2, 2019, at 10:35 AM, [email protected] wrote:

Working with Bokeh server, I have an updating ColumnDataSource with data of the following structure:

Winter Spring Summer Autumn
0 34.331625 38.795715 45.929808 45.012135
1 34.317697 39.102616 46.327440 43.712549
2 35.937087 38.637403 46.879502 42.152996
3 35.120408 38.195147 47.275160 41.734490
4 33.805244 35.815556 47.550663 41.155371
5 35.334733 37.654497 47.634063 44.799259
6 35.743624 38.012639 48.044815 45.249237

The structure is constant however the data may change.

I am trying to create a grouped bar table, where the X axis is the index (representing days of the week) and the y axis is the different values. Each day should have 4 bars within: winter, spring, summer and autumn.

How do I achieve this? I tried following the Grouped / Nested tutorial in the documentation however that keep taking me to a ‘Expected top to reference fields in the supplied data source’ error.

   index = ['0', '1', '2', '3', '4', '5', '6']
   columns = ['Winter', 'Spring', 'Summer', 'Autumn']
   x = [(i, season) for i in index for season in columns]
   n = sum(zip(rb.SDCM_src.data['Winter'].tolist(),
               rb.SDCM_src.data['Spring'].tolist(),
               rb.SDCM_src.data['Summer'].tolist(),
               rb.SDCM_src.data['Autumn'].tolist()), ())

   self.bf2 = figure(x_range = FactorRange(*x), plot_height=250)
   self.bf2.vbar(x='x', top=n, width=0.2, source = self.SDCM_src)

I can probably extract the data into an intermediate set of variables, however I don’t think the graph would then update with the changing data.


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/f486ed98-3019-4ed4-8762-7d9d90edc6ae%40continuum.io.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.


You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.

To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].

To post to this group, send email to [email protected].

To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/b1e378cd-2e32-41ae-985a-f2e0de92a534%40continuum.io.

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

Hi,

The coordinates in a grouped chart are lists, e.g ['Tue', 'Winter'] The legend parameter expects strings (i.e. what label you want to show up in the legend on the plot) You need to convert the "x" values to strings somehow. How you do that is up to you, since it depends on what exactly you want to show up in the legend.

Thanks,

Bryan

···

On May 9, 2019, at 7:34 AM, [email protected] wrote:

I am trying to create a legend for this table by following this example from the documentation, where it shows:
p.vbar_stack(years, x='fruits', width=0.9, color=colors, source=data,

legend=[value(x) for x in years])

However this triggers a TypeError:
self.barFig.vbar (x='x', top='n', width = 0.5, source = self.SDCM_barFig_src,
                        legend = [value(x) for x in columns],
                        line_color='white',
                        fill_color=factor_cmap('x', palette=colorPallete, factors=["Winter", "Spring", "Summer", "Autumn"], start=1, end=2))

On Thursday, May 9, 2019 at 3:17:55 PM UTC+1, Bryan Van de Ven wrote:
That should read: single string *label*

> On May 9, 2019, at 7:16 AM, Bryan Van de Ven <[email protected]> wrote:
>
> Hi,
>
> It's unclear to me what you are trying to accomplish. The value of the legend parameter should only ever be single string level, or a single value(label) if yo need to make it clear the legend is not referring to a column name to group by.
>
> Thanks,
>
> Bryan
>
>> On May 9, 2019, at 3:23 AM, noa...@gmail.com wrote:
>>
>> Seems like creating an index here is tricky however :
>> legend = value(x) for x in columns
>> triggers:
>> TypeError: StringSpec convenience list values must have length 1
>>
>> it is possible to go around this by defining the legend as part of the ColumnDataSource:
>> cds.data['legend'] = columns
>> ...
>> legend = 'legend'
>> however then a non-fatal UserWarning is triggered:
>> BokehUserWarning: ColumnDataSource's columns must be of the same length. Current lengths: ('legend', 4), ('n', 28), ('x', 28)
>>
>>
>>
>> On Thursday, May 9, 2019 at 10:29:59 AM UTC+1, Noam Naveh wrote:
>> Thanks Bryan this works:
>> (data is the dataframe in the discussion above)
>>
>> colorPallete = Spectral4[0:4]
>> data = rb.SDCM
>> cds = ColumnDataSource()
>>
>> index = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
>> columns = ['Winter', 'Spring', 'Summer', 'Autumn']
>> x = [(i, season) for i in index for season in columns]
>>
>> n = sum(zip(data['Winter'].tolist(),
>> data['Spring'].tolist(),
>> data['Summer'].tolist(),
>> data['Autumn'].tolist()), ())
>> cds.data['n'] = n
>> cds.data['x'] = x
>>
>> p = figure(x_range = FactorRange(*x), plot_height=250)
>> p.vbar (x='x', top='n', width = 0.5, source = cds,
>> line_color='white',
>> fill_color=factor_cmap('x', palette=colorPallete, factors=columns, start=1, end=2))
>> p.xaxis.major_label_orientation = 1.58
>> show(p)
>>
>>
>>
>> On Thursday, May 2, 2019 at 4:21:43 PM UTC+1, Bryan Van de Ven wrote:
>> Hi,
>>
>> You need to put *all* the data in the source self.SDCM_src. You should not mix passing in both a column name "x" and a literal list of data n. In fact there should be getting a very loud warning about doing this. Offhand,
>>
>> self.SDCM_src.data['n] = n
>>
>> and
>>
>> self.bf2.vbar(x='x', top='n, ...)
>>
>> Should work but you will have to change to whatever is most appropriate for your situation.
>>
>> Thanks
>>
>>> On May 2, 2019, at 10:35 AM, noa...@gmail.com wrote:
>>>
>>> Working with Bokeh server, I have an updating ColumnDataSource with data of the following structure:
>>>
>>> Winter Spring Summer Autumn
>>> 0 34.331625 38.795715 45.929808 45.012135
>>> 1 34.317697 39.102616 46.327440 43.712549
>>> 2 35.937087 38.637403 46.879502 42.152996
>>> 3 35.120408 38.195147 47.275160 41.734490
>>> 4 33.805244 35.815556 47.550663 41.155371
>>> 5 35.334733 37.654497 47.634063 44.799259
>>> 6 35.743624 38.012639 48.044815 45.249237
>>>
>>> The structure is constant however the data may change.
>>>
>>> I am trying to create a grouped bar table, where the X axis is the index (representing days of the week) and the y axis is the different values. Each day should have 4 bars within: winter, spring, summer and autumn.
>>>
>>>
>>> How do I achieve this? I tried following the Grouped / Nested tutorial in the documentation however that keep taking me to a 'Expected top to reference fields in the supplied data source' error.
>>>
>>> index = ['0', '1', '2', '3', '4', '5', '6']
>>> columns = ['Winter', 'Spring', 'Summer', 'Autumn']
>>> x = [(i, season) for i in index for season in columns]
>>> n = sum(zip(rb.SDCM_src.data['Winter'].tolist(),
>>> rb.SDCM_src.data['Spring'].tolist(),
>>> rb.SDCM_src.data['Summer'].tolist(),
>>> rb.SDCM_src.data['Autumn'].tolist()), ())
>>>
>>> self.bf2 = figure(x_range = FactorRange(*x), plot_height=250)
>>> self.bf2.vbar(x='x', top=n, width=0.2, source = self.SDCM_src)
>>>
>>> I can probably extract the data into an intermediate set of variables, however I don't think the graph would then update with the changing data.
>>>
>>>
>>>
>>> --
>>> 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 bo...@continuum.io.
>>> To post to this group, send email to bo...@continuum.io.
>>> To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/f486ed98-3019-4ed4-8762-7d9d90edc6ae%40continuum.io\.
>>> For more options, visit https://groups.google.com/a/continuum.io/d/optout\.
>>
>>
>> --
>> You received this message because you are subscribed to the Google Groups "Bokeh Discussion - Public" group.
>> To unsubscribe from this group and stop receiving emails from it, send an email to bo...@continuum.io.
>> To post to this group, send email to bo...@continuum.io.
>> To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/b1e378cd-2e32-41ae-985a-f2e0de92a534%40continuum.io\.
>> For more options, visit https://groups.google.com/a/continuum.io/d/optout\.
>

--
You received this message because you are subscribed to the Google Groups "Bokeh Discussion - Public" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/e049b9cc-d6db-4dca-ba66-6dea5718b174%40continuum.io\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.