bokeh.charts.Scatter: problems with size, alpha, and hover

I started off
creating a Scatter plot for a short lesson using a Bokeh plot
constructed using the bokeh.plotting.circle
module but realized, as it grew in complexity, that I should try
to use bokeh.charts.Scatter
instead. However I then ended up with no alpha, no size, and an
inability to figure out how to construct the HoverTool
correctly. I’m hoping this is mostly down to my own poor
searching/reading of the docs, but at this point I need to ask
here how to move forwards. Here’s my current code:

from bokeh.charts import Scatter
from bokeh.io import output_notebook, show
from bokeh.models import ColumnDataSource, HoverTool
output_notebook()
hover = HoverTool(tooltips=[
("Make", "@Make"    ),
("Model", "@Model"    ),
("$", "@MSRP"
)
])
TOOLS = 'box_zoom,box_select,resize,reset,pan'.split(',') + [hover]
cars['scaledhp'] = cars['Horsepower'] /20
x, y = 'EngineSize', 'MPG_Highway'
p = Scatter(cars, x="EngineSize", y="MPG_Highway", color='Type'            ,
height=500, width=700            ,
title="Cars Data Set: {x} vs. {y}"            .format(x=x, y=y),
tools=TOOLS, legend='top_right'            ,
background_fill_alpha=0.1
)
_ = show(p)

    And here is the plot

I get:

    My hover events,

however, give me:

    So the three things

I’m looking to solve:

  1.         Setting marker size based on some dimension of
    

the data set.

  1.         Setting alpha channel — ideally based on some
    

dimension of the data set, but even a scalar value would be
OK.

  1. Making the HoverTool work.

     I’m using Bokeh
    

0.12.0 — ah, I just updated to 0.12.2 and the hover layout is
different but otherwise hover content is ??? and alpha doesn’t
appear to be set.

    The data file is a

SAS format version of the standard “cars” data set and is
imported as a Pandas DataFrame .
It is accessible here:

https://dl.dropboxusercontent.com/u/1561496/cars.sas7bdat

Regards,

Ian

···

Ian Stokes-Rees
Computational Scientist

Continuum Analytics
@ijstokes Twitter LinkedIn Github 617.942.0218

Hi,

···

I started off
creating a Scatter plot for a short lesson using a Bokeh plot
constructed using bokeh.plotting.circle
(plotting module) but realized, as it grew in complexity, that
I should try to use bokeh.charts.Scatter
instead (charts module). However I then ended up with no
alpha, no size, and an inability to figure out how to
construct the HoverTool
correctly. I’m hoping this is mostly down to my own poor
searching/reading of the docs, but at this point I need to ask
here how to move forwards. Here’s my current code:

from bokeh.charts import Scatter
from bokeh.io import output_notebook, show
from bokeh.models import ColumnDataSource, HoverTool
output_notebook()
hover = HoverTool(tooltips=[
("Make", "@Make"    ),
("Model", "@Model"    ),
("$", "@MSRP"
)
])
TOOLS = 'box_zoom,box_select,resize,reset,pan'.split(',') + [hover]
cars['scaledhp'] = cars['Horsepower'] /20
x, y = 'EngineSize', 'MPG_Highway'
p = Scatter(cars, x="EngineSize", y="MPG_Highway", color='Type'            ,
height=500, width=700            ,
title="Cars Data Set: {x} vs. {y}"            .format(x=x, y=y),
tools=TOOLS, legend='top_right'            ,
background_fill_alpha=0.1
)
_ = show(p)

      And here is the

plot I get:

      My hover events,

however, give me:

      So the three

things I’m looking to solve:

  1.           Setting marker size based on some
    

dimension of the data set.

  1.           Setting alpha channel — ideally based on
    

some dimension of the data set, but even a scalar value
would be OK. I realize that background_fill_alpha is
probably for the plot transparency for overlaying on some
other background, not for marker transparency: but I was
grasping at anything I could find.

  1.           Making the HoverTool work.  I did try
    

putting the cars DataFrame into a ColumnDataSource but
that didn’t have any effect.

      I’m using Bokeh

0.12.0 — ah, I just updated to 0.12.2 and the hover layout is
different but otherwise hover content is ??? and alpha doesn’t
appear to be set.

      The data file is a

SAS format version of the standard “cars” data set and is
imported as a Pandas DataFrame .
It is accessible here:

https://dl.dropboxusercontent.com/u/1561496/cars.sas7bdat

Regards,

Ian


Ian Stokes-Rees
Computational Scientist

Continuum Analytics
@ijstokes Twitter LinkedIn Github 617.942.0218

Hi,

A few comments:

Scatter does not currently support setting size except as a single value. Same for alpha. There is an open pull request to make it possible to add “extra” columns for use by Hover tools, but it is still WIP and not yet merged:

[https://github.com/bokeh/bokeh/pull/5037](https://github.com/bokeh/bokeh/pull/5037)

However, some recent work around “computed columns” and legend selection has made this kind of chart much simpler to make from bokeh.plotting, and that is what I recommend. The capabilities are very new, so they need both more and better documentation and examples, as well as some syntax conveniences to make it easier to spell. But here is an example you can emulate

from bokeh.plotting import figure
from [bokeh.io](http://bokeh.io) import output_file, show
from bokeh.models import CategoricalColorMapper, ColumnDataSource, LinearInterpolator

from bokeh.sampledata.iris import df

source = ColumnDataSource(df)

# There will be some convenience functions to make this simpler sooon
color_mapper = CategoricalColorMapper(factors=list(df.species.unique()),
                                      palette=["red", "green", "blue"])

size_scale = LinearInterpolator(x=[min(df.sepal_width), max(df.sepal_width)],
                                y=[4, 16])

alpha_scale = LinearInterpolator(x=[min(df.sepal_length), max(df.sepal_length)],
                                 y=[0.3, 0.8])

p = figure()
p.circle('petal_width', 'petal_length', legend="species", source=source,

         # compute all these properties in client, based on the data
         color=dict(field='species', transform=color_mapper),
         size=dict(field='sepal_width', transform=size_scale),
         alpha=dict(field='sepal_length', transform=alpha_scale))

p.legend.location = "top_left"

output_file("iris.html")

show(p)

This code generates the following bubble chart with size, color, and alpha all mapped from the data:

As mentioned, some of the syntax is a bit clunky, there will be some convenience functions, etc to make it even simpler (but the above version will always be valid as well). For some of the features, you’ll need a 0.12.3 dev build (or wait for 0.12.3 this week).

Thanks,

Bryan

···

On Sep 19, 2016, at 7:29 AM, Ian Stokes Rees [email protected] wrote:

Hi,

I started off creating a Scatter plot for a short lesson using a Bokeh plot constructed using bokeh.plotting.circle (plotting module) but realized, as it grew in complexity, that I should try to use bokeh.charts.Scatter instead (charts module). However I then ended up with no alpha, no size, and an inability to figure out how to construct the HoverTool correctly. I’m hoping this is mostly down to my own poor searching/reading of the docs, but at this point I need to ask here how to move forwards. Here’s my current code:

from bokeh.charts import
Scatter

from bokeh.io import
output_notebook, show

from bokeh.models import
ColumnDataSource, HoverTool

output_notebook()

hover = HoverTool(tooltips=[

(

“Make”, “@Make
),

(

“Model”, “@Model
),

(

“$”, “@MSRP
)

])

TOOLS =

‘box_zoom,box_select,resize,reset,pan’.split(’,’
) + [hover]

cars[

‘scaledhp’] = cars[‘Horsepower’] /20

x, y =

‘EngineSize’, ‘MPG_Highway’

p = Scatter(cars, x=

“EngineSize”, y=“MPG_Highway”, color=‘Type’
,

height=

500, width=700
,

title=

“Cars Data Set: {x} vs. {y}”
.format(x=x, y=y),

tools=TOOLS, legend=

‘top_right’
,

background_fill_alpha=

0.1
)

_ = show§

And here is the plot I get:

My hover events, however, give me:

So the three things I’m looking to solve:

• Setting marker size based on some dimension of the data set.

• Setting alpha channel — ideally based on some dimension of the data set, but even a scalar value would be OK. I realize that background_fill_alpha is probably for the plot transparency for overlaying on some other background, not for marker transparency: but I was grasping at anything I could find.

• Making the HoverTool work. I did try putting the cars DataFrame into a ColumnDataSource but that didn’t have any effect.

I’m using Bokeh 0.12.0 — ah, I just updated to 0.12.2 and the hover layout is different but otherwise hover content is ??? and alpha doesn’t appear to be set.

The data file is a SAS format version of the standard “cars” data set and is imported as a Pandas DataFrame. It is accessible here:

https://dl.dropboxusercontent.com/u/1561496/cars.sas7bdat

Regards,

Ian

Ian Stokes-Rees
Computational Scientist

@ijstokes 617.942.0218


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/93fe3941-564d-3770-ddfd-5ffd7e0ef224%40continuum.io.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.

About the hover tool.

Looks like cars is a pandas dataframe and you are passing cars to Scatter(). You need to use a ColumnDataSource to feed the drawings, otherwise HoverTool will not be able to pull any data.

And I am not sure how to use a ColumnDataSource with Scatter, but you here is a scatterplot built with the plotting interface and with a working hover tool.

from bokeh.plotting import figure
from bokeh.io import show, output_file
from bokeh.models import ColumnDataSource, HoverTool
import pandas
output_file(“hovering.html”)
p=figure()
hover=HoverTool(tooltips=[(“X”,"@x")])
p.add_tools(hover)
df=pandas.DataFrame(dict(x=[1,2,3],y=[4,5,6]))
cds=ColumnDataSource(df)
p.circle(x=“x”,y=“y”,size=14,source=cds)
show§

``

···

On Monday, September 19, 2016 at 2:29:35 PM UTC+2, Ian Stokes-Rees wrote:

Hi,

      I started off

creating a Scatter plot for a short lesson using a Bokeh plot
constructed using bokeh.plotting.circle
(plotting module) but realized, as it grew in complexity, that
I should try to use bokeh.charts.Scatter
instead (charts module). However I then ended up with no
alpha, no size, and an inability to figure out how to
construct the HoverTool
correctly. I’m hoping this is mostly down to my own poor
searching/reading of the docs, but at this point I need to ask
here how to move forwards. Here’s my current code:

from bokeh.charts import Scatter
from [bokeh.io](http://bokeh.io) import output_notebook, show
from bokeh.models import ColumnDataSource, HoverTool
output_notebook()
hover = HoverTool(tooltips=[
("Make", "@Make"    ),
("Model", "@Model"    ),
("$", "@MSRP"
)
])
TOOLS = 'box_zoom,box_select,resize,reset,pan'.split(',') + [hover]
cars['scaledhp'] = cars['Horsepower'] /20
x, y = 'EngineSize', 'MPG_Highway'
p = Scatter(cars, x="EngineSize", y="MPG_Highway", color='Type'            ,
height=500, width=700            ,
title="Cars Data Set: {x} vs. {y}"            .format(x=x, y=y),
tools=TOOLS, legend='top_right'            ,
background_fill_alpha=0.1
)
_ = show(p)

      And here is the

plot I get:

      My hover events,

however, give me:

      So the three

things I’m looking to solve:

  1.           Setting marker size based on some
    

dimension of the data set.

  1.           Setting alpha channel — ideally based on
    

some dimension of the data set, but even a scalar value
would be OK. I realize that background_fill_alpha is
probably for the plot transparency for overlaying on some
other background, not for marker transparency: but I was
grasping at anything I could find.

  1.           Making the HoverTool work.  I did try
    

putting the cars DataFrame into a ColumnDataSource but
that didn’t have any effect.

      I’m using Bokeh

0.12.0 — ah, I just updated to 0.12.2 and the hover layout is
different but otherwise hover content is ??? and alpha doesn’t
appear to be set.

      The data file is a

SAS format version of the standard “cars” data set and is
imported as a Pandas DataFrame .
It is accessible here:

https://dl.dropboxusercontent.com/u/1561496/cars.sas7bdat

Regards,

Ian


Ian Stokes-Rees
Computational Scientist

Continuum Analytics
@ijstokes Twitter LinkedIn Github 617.942.0218

Sorry, I botched a last minute change to an import, and forgot to add a hover tool. Here is the full corrected code:

    from bokeh.plotting import figure
    from bokeh.io import output_file, show
    from bokeh.models import CategoricalColorMapper, ColumnDataSource, HoverTool, LinearInterpolator

    from bokeh.sampledata.iris import flowers as df

    source = ColumnDataSource(df)

    color_mapper = CategoricalColorMapper(factors=list(df.species.unique()),
                                          palette=["red", "green", "blue"])

    size_scale = LinearInterpolator(x=[min(df.sepal_width), max(df.sepal_width)],
                                    y=[4, 16])

    alpha_scale = LinearInterpolator(x=[min(df.sepal_length), max(df.sepal_length)],
                                     y=[0.3, 0.8])

    p = figure(tools=[HoverTool(tooltips=dict(species="@species"))])
    p.circle('petal_width', 'petal_length', legend="species", source=source,

             # compute all these properties in client, based on the data
             color=dict(field='species', transform=color_mapper),
             size=dict(field='sepal_width', transform=size_scale),
             alpha=dict(field='sepal_length', transform=alpha_scale))

    p.legend.location = "top_left"

    output_file("iris.html")

    show(p)

Thanks,

Bryan

···

On Sep 19, 2016, at 8:44 AM, Bryan Van de Ven <[email protected]> wrote:

Hi,

A few comments:

Scatter does not currently support setting size except as a single value. Same for alpha. There is an open pull request to make it possible to add "extra" columns for use by Hover tools, but it is still WIP and not yet merged:

  https://github.com/bokeh/bokeh/pull/5037

However, some recent work around "computed columns" and legend selection has made this kind of chart much simpler to make from bokeh.plotting, and that is what I recommend. The capabilities are very new, so they need both more and better documentation and examples, as well as some syntax conveniences to make it easier to spell. But here is an example you can emulate

    from bokeh.plotting import figure
    from bokeh.io import output_file, show
    from bokeh.models import CategoricalColorMapper, ColumnDataSource, LinearInterpolator

    from bokeh.sampledata.iris import df

    source = ColumnDataSource(df)

    # There will be some convenience functions to make this simpler sooon
    color_mapper = CategoricalColorMapper(factors=list(df.species.unique()),
                                          palette=["red", "green", "blue"])

    size_scale = LinearInterpolator(x=[min(df.sepal_width), max(df.sepal_width)],
                                    y=[4, 16])

    alpha_scale = LinearInterpolator(x=[min(df.sepal_length), max(df.sepal_length)],
                                     y=[0.3, 0.8])

    p = figure()
    p.circle('petal_width', 'petal_length', legend="species", source=source,

             # compute all these properties in client, based on the data
             color=dict(field='species', transform=color_mapper),
             size=dict(field='sepal_width', transform=size_scale),
             alpha=dict(field='sepal_length', transform=alpha_scale))

    p.legend.location = "top_left"

    output_file("iris.html")

    show(p)

This code generates the following bubble chart with size, color, and alpha all mapped from the data:

<Screen Shot 2016-09-19 at 8.41.27 AM.png>

As mentioned, some of the syntax is a bit clunky, there will be some convenience functions, etc to make it even simpler (but the above version will always be valid as well). For some of the features, you'll need a 0.12.3 dev build (or wait for 0.12.3 this week).

Thanks,

Bryan

On Sep 19, 2016, at 7:29 AM, Ian Stokes Rees <[email protected]> wrote:

Hi,

I started off creating a Scatter plot for a short lesson using a Bokeh plot constructed using bokeh.plotting.circle (plotting module) but realized, as it grew in complexity, that I should try to use bokeh.charts.Scatter instead (charts module). However I then ended up with no alpha, no size, and an inability to figure out how to construct the HoverTool correctly. I’m hoping this is mostly down to my own poor searching/reading of the docs, but at this point I need to ask here how to move forwards. Here’s my current code:

from bokeh.charts import
Scatter

from bokeh.io import
output_notebook, show

from bokeh.models import
ColumnDataSource, HoverTool

output_notebook()

hover = HoverTool(tooltips=[
    (
"Make", "@Make"
),
    (
"Model", "@Model"
),
    (
"$", "@MSRP"
)
])

TOOLS =
'box_zoom,box_select,resize,reset,pan'.split(','
) + [hover]
cars[
'scaledhp'] = cars['Horsepower'] /20

x, y =
'EngineSize', 'MPG_Highway'

p = Scatter(cars, x=
"EngineSize", y="MPG_Highway", color='Type'
,
            height=
500, width=700
,
            title=
"Cars Data Set: {x} vs. {y}"
.format(x=x, y=y),
            tools=TOOLS, legend=
'top_right'
,
            background_fill_alpha=
0.1
)

_ = show(p)

And here is the plot I get:

<Mail Attachment.png>

My hover events, however, give me:

<Mail Attachment.png>

So the three things I’m looking to solve:

  • Setting marker size based on some dimension of the data set.
  • Setting alpha channel — ideally based on some dimension of the data set, but even a scalar value would be OK. I realize that background_fill_alpha is probably for the plot transparency for overlaying on some other background, not for marker transparency: but I was grasping at anything I could find.
  • Making the HoverTool work. I did try putting the `cars` DataFrame into a ColumnDataSource but that didn't have any effect.
I’m using Bokeh 0.12.0 — ah, I just updated to 0.12.2 and the hover layout is different but otherwise hover content is ??? and alpha doesn’t appear to be set.

The data file is a SAS format version of the standard “cars” data set and is imported as a Pandas DataFrame. It is accessible here:

https://dl.dropboxusercontent.com/u/1561496/cars.sas7bdat

Regards,

Ian

Ian Stokes-Rees
Computational Scientist

@ijstokes 617.942.0218

--
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/93fe3941-564d-3770-ddfd-5ffd7e0ef224%40continuum.io.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.

Bryan and Adi,
thanks for your quick responses.

Bryan, the plotting
example you provided is basically what I started with. It is
fine for me to go back to that (and I’ll use the 0.12.3dev). The
convenience functions will be great. I really was looking for
the smallest possible piece of code to create the scatter plot,
which is what led me to the charting
approach: it almost got me there, but I need hover and marker
sizing (alpha less critical) so I’ll head back to plotting.

Adi, the charting
sub-module will take a pandas.DataFrame
for many things that previously (or otherwise, such as in the plotting
sub-module) require aColumnDataSource. It just seems likechartingdoesn't completely pull fields from a DataFrame the wayplottingdoes for aColumnDataSource`.

Regards,

Ian

···

On 9/19/16 9:57 AM, Adi wrote:

About the hover tool.

Looks like cars is a pandas dataframe and you
are passing cars to Scatter(). You need
to use a ColumnDataSource to feed the drawings, otherwise
HoverTool will not be able to pull any data.

          And I am not sure how to use a ColumnDataSource with

Scatter, but you here is a scatterplot built with the
plotting interface and with a working hover tool.

Hi-- I’m interested in this issue too, but unfortunately the posted suggestion doesn’t quite work for me. This is because I’d like to use the interactive legend functionality, but when I add p.legend.click_policy='hide' to the example code here, it turns on & off all the points at once, instead of one label at a time.

Is there something else I have to add manually to make the interactive legend functionality work properly, before the improvements that will make this easier to use the Scatter chart are completed?

Thanks,

Tim

···

On Monday, September 19, 2016 at 8:29:35 AM UTC-4, Ian Stokes-Rees wrote:

Hi,

      I started off

creating a Scatter plot for a short lesson using a Bokeh plot
constructed using bokeh.plotting.circle
(plotting module) but realized, as it grew in complexity, that
I should try to use bokeh.charts.Scatter
instead (charts module). However I then ended up with no
alpha, no size, and an inability to figure out how to
construct the HoverTool
correctly. I’m hoping this is mostly down to my own poor
searching/reading of the docs, but at this point I need to ask
here how to move forwards. Here’s my current code:

from bokeh.charts import Scatter
from [bokeh.io](http://bokeh.io) import output_notebook, show
from bokeh.models import ColumnDataSource, HoverTool
output_notebook()
hover = HoverTool(tooltips=[
("Make", "@Make"    ),
("Model", "@Model"    ),
("$", "@MSRP"
)
])
TOOLS = 'box_zoom,box_select,resize,reset,pan'.split(',') + [hover]
cars['scaledhp'] = cars['Horsepower'] /20
x, y = 'EngineSize', 'MPG_Highway'
p = Scatter(cars, x="EngineSize", y="MPG_Highway", color='Type'            ,
height=500, width=700            ,
title="Cars Data Set: {x} vs. {y}"            .format(x=x, y=y),
tools=TOOLS, legend='top_right'            ,
background_fill_alpha=0.1
)
_ = show(p)

      And here is the

plot I get:

      My hover events,

however, give me:

      So the three

things I’m looking to solve:

  1.           Setting marker size based on some
    

dimension of the data set.

  1.           Setting alpha channel — ideally based on
    

some dimension of the data set, but even a scalar value
would be OK. I realize that background_fill_alpha is
probably for the plot transparency for overlaying on some
other background, not for marker transparency: but I was
grasping at anything I could find.

  1.           Making the HoverTool work.  I did try
    

putting the cars DataFrame into a ColumnDataSource but
that didn’t have any effect.

      I’m using Bokeh

0.12.0 — ah, I just updated to 0.12.2 and the hover layout is
different but otherwise hover content is ??? and alpha doesn’t
appear to be set.

      The data file is a

SAS format version of the standard “cars” data set and is
imported as a Pandas DataFrame .
It is accessible here:

https://dl.dropboxusercontent.com/u/1561496/cars.sas7bdat

Regards,

Ian


Ian Stokes-Rees
Computational Scientist

Continuum Analytics
@ijstokes Twitter LinkedIn Github 617.942.0218

Hi,

I should probably say a few things at this point. The first is that the bokeh.charts API has been moved to a new separate project “bkcharts”. There will be a compatibility shim that keeps existing code working until Bokeh 1.0 is released later this year. Part of the motivation is to pare down the core library for long term stability and maintainability. But it’s also true that none of the original bokeh.charts contributors are working on it anymore, and it is effectively unmaintained right now. I would be happy to turn over the maintenance to any interested party (it is a pure python project with few dependencies so should hopefully have a shallow learning curve to get started on).

Second, I’d encourage you to just use the bokeh.plotting API. It is stable, well-tested and understood, and offers far more control and customizability. Accomplishing the kind of plot you have is only 2-3 more lines of code:

(This uses the built-in “autompg” sample data set instead of your “cars” data set but is fairly equivalent)

Once the “Filterable Column Data Source” PR:

[https://github.com/bokeh/bokeh/pull/5982](https://github.com/bokeh/bokeh/pull/5982)

is merged, this kind of grouping will become even easier from the bokeh.plotting API.

Finally, if you do want to use an actively supported very-high-level API, the Holoviews project (http://holoviews.org) has the backing of Continuum Analytics and will be promoted as the go-to for an extremely minimal data-centric API that ties together both Bokeh and DataShader and automatic interactivity. Look for a tutorial on the topic at this years SciPy conference:

[https://scipy2017.scipy.org/ehome/220975/493418/](https://scipy2017.scipy.org/ehome/220975/493418/)

Thanks,

Bryan

···

On May 26, 2017, at 13:17, Tim Morton [email protected] wrote:

Hi-- I’m interested in this issue too, but unfortunately the posted suggestion doesn’t quite work for me. This is because I’d like to use the interactive legend functionality, but when I add p.legend.click_policy='hide' to the example code here, it turns on & off all the points at once, instead of one label at a time.

Is there something else I have to add manually to make the interactive legend functionality work properly, before the improvements that will make this easier to use the Scatter chart are completed?

Thanks,
Tim

On Monday, September 19, 2016 at 8:29:35 AM UTC-4, Ian Stokes-Rees wrote:
Hi,

I started off creating a Scatter plot for a short lesson using a Bokeh plot constructed using bokeh.plotting.circle (plotting module) but realized, as it grew in complexity, that I should try to use bokeh.charts.Scatter instead (charts module). However I then ended up with no alpha, no size, and an inability to figure out how to construct the HoverTool correctly. I’m hoping this is mostly down to my own poor searching/reading of the docs, but at this point I need to ask here how to move forwards. Here’s my current code:

from bokeh.charts import
Scatter

from bokeh.io import
output_notebook, show

from bokeh.models import
ColumnDataSource, HoverTool

output_notebook()

hover = HoverTool(tooltips=[

(

“Make”, “@Make
),

(

“Model”, “@Model
),

(

“$”, “@MSRP
)

])

TOOLS =

‘box_zoom,box_select,resize,reset,pan’.split(’,’
) + [hover]

cars[

‘scaledhp’] = cars[‘Horsepower’] /20

x, y =

‘EngineSize’, ‘MPG_Highway’

p = Scatter(cars, x=

“EngineSize”, y=“MPG_Highway”, color=‘Type’
,

height=

500, width=700
,

title=

“Cars Data Set: {x} vs. {y}”
.format(x=x, y=y),

tools=TOOLS, legend=

‘top_right’
,

background_fill_alpha=

0.1
)

_ = show§

And here is the plot I get:

My hover events, however, give me:

So the three things I’m looking to solve:

• Setting marker size based on some dimension of the data set.

• Setting alpha channel — ideally based on some dimension of the data set, but even a scalar value would be OK. I realize that background_fill_alpha is probably for the plot transparency for overlaying on some other background, not for marker transparency: but I was grasping at anything I could find.

• Making the HoverTool work. I did try putting the cars DataFrame into a ColumnDataSource but that didn’t have any effect.

I’m using Bokeh 0.12.0 — ah, I just updated to 0.12.2 and the hover layout is different but otherwise hover content is ??? and alpha doesn’t appear to be set.

The data file is a SAS format version of the standard “cars” data set and is imported as a Pandas DataFrame. It is accessible here:

https://dl.dropboxusercontent.com/u/1561496/cars.sas7bdat

Regards,

Ian

Ian Stokes-Rees
Computational Scientist

@ijstokes 617.942.0218


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/f32fb619-b0b2-475e-90ae-2a3534122e5d%40continuum.io.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.

So I’m gathering that to achieve the same effect as applying different markers to a high level Scatter plot I’d need to invoke a series of plot commands for the different shapes I wanted to partition my data by. I think the marker variability that Scatter offered was very expressive like ggplot. I should be able to work with the plotting API however, just need to slice my dataframe to the appropriate markers…
p.circle
p.triangle
p.inverted_triangle
…etc

``

···

On Friday, May 26, 2017 at 5:52:00 PM UTC-7, Bryan Van de ven wrote:

Hi,

I should probably say a few things at this point. The first is that the bokeh.charts API has been moved to a new separate project “bkcharts”. There will be a compatibility shim that keeps existing code working until Bokeh 1.0 is released later this year. Part of the motivation is to pare down the core library for long term stability and maintainability. But it’s also true that none of the original bokeh.charts contributors are working on it anymore, and it is effectively unmaintained right now. I would be happy to turn over the maintenance to any interested party (it is a pure python project with few dependencies so should hopefully have a shallow learning curve to get started on).

Second, I’d encourage you to just use the bokeh.plotting API. It is stable, well-tested and understood, and offers far more control and customizability. Accomplishing the kind of plot you have is only 2-3 more lines of code:

(This uses the built-in “autompg” sample data set instead of your “cars” data set but is fairly equivalent)

Once the “Filterable Column Data Source” PR:

https://github.com/bokeh/bokeh/pull/5982

is merged, this kind of grouping will become even easier from the bokeh.plotting API.

Finally, if you do want to use an actively supported very-high-level API, the Holoviews project (http://holoviews.org) has the backing of Continuum Analytics and will be promoted as the go-to for an extremely minimal data-centric API that ties together both Bokeh and DataShader and automatic interactivity. Look for a tutorial on the topic at this years SciPy conference:

https://scipy2017.scipy.org/ehome/220975/493418/

Thanks,

Bryan

Scatter

output_notebook, show

ColumnDataSource, HoverTool

output_notebook()

hover = HoverTool(tooltips=[

(

),

(

),

(

)

])

TOOLS =

) + [hover]

cars[

x, y =

p = Scatter(cars, x=

,

height=

,

title=

.format(x=x, y=y),

tools=TOOLS, legend=

,

background_fill_alpha=

)

_ = show§

• Setting marker size based on some dimension of the data set.
• Setting alpha channel — ideally based on some dimension of the data set, but even a scalar value would be OK.  I realize that background_fill_alpha is probably for the plot transparency for overlaying on some other background, not for marker transparency: but I was grasping at anything I could find.
• Making the HoverTool work.  I did try putting the `cars` DataFrame into a ColumnDataSource but that didn't have any effect.

On May 26, 2017, at 13:17, Tim Morton [email protected] wrote:

Hi-- I’m interested in this issue too, but unfortunately the posted suggestion doesn’t quite work for me. This is because I’d like to use the interactive legend functionality, but when I add p.legend.click_policy='hide' to the example code here, it turns on & off all the points at once, instead of one label at a time.

Is there something else I have to add manually to make the interactive legend functionality work properly, before the improvements that will make this easier to use the Scatter chart are completed?

Thanks,
Tim

On Monday, September 19, 2016 at 8:29:35 AM UTC-4, Ian Stokes-Rees wrote:
Hi,

I started off creating a Scatter plot for a short lesson using a Bokeh plot constructed using bokeh.plotting.circle (plotting module) but realized, as it grew in complexity, that I should try to use bokeh.charts.Scatter instead (charts module). However I then ended up with no alpha, no size, and an inability to figure out how to construct the HoverTool correctly. I’m hoping this is mostly down to my own poor searching/reading of the docs, but at this point I need to ask here how to move forwards. Here’s my current code:

from bokeh.charts import
from bokeh.io import
from bokeh.models import"Make", “@Make”“Model”, “@Model”"$", “@MSRP”‘box_zoom,box_select,resize,reset,pan’.split(’,’‘scaledhp’] = cars[‘Horsepower’] /20’EngineSize’, ‘MPG_Highway’“EngineSize”, y=“MPG_Highway”, color='Type’500, width=700"Cars Data Set: {x} vs. {y}"'top_right’0.1
And here is the plot I get:

My hover events, however, give me:

So the three things I’m looking to solve:

I’m using Bokeh 0.12.0 — ah, I just updated to 0.12.2 and the hover layout is different but otherwise hover content is ??? and alpha doesn’t appear to be set.

The data file is a SAS format version of the standard “cars” data set and is imported as a Pandas DataFrame. It is accessible here:

https://dl.dropboxusercontent.com/u/1561496/cars.sas7bdat

Regards,

Ian

Ian Stokes-Rees
Computational Scientist

@ijstokes 617.942.0218


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/f32fb619-b0b2-475e-90ae-2a3534122e5d%40continuum.io.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.