Error in plot.add_glyph(text_source, text) - Does not add text to plot

I think there is a BUG in the adding text Glyph to a plot. Please find below the sample plot which does not create “add text” to the plot.
Just copy and paste the below code, you will see the issue. Thanks for your great package.

My Ipython, Pandas, and Bokeh Versions:

IPython - 4.0.0
Pandas - 0.16.2
Bokeh - 0.10.0

--------------------------------------- Copy From here ------------------------------------------------

from bokeh.io import output_notebook, show

from bokeh.sampledata.autompg import autompg as df

from IPython import version as ipython_version

from pandas import version as pandas_version

from bokeh import version as bokeh_version

output_notebook()

print “IPython - %s” % ipython_version

print “Pandas - %s” % pandas_version

print “Bokeh - %s” %bokeh_version

from bokeh.models import Range1d, Plot

def get_plot():

xdr = Range1d(1600, 5500)

ydr = Range1d(5, 25)

plot = Plot(

x_range = xdr,

y_range = ydr,

title = “”,

plot_width = 800,

plot_height = 400,

outline_line_color = None,

toolbar_location = None,

responsive = True)

return plot

AXIS_FORMATS = dict(

minor_tick_in = None,

minor_tick_out = None,

major_tick_in = None,

major_label_text_font_size = “10pt”,

major_label_text_font_style = “normal”,

axis_label_text_font_size = “10pt”,

axis_line_color = ‘#AAAAAA’,

major_tick_line_color = ‘#AAAAAA’,

major_label_text_color = ‘#666666’,

major_tick_line_cap = “round”,

axis_line_cap = “round”,

axis_line_width = 1,

major_tick_line_width = 1,)

from bokeh.models import LinearAxis, SingleIntervalTicker

def add_axes(plot):

xaxis = LinearAxis (SingleIntervalTicker(interval = 500), axis_label = “Children per women”, **AXIS_FORMATS)

yaxis = LinearAxis (SingleIntervalTicker(interval = 2.5), axis_label = “Children per women”, **AXIS_FORMATS)

plot.add_layout(xaxis, ‘below’)

plot.add_layout(yaxis, ‘left’)

return plot

from bokeh.models import ColumnDataSource, Text

text_source = ColumnDataSource({‘year’: ‘71’})

def add_text(plot):

plot = add_axes(plot)

manually create your glyph, before, we alwaays write .circle or .line, …

(so for alll those methose this is actually what is going on under the hood)

text = Text(x=2, y=35, text=‘year’, text_font_size=‘150pt’, text_color=’#EEEEEE’)

plot.add_glyph(text_source, text)

return plot

from bokeh.models import Circle, HoverTool

render_source = ColumnDataSource(df)

def add_circle(plot):

plot = add_text(plot)

circle_glyph = Circle (x = ‘weight’, y = ‘accel’, size = ‘cyl’, fill_alpha = 0.8)

circle_renderer = plot.add_glyph(render_source, circle_glyph)

tooltips = “@index

plot.add_tools(HoverTool(tooltips = tooltips, renderers = [circle_renderer]))

return plot

show(add_circle(get_plot()))

hbokeh,

You have two issues. One is that ColumnDataSources need to contain columns/arrays/sequences of data:

  text_source = ColumnDataSource({'year': ['71']}) # note '71' in a list

Next, the ranges for your data are x -> (1600, 5500) and y -> (5,25) The coordinates you have given to display the text (x=2, y=35) are way outside this range. (The text glyph is being rendered, but the coordinates you gave are offscreen.) If I change it to, say:

    text = Text(x=2000, y=15, text='year', text_font_size='150pt', text_color='#EEEEEE') # note x, y different

Then I see the text as expected.

If you are looking for absolute screen positioning that is an on PR we are still working on.

Hope that helps,

Bryan

···

On Dec 22, 2015, at 10:45 AM, hkbokeh <[email protected]> wrote:

I think there is a BUG in the adding text Glyph to a plot. Please find below the sample plot which does not create "add text" to the plot.
Just copy and paste the below code, you will see the issue. Thanks for your great package.

My Ipython, Pandas, and Bokeh Versions:
IPython - 4.0.0
Pandas - 0.16.2
Bokeh - 0.10.0

--------------------------------------- Copy From here ------------------------------------------------
from bokeh.io import output_notebook, show
from bokeh.sampledata.autompg import autompg as df
from IPython import __version__ as ipython_version
from pandas import __version__ as pandas_version
from bokeh import __version__ as bokeh_version

output_notebook()
print "IPython - %s" % ipython_version
print "Pandas - %s" % pandas_version
print "Bokeh - %s" %bokeh_version
from bokeh.models import Range1d, Plot

def get_plot():
    xdr = Range1d(1600, 5500)
    ydr = Range1d(5, 25)
    plot = Plot(
        x_range = xdr,
        y_range = ydr,
        title = "",
        plot_width = 800,
        plot_height = 400,
        outline_line_color = None,
        toolbar_location = None,
        responsive = True)
    return plot

AXIS_FORMATS = dict(
    minor_tick_in = None,
    minor_tick_out = None,
    major_tick_in = None,
    major_label_text_font_size = "10pt",
    major_label_text_font_style = "normal",
    axis_label_text_font_size = "10pt",
    axis_line_color = '#AAAAAA',
    major_tick_line_color = '#AAAAAA',
    major_label_text_color = '#666666',
    major_tick_line_cap = "round",
    axis_line_cap = "round",
    axis_line_width = 1,
    major_tick_line_width = 1,)

from bokeh.models import LinearAxis, SingleIntervalTicker

def add_axes(plot):
    xaxis = LinearAxis (SingleIntervalTicker(interval = 500), axis_label = "Children per women", **AXIS_FORMATS)
    yaxis = LinearAxis (SingleIntervalTicker(interval = 2.5), axis_label = "Children per women", **AXIS_FORMATS)
    plot.add_layout(xaxis, 'below')
    plot.add_layout(yaxis, 'left')
    return plot

from bokeh.models import ColumnDataSource, Text

text_source = ColumnDataSource({'year': '71'})
def add_text(plot):
    
    plot = add_axes(plot)
    # manually create your glyph, before, we alwaays write .circle or .line, ....
    # (so for alll those methose this is actually what is going on under the hood)
    text = Text(x=2, y=35, text='year', text_font_size='150pt', text_color='#EEEEEE')
    plot.add_glyph(text_source, text)
    return plot

from bokeh.models import Circle, HoverTool
render_source = ColumnDataSource(df)
def add_circle(plot):
    plot = add_text(plot)
    circle_glyph = Circle (x = 'weight', y = 'accel', size = 'cyl', fill_alpha = 0.8)
    circle_renderer = plot.add_glyph(render_source, circle_glyph)
    tooltips = "@index"
    plot.add_tools(HoverTool(tooltips = tooltips, renderers = [circle_renderer]))
    return plot
show(add_circle(get_plot()))

--
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/4893cebf-e0e4-4023-9d9a-4850b834b1f2%40continuum.io\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.

Thanks Bryan, I noticed the second one and fixed it but I missed the first issue. Thanks again.

···

On Tuesday, December 22, 2015 at 11:45:41 AM UTC-5, hkbokeh wrote:

I think there is a BUG in the adding text Glyph to a plot. Please find below the sample plot which does not create “add text” to the plot.
Just copy and paste the below code, you will see the issue. Thanks for your great package.

My Ipython, Pandas, and Bokeh Versions:

IPython - 4.0.0
Pandas - 0.16.2
Bokeh - 0.10.0

--------------------------------------- Copy From here ------------------------------------------------

from bokeh.io import output_notebook, show

from bokeh.sampledata.autompg import autompg as df

from IPython import version as ipython_version

from pandas import version as pandas_version

from bokeh import version as bokeh_version

output_notebook()

print “IPython - %s” % ipython_version

print “Pandas - %s” % pandas_version

print “Bokeh - %s” %bokeh_version

from bokeh.models import Range1d, Plot

def get_plot():

xdr = Range1d(1600, 5500)

ydr = Range1d(5, 25)

plot = Plot(

x_range = xdr,

y_range = ydr,

title = “”,

plot_width = 800,

plot_height = 400,

outline_line_color = None,

toolbar_location = None,

responsive = True)

return plot

AXIS_FORMATS = dict(

minor_tick_in = None,

minor_tick_out = None,

major_tick_in = None,

major_label_text_font_size = “10pt”,

major_label_text_font_style = “normal”,

axis_label_text_font_size = “10pt”,

axis_line_color = ‘#AAAAAA’,

major_tick_line_color = ‘#AAAAAA’,

major_label_text_color = ‘#666666’,

major_tick_line_cap = “round”,

axis_line_cap = “round”,

axis_line_width = 1,

major_tick_line_width = 1,)

from bokeh.models import LinearAxis, SingleIntervalTicker

def add_axes(plot):

xaxis = LinearAxis (SingleIntervalTicker(interval = 500), axis_label = “Children per women”, **AXIS_FORMATS)

yaxis = LinearAxis (SingleIntervalTicker(interval = 2.5), axis_label = “Children per women”, **AXIS_FORMATS)

plot.add_layout(xaxis, ‘below’)

plot.add_layout(yaxis, ‘left’)

return plot

from bokeh.models import ColumnDataSource, Text

text_source = ColumnDataSource({‘year’: ‘71’})

def add_text(plot):

plot = add_axes(plot)

manually create your glyph, before, we alwaays write .circle or .line, …

(so for alll those methose this is actually what is going on under the hood)

text = Text(x=2, y=35, text=‘year’, text_font_size=‘150pt’, text_color=‘#EEEEEE’)

plot.add_glyph(text_source, text)

return plot

from bokeh.models import Circle, HoverTool

render_source = ColumnDataSource(df)

def add_circle(plot):

plot = add_text(plot)

circle_glyph = Circle (x = ‘weight’, y = ‘accel’, size = ‘cyl’, fill_alpha = 0.8)

circle_renderer = plot.add_glyph(render_source, circle_glyph)

tooltips = “@index

plot.add_tools(HoverTool(tooltips = tooltips, renderers = [circle_renderer]))

return plot

show(add_circle(get_plot()))