[bokeh.models] Line: Multiple variable colors and sizes

Hi everyone,

I’m running bokeh 12.5, using the bokeh.models interface to generate plots. One of my requirements is to have a Line-Glyph drawn with variable colors and sizes for each coordinate based on the data in a ColumnDataSource.

In short, I’m looking for the “Line”-equivalent of the following VBar-Glyph, with color and size interpolating between the coordinates:

glyph = VBar(x=field(“x”), top=field(“y”), fill_color=field(“color”), width=field(“size”))

I’ve attached an image showing an example of the Line I’d like to plot.

So far I’ve been running into a few problems when attempting to implement this.

  • The Line-Glyph does not support getting a field name instead of a fixed value for both the line_color and the line_width properties. This happends despite the documentation stating that those properties are ColorSpec (or NumberSpec respectively) and should work with field names. No error is thrown in Python, no Glyph is rendered in the HTML and the JS-Error-Console reports “Uncaught Error: attempted to retrieve property value for property without value specification”. The same approach works fine for VBar/Circle Glyphs, so I suspect that this is a bug/missing feature in the Line Glyph.
  • I’ve been looking into Patch/Patches and Segment-Glyphs in order to get the desired output. However, none of them will be able to support both the color/size interpolation I’m looking for.

Based on this, I have a few questions that I hope you can help me out with:

  1. Am I doing something wrong here and Lines actually support the features I’m looking for?
  2. If not, is any implementation for this feature already underway or already available in some feature branches?
  3. If this is also not the case, would you be open to a Pull Request with this feature? Provided that I can get some pointers on where to look for the respective modules (currently not familiar with the bokeh codebase), I’d definitely be willing to sit down and give implementing this a shot.

Thanks in advance,

MT

Hi,

There is nothing built in to Bokeh currently that would accomplish that sort of color interpolation along a line. You would have to create a custom extension to get that effect:

  http://bokeh.pydata.org/en/latest/docs/user_guide/extensions.html

Regarding the line_width and line_color properties, the primary reason it does not work is because Line only draws a single line (through multiple points). The line itself has nothing to vectorize, so supplying a field does not make sense. It's only defined as a ColorSpec because of some dumb and uninteresting technical reasons. In general it would have been more precise to complete separate the notion of geometry (the "points") from topology (any "connections" between points). It's possible to do this (see e.g. the VTK library) but it makes for a much more cumbersome API. Offering Line as its own primitive (even with the width/color API warts) makes for a much more approachable interface for the majority of users, most of the time.

Thanks,

Bryan

···

On May 28, 2017, at 04:59, [email protected] wrote:

Hi everyone,

I'm running bokeh 12.5, using the bokeh.models interface to generate plots. One of my requirements is to have a Line-Glyph drawn with variable colors and sizes for each coordinate based on the data in a ColumnDataSource.

In short, I'm looking for the "Line"-equivalent of the following VBar-Glyph, with color and size interpolating between the coordinates:

glyph = VBar(x=field("x"), top=field("y"), fill_color=field("color"), width=field("size"))

I've attached an image showing an example of the Line I'd like to plot.

So far I've been running into a few problems when attempting to implement this.

  • The Line-Glyph does not support getting a field name instead of a fixed value for both the line_color and the line_width properties. This happends despite the documentation stating that those properties are ColorSpec (or NumberSpec respectively) and should work with field names. No error is thrown in Python, no Glyph is rendered in the HTML and the JS-Error-Console reports "Uncaught Error: attempted to retrieve property value for property without value specification". The same approach works fine for VBar/Circle Glyphs, so I suspect that this is a bug/missing feature in the Line Glyph.
  • I've been looking into Patch/Patches and Segment-Glyphs in order to get the desired output. However, none of them will be able to support both the color/size interpolation I'm looking for.

Based on this, I have a few questions that I hope you can help me out with:

  • Am I doing something wrong here and Lines actually support the features I'm looking for?
  • If not, is any implementation for this feature already underway or already available in some feature branches?
  • If this is also not the case, would you be open to a Pull Request with this feature? Provided that I can get some pointers on where to look for the respective modules (currently not familiar with the bokeh codebase), I'd definitely be willing to sit down and give implementing this a shot.

Thanks in advance,
MT

--
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/1bb59515-664d-4690-87d7-e6950355dc98%40continuum.io\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.
<line.png>

Hi Bryan,

thanks for the response. I’ve looked into the documentation you’ve linked and this seems to be exactly the starting point I was looking for.

Asking ahead of time: Is there any centralized project/initiative where I could submit a finished implementation of a “InterpolatingLine”-Glyph back to the community? Something like the “Garden” project for Kivy, where 3rd party addons for bokeh can be made available for others?

Thanks again and have a great week,

MT

···

On Sunday, 28 May 2017 18:16:04 UTC+2, Bryan Van de ven wrote:

Hi,

There is nothing built in to Bokeh currently that would accomplish that sort of color interpolation along a line. You would have to create a custom extension to get that effect:

    [http://bokeh.pydata.org/en/latest/docs/user_guide/extensions.html](http://bokeh.pydata.org/en/latest/docs/user_guide/extensions.html)

Regarding the line_width and line_color properties, the primary reason it does not work is because Line only draws a single line (through multiple points). The line itself has nothing to vectorize, so supplying a field does not make sense. It’s only defined as a ColorSpec because of some dumb and uninteresting technical reasons. In general it would have been more precise to complete separate the notion of geometry (the “points”) from topology (any “connections” between points). It’s possible to do this (see e.g. the VTK library) but it makes for a much more cumbersome API. Offering Line as its own primitive (even with the width/color API warts) makes for a much more approachable interface for the majority of users, most of the time.

Thanks,

Bryan

On May 28, 2017, at 04:59, [email protected] wrote:

Hi everyone,

I’m running bokeh 12.5, using the bokeh.models interface to generate plots. One of my requirements is to have a Line-Glyph drawn with variable colors and sizes for each coordinate based on the data in a ColumnDataSource.

In short, I’m looking for the “Line”-equivalent of the following VBar-Glyph, with color and size interpolating between the coordinates:

glyph = VBar(x=field(“x”), top=field(“y”), fill_color=field(“color”), width=field(“size”))

I’ve attached an image showing an example of the Line I’d like to plot.

So far I’ve been running into a few problems when attempting to implement this.

    • The Line-Glyph does not support getting a field name instead of a fixed value for both the line_color and the line_width properties. This happends despite the documentation stating that those properties are ColorSpec (or NumberSpec respectively) and should work with field names. No error is thrown in Python, no Glyph is rendered in the HTML and the JS-Error-Console reports "Uncaught Error: attempted to retrieve property value for property without value specification". The same approach works fine for VBar/Circle Glyphs, so I suspect that this is a bug/missing feature in the Line Glyph.
    • I've been looking into Patch/Patches and Segment-Glyphs in order to get the desired output. However, none of them will be able to support both the color/size interpolation I'm looking for.

Based on this, I have a few questions that I hope you can help me out with:

    • Am I doing something wrong here and Lines actually support the features I'm looking for?
    • If not, is any implementation for this feature already underway or already available in some feature branches?
    • If this is also not the case, would you be open to a Pull Request with this feature? Provided that I can get some pointers on where to look for the respective modules (currently not familiar with the bokeh codebase), I'd definitely be willing to sit down and give implementing this a shot.

Thanks in advance,

MT


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/1bb59515-664d-4690-87d7-e6950355dc98%40continuum.io.

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

<line.png>