Specify Histogram Bins

I have a list of Pandas dataframes stored in dfs and I am plotting a grid (three columns) of histograms:

hists = [Histogram(dfs[colname],

title=colname,

bins=20,

) for colname in dfs.columns]

for h in hists:

h.x_range = Range1d(-20, 20)

ncol = 3

hists = [hists[i:i+ncol] for i in range(0,len(hists),ncol)]

p = gridplot(hists)

However, I’ve noticed that while the number of bins (20) are the same in all of the plots, the width and location of each bin is inconsistent from plot to plot. I believe this is because each plot has a different x_range and the bins are generated using some optimized method. Instead, I’d like to be able to specify the width and location of each bin, maybe in the form of a list of tuples or something:

bins = [(-20, -15), (-15, -10), (-10, -5), (-5, 0), (0, 5), (5, 10), (10, 15), (15, 20)]

Also, notice that I’ve set my x_range to (-20, 20) so I know my min/max are from all of the plots.

Hi,

You can’t specify the width and location of the bins with Histogram chart. I suggest you to add a github issue with this feature request so we can have a discussion and better understanding of what is needed and if we can plan on doing it. As a side note, we have many improvements in mind for the Charts interface and one of these is to make it possible (and hopefully easy) to specify custom binning function to Histogram. This MAY related to your needs.

Thanks

Fabio

···

On Tue, Dec 22, 2015 at 9:16 AM, [email protected] wrote:

I have a list of Pandas dataframes stored in dfs and I am plotting a grid (three columns) of histograms:

hists = [Histogram(dfs[colname],

title=colname,

bins=20,

) for colname in dfs.columns]

for h in hists:

h.x_range = Range1d(-20, 20)

ncol = 3

hists = [hists[i:i+ncol] for i in range(0,len(hists),ncol)]

p = gridplot(hists)

However, I’ve noticed that while the number of bins (20) are the same in all of the plots, the width and location of each bin is inconsistent from plot to plot. I believe this is because each plot has a different x_range and the bins are generated using some optimized method. Instead, I’d like to be able to specify the width and location of each bin, maybe in the form of a list of tuples or something:

bins = [(-20, -15), (-15, -10), (-10, -5), (-5, 0), (0, 5), (5, 10), (10, 15), (15, 20)]

Also, notice that I’ve set my x_range to (-20, 20) so I know my min/max are from all of the plots.

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/72b5fc11-d413-419f-9a7e-dc0554e643f1%40continuum.io.

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

Fabio Pliger

Senior Software Engineer, Bokeh

Is there a way to accomplish this with bar charts instead?

···

On Tuesday, December 22, 2015 at 12:22:00 PM UTC-5, Fabio Pliger wrote:

Hi,

You can’t specify the width and location of the bins with Histogram chart. I suggest you to add a github issue with this feature request so we can have a discussion and better understanding of what is needed and if we can plan on doing it. As a side note, we have many improvements in mind for the Charts interface and one of these is to make it possible (and hopefully easy) to specify custom binning function to Histogram. This MAY related to your needs.

Thanks

Fabio

On Tue, Dec 22, 2015 at 9:16 AM, [email protected] wrote:

I have a list of Pandas dataframes stored in dfs and I am plotting a grid (three columns) of histograms:

hists = [Histogram(dfs[colname],

title=colname,

bins=20,

) for colname in dfs.columns]

for h in hists:

h.x_range = Range1d(-20, 20)

ncol = 3

hists = [hists[i:i+ncol] for i in range(0,len(hists),ncol)]

p = gridplot(hists)

However, I’ve noticed that while the number of bins (20) are the same in all of the plots, the width and location of each bin is inconsistent from plot to plot. I believe this is because each plot has a different x_range and the bins are generated using some optimized method. Instead, I’d like to be able to specify the width and location of each bin, maybe in the form of a list of tuples or something:

bins = [(-20, -15), (-15, -10), (-10, -5), (-5, 0), (0, 5), (5, 10), (10, 15), (15, 20)]

Also, notice that I’ve set my x_range to (-20, 20) so I know my min/max are from all of the plots.

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/72b5fc11-d413-419f-9a7e-dc0554e643f1%40continuum.io.

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


Fabio Pliger

Senior Software Engineer, Bokeh

It may be possible, but probably would require some effort.

You would need to pre calculate the histogram values as one column, then the other column would have the categorical locations (labels) for where the bar should go. I’m not sure how it would handle the numerical data that represents the bar centers.

···

On Tuesday, December 22, 2015 at 11:33:17 AM UTC-6, [email protected] wrote:

Is there a way to accomplish this with bar charts instead?

On Tuesday, December 22, 2015 at 12:22:00 PM UTC-5, Fabio Pliger wrote:

Hi,

You can’t specify the width and location of the bins with Histogram chart. I suggest you to add a github issue with this feature request so we can have a discussion and better understanding of what is needed and if we can plan on doing it. As a side note, we have many improvements in mind for the Charts interface and one of these is to make it possible (and hopefully easy) to specify custom binning function to Histogram. This MAY related to your needs.

Thanks

Fabio

On Tue, Dec 22, 2015 at 9:16 AM, [email protected] wrote:

I have a list of Pandas dataframes stored in dfs and I am plotting a grid (three columns) of histograms:

hists = [Histogram(dfs[colname],

title=colname,

bins=20,

) for colname in dfs.columns]

for h in hists:

h.x_range = Range1d(-20, 20)

ncol = 3

hists = [hists[i:i+ncol] for i in range(0,len(hists),ncol)]

p = gridplot(hists)

However, I’ve noticed that while the number of bins (20) are the same in all of the plots, the width and location of each bin is inconsistent from plot to plot. I believe this is because each plot has a different x_range and the bins are generated using some optimized method. Instead, I’d like to be able to specify the width and location of each bin, maybe in the form of a list of tuples or something:

bins = [(-20, -15), (-15, -10), (-10, -5), (-5, 0), (0, 5), (5, 10), (10, 15), (15, 20)]

Also, notice that I’ve set my x_range to (-20, 20) so I know my min/max are from all of the plots.

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/72b5fc11-d413-419f-9a7e-dc0554e643f1%40continuum.io.

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


Fabio Pliger

Senior Software Engineer, Bokeh

So, I was able to use bar charts by first rounding my “label” column to the nearest integer and then doing:

p = Bar(dfs, label=‘rounded’, values=‘A’, agg=‘count’, legend=‘top_right’)

show§

However, the labeled column ‘rounded’ has values between (-11, 11) and I can’t find a way to set the axis to be between (-20, 20). Any suggestion?

···

On Tuesday, December 22, 2015 at 1:15:34 PM UTC-5, Nick Roth wrote:

It may be possible, but probably would require some effort.

You would need to pre calculate the histogram values as one column, then the other column would have the categorical locations (labels) for where the bar should go. I’m not sure how it would handle the numerical data that represents the bar centers.

On Tuesday, December 22, 2015 at 11:33:17 AM UTC-6, [email protected] wrote:

Is there a way to accomplish this with bar charts instead?

On Tuesday, December 22, 2015 at 12:22:00 PM UTC-5, Fabio Pliger wrote:

Hi,

You can’t specify the width and location of the bins with Histogram chart. I suggest you to add a github issue with this feature request so we can have a discussion and better understanding of what is needed and if we can plan on doing it. As a side note, we have many improvements in mind for the Charts interface and one of these is to make it possible (and hopefully easy) to specify custom binning function to Histogram. This MAY related to your needs.

Thanks

Fabio

On Tue, Dec 22, 2015 at 9:16 AM, [email protected] wrote:

I have a list of Pandas dataframes stored in dfs and I am plotting a grid (three columns) of histograms:

hists = [Histogram(dfs[colname],

title=colname,

bins=20,

) for colname in dfs.columns]

for h in hists:

h.x_range = Range1d(-20, 20)

ncol = 3

hists = [hists[i:i+ncol] for i in range(0,len(hists),ncol)]

p = gridplot(hists)

However, I’ve noticed that while the number of bins (20) are the same in all of the plots, the width and location of each bin is inconsistent from plot to plot. I believe this is because each plot has a different x_range and the bins are generated using some optimized method. Instead, I’d like to be able to specify the width and location of each bin, maybe in the form of a list of tuples or something:

bins = [(-20, -15), (-15, -10), (-10, -5), (-5, 0), (0, 5), (5, 10), (10, 15), (15, 20)]

Also, notice that I’ve set my x_range to (-20, 20) so I know my min/max are from all of the plots.

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/72b5fc11-d413-419f-9a7e-dc0554e643f1%40continuum.io.

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


Fabio Pliger

Senior Software Engineer, Bokeh