Hi,
My suspicion is that the interaction of transforms with "groupby" legends has never been explicitly considered, and so probably does not do anything desirable. A GH issue to request making these two features work better would be appropriate. As a workaround in the mean time, I can only suggest colormapping the data yourself in python (instead of using factor_cmap) and sending the colors as their own column.
Thanks,
Bryan
···
On Apr 14, 2018, at 11:08, [email protected] wrote:
I've created a bokeh app that displays birth data at the county and state levels between 1990 and 2007. The issue is that the legend I've defined doesn't display information for all of the factors in the specified column ('race'). Here is my source code:
from bokeh.io import output_notebook, output_file, show,
curdocfrom bokeh.plotting import
figurefrom bokeh.models import ColumnDataSource, HoverTool, Slider, CDSView, BooleanFilter, NumeralTickFormatter
from bokeh.palettes import Spectral as
palettefrom bokeh.layouts import widgetbox, row,
columnfrom bokeh.transform import
factor_cmapsource
= ColumnDataSource(data=dict(final_merge.reset_index()))races
= ['black', 'hispanic', 'other', 'white']def set_bools(yr, lvl):
return [True if (year == yr) and (level == lvl) else False for year, level in zip(source.data['year'], source.data['level'])]
def set_views(boolean):
return CDSView(source=source, filters=[BooleanFilter(boolean)])
p1
= figure(x_axis_label = 'Number of Births', y_axis_label = 'Percentage of Births',title
='Harris County Births 1990-2007', x_range=(0, x_max + 10000), y_range=(0, y_max + 5))p2
= figure(x_axis_label = 'Number of Births', y_axis_label = 'Percentage of Births',title
='Texas Births 1990-2007', x_range=(0, x_max + 10000), y_range=(0, y_max + 5))bools1
, bools2 = set_bools(1990, 'county'), set_bools(1990, 'state')view1
, view2 = set_views(bools1), set_views(bools2)c1
= p1.circle(x='total', y='percent', size=10, color=factor_cmap('race', palette[4], races), legend='race', source=source)
c2 = p2.circle(x='total', y='percent', size=10, color=factor_cmap('race', palette[4], races), legend='race', source=source)c1
.view, c2.view = view1,
view2p1
.legend.location = 'bottom_right'p2
.legend.location = 'bottom_right'hover1
= HoverTool(tooltips=[('Total Births','@total'),('Percentage of All Births','@percent%')])hover2
= HoverTool(tooltips=[('Total Births','@total'),('Percentage of All Births','@percent%')])p1
.add_tools(hover1)p2
.add_tools(hover2)p1
.xaxis[0].formatter = NumeralTickFormatter(format="0,")p2
.xaxis[0].formatter = NumeralTickFormatter(format="0,")def update_plots(attr, old, new):
time
= slider.
value
bools1
, bools2 = set_bools(time, 'county'), set_bools(time, 'state')view1
, view2 = set_views(bools1), set_views(bools2)c1
.view, c2.view = view1,
view2slider
= Slider(start=1990, end=2007, step=1, value=1990, title='Year')slider
.on_change('value', update_plots)layout
= row(widgetbox(slider), p1, p2)curdoc
().add_root(layout)I suspect that the error may have to do with the views I've defined because the legend is correctly mapped when I remove them, but obviously the points are displayed incorrectly. When I view the plots, the glyph for 'black' is mapped correctly to the legend, but the other categories ('hispanic', 'white', 'other') appear as black dots in the legend although they appear correctly on the plot. Thanks in advance for the help!
--
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/5c9cccfe-a519-4fd0-a1e2-bff3f9544b14%40continuum.io\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.