# Is it possible to define y\_units of a glyph to be canvas (so they won't move vertically on pan/zoom)

**URL:** <https://discourse.bokeh.org/t/is-it-possible-to-define-y-units-of-a-glyph-to-be-canvas-so-they-wont-move-vertically-on-pan-zoom/2921>\
**Category:** Community Support\
**Created:** [April 23, 2018, 10:02am UTC](https://discourse.bokeh.org/t/is-it-possible-to-define-y-units-of-a-glyph-to-be-canvas-so-they-wont-move-vertically-on-pan-zoom/2921 "2018-04-23T10:02:24Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Meir\_Tseitlin](https://discourse.bokeh.org/letter_avatar_proxy/v4/letter/m/838e76/32.png) [@Meir\_Tseitlin](https://discourse.bokeh.org/u/Meir_Tseitlin)\
**Post date:** [April 23, 2018, 10:02am UTC](https://discourse.bokeh.org/t/is-it-possible-to-define-y-units-of-a-glyph-to-be-canvas-so-they-wont-move-vertically-on-pan-zoom/2921/1 "2018-04-23T10:02:24Z")

</div>

I have time-series plots displayed and on the the plot I want to add a representation of different “Events” happened.

I think that the best way to visualize events is with circle glyph which will show event information with Hover tool.

Yet “events” don’t have Y value (only their time), so the best way would be to have a constant Y location on plot and move them only on X (when the plot is moved/zooms).

This can be achieved with Labels and I wonder if the same can somehow be applied for Glyphs.

Thanks

---

<div class="post-metadata">

**Author:** ![Angelo\_Fausti](https://discourse.bokeh.org/user_avatar/discourse.bokeh.org/angelo_fausti/32/842_2.png) [@Angelo\_Fausti](https://discourse.bokeh.org/u/Angelo_Fausti)\
**Post date:** [April 23, 2018, 5:07pm UTC](https://discourse.bokeh.org/t/is-it-possible-to-define-y-units-of-a-glyph-to-be-canvas-so-they-wont-move-vertically-on-pan-zoom/2921/2 "2018-04-23T17:07:56Z")

</div>

Hi Meir,

it is not possible to position glyphs directly using screen coordinates. Alternatively, you could use a secondary y-axis ([https://bokeh.pydata.org/en/latest/docs/user\_guide/plotting.html#twin-axes](https://bokeh.pydata.org/en/latest/docs/user_guide/plotting.html#twin-axes)) and use a callback to always reset the secondary y-axis range. Something like this:

p.add\_layout(LinearAxis(y\_range\_name=‘events’, axis\_label=‘Events’), ‘right’)

p.extra\_y\_ranges = {‘events’: Range1d(start=0, end=1)}

# make sure you have ‘events\_y’ in your CDS perhaps a list filled with ‘0.5’

p.circle(x=‘time’, y=‘events\_y’, y\_range\_name=‘events’, source=cds, size=20)

# This callback is used to reset the range of the secondary y-axis range

# to its original value

args = {‘range’: p.extra\_y\_ranges[‘events’]}

code = “”"  
range.start = 0;  
range.end = 1;  
“”"

callback = CustomJS(args=args, code=code)

p.extra\_y\_ranges[‘events’].js\_on\_change(‘start’, callback)

best,

> **···**
>
> On Mon, Apr 23, 2018 at 3:02 AM, Meir Tseitlin [meir@imubit.com](mailto:meir@imubit.com) wrote:
> 
> > I have time-series plots displayed and on the the plot I want to add a representation of different “Events” happened.
> 
> > I think that the best way to visualize events is with circle glyph which will show event information with Hover tool.
> 
> > 
> 
> > Yet “events” don’t have Y value (only their time), so the best way would be to have a constant Y location on plot and move them only on X (when the plot is moved/zooms).
> 
> > 
> 
> > This can be achieved with Labels and I wonder if the same can somehow be applied for Glyphs.
> 
> > 
> 
> > Thanks
> 
> > –
> > 
> > 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 [bokeh+unsubscribe@continuum.io](mailto:bokeh+unsubscribe@continuum.io).
> > 
> > To post to this group, send email to [bokeh@continuum.io](mailto:bokeh@continuum.io).
> > 
> > To view this discussion on the web visit [https://groups.google.com/a/continuum.io/d/msgid/bokeh/f47a2f6f-ad9f-458e-9b38-dceca8e5ce72%40continuum.io](https://groups.google.com/a/continuum.io/d/msgid/bokeh/f47a2f6f-ad9f-458e-9b38-dceca8e5ce72%40continuum.io?utm_medium=email&utm_source=footer).
> > 
> > For more options, visit [https://groups.google.com/a/continuum.io/d/optout](https://groups.google.com/a/continuum.io/d/optout).
> 
> Angelo Fausti

---

<div class="post-metadata">

**Author:** ![Bryan](https://discourse.bokeh.org/user_avatar/discourse.bokeh.org/bryan/32/3625_2.png) [@Bryan](https://discourse.bokeh.org/u/Bryan)\
**Post date:** [April 23, 2018, 5:27pm UTC](https://discourse.bokeh.org/t/is-it-possible-to-define-y-units-of-a-glyph-to-be-canvas-so-they-wont-move-vertically-on-pan-zoom/2921/3 "2018-04-23T17:27:02Z")

</div>

Hi,

This used to be possible a very long time ago, but as features for more advanced hit testing and hover, etc were added, it had to be removed. Basically trying to hit test when coordinates could be in data space or screen space or a mix was just an unmanageable nightmare. The compromise we came up with was that Annotations were things that could be positioned directly in screen space, but that they would not participate in hit-testing. The thing desired here sounds a bit like a "Rug" annotation, which I've thought would be a nice addition for some time, so feel free to make an issue to discuss it. I don't think would be a ton of work and possibly a nice task for a new contributor.

Thanks,

Bryan

> **···**
>
> > On Apr 23, 2018, at 10:07, Angelo Fausti \<angelofausti@gmail.com\> wrote:
> > 
> > Hi Meir,
> > 
> > it is not possible to position glyphs directly using screen coordinates. Alternatively, you could use a secondary y-axis ([https://bokeh.pydata.org/en/latest/docs/user\_guide/plotting.html#twin-axes\](https://bokeh.pydata.org/en/latest/docs/user_guide/plotting.html#twin-axes%5C)) and use a callback to always reset the secondary y-axis range. Something like this:
> > 
> > p.add\_layout(LinearAxis(y\_range\_name='events', axis\_label='Events'), 'right')
> > 
> > p.extra\_y\_ranges = {'events': Range1d(start=0, end=1)}
> > 
> > # make sure you have 'events\_y' in your CDS perhaps a list filled with '0.5'
> > 
> > p.circle(x='time', y='events\_y', y\_range\_name='events', source=cds, size=20
> > 
> > # This callback is used to reset the range of the secondary y-axis range  
> > # to its original value
> > 
> > args = {'range': p.extra\_y\_ranges['events']}
> > 
> > code = """  
> > range.start = 0;  
> > range.end = 1;  
> > """
> > 
> > callback = CustomJS(args=args, code=code)
> > 
> > p.extra\_y\_ranges['events'].js\_on\_change('start', callback)
> > 
> > best,
> > 
> > Angelo Fausti
> > 
> > On Mon, Apr 23, 2018 at 3:02 AM, Meir Tseitlin \<meir@imubit.com\> wrote:  
> > I have time-series plots displayed and on the the plot I want to add a representation of different "Events" happened.
> > 
> > I think that the best way to visualize events is with circle glyph which will show event information with Hover tool.
> > 
> > Yet "events" don't have Y value (only their time), so the best way would be to have a constant Y location on plot and move them only on X (when the plot is moved/zooms).
> > 
> > This can be achieved with Labels and I wonder if the same can somehow be applied for Glyphs.
> > 
> > Thanks
> > 
> > --  
> > 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 bokeh+unsubscribe@continuum.io.  
> > To post to this group, send email to bokeh@continuum.io.  
> > To view this discussion on the web visit [https://groups.google.com/a/continuum.io/d/msgid/bokeh/f47a2f6f-ad9f-458e-9b38-dceca8e5ce72%40continuum.io\](https://groups.google.com/a/continuum.io/d/msgid/bokeh/f47a2f6f-ad9f-458e-9b38-dceca8e5ce72%40continuum.io%5C).  
> > For more options, visit [https://groups.google.com/a/continuum.io/d/optout\](https://groups.google.com/a/continuum.io/d/optout%5C).
> > 
> > --  
> > 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 bokeh+unsubscribe@continuum.io.  
> > To post to this group, send email to bokeh@continuum.io.  
> > To view this discussion on the web visit [https://groups.google.com/a/continuum.io/d/msgid/bokeh/CAD%3DOK5MH52MpZTiDHzap%3DcbTo\_EdJSViW5wgr5%3D8gew2AmLHrw%40mail.gmail.com\](https://groups.google.com/a/continuum.io/d/msgid/bokeh/CAD%3DOK5MH52MpZTiDHzap%3DcbTo_EdJSViW5wgr5%3D8gew2AmLHrw%40mail.gmail.com%5C).  
> > For more options, visit [https://groups.google.com/a/continuum.io/d/optout\](https://groups.google.com/a/continuum.io/d/optout%5C).

---

<div class="post-metadata">

**Author:** ![system](https://discourse-uploads.bokeh.org/original/2X/1/14eb24f9e10e4e9b78e3f10f66c04ffa96446e5a.svg) [@system](https://discourse.bokeh.org/u/system)\
**Post date:** [July 21, 2021, 9:14pm UTC](https://discourse.bokeh.org/t/is-it-possible-to-define-y-units-of-a-glyph-to-be-canvas-so-they-wont-move-vertically-on-pan-zoom/2921/4 "2021-07-21T21:14:43Z")

</div>


