☰Read-only archive⌕
Looking for help with Bokeh?

This is a read-only archive. Ask questions and join the conversation on GitHub.

Visit Community Support on GitHub →
Archived discussions · Captured October 28, 2026

Patch glyph source problems

Community Support
mmcguffi
mmcguffi

I am trying to plot patches using source, but I am running into issues. I have gotten this to work in (from what I can tell) almost identical ways, but I cannot for the life of me figure out what I am doing wrong here.

Here is a minimal example:

import pandas as pd
from bokeh.io import show
from bokeh.plotting import figure
from bokeh.models import HoverTool

url='https://raw.githubusercontent.com/mmcguffi/random_test_cases/master/test.csv'
df=pd.read_csv(url,index_col=0)
df['x'] = pd.eval(df['x']) #convert to list
df['y'] = pd.eval(df['y']) #convert to list

hover = HoverTool(names=["1"])
TOOLTIPS='<font size="3"><b>@Feature</b> — @Type</font> <br> @Description'
plotSize=.35
plotDimen=800
p = figure(plot_height=plotDimen,plot_width=plotDimen, title="", toolbar_location=None, match_aspect=True,sizing_mode='scale_width',
               tools=[hover,], tooltips=TOOLTIPS, x_range=(-plotSize, plotSize), y_range=(-plotSize, plotSize))

for index in df.index:
    p.patch(x='x', y='y', fill_color='fill_color',line_color='line_color',name="1",line_width=2, source=df.loc[[index]])
show(p)

It throws an error about colors, but even if you manually change that, it still does not display the plot. I really dont know what’s going on here any help or a pointer to some clear resources would be very much appreciated!

⌁   Link to post
carolyn
carolyn

Hi mmcguffi,

I think what you want may be p.patches– check out this example:

I tried it in your code by replacing your for loop with the following. (You’ll also have to add ColumnDataSource to your import from bokeh.models.)

source = ColumnDataSource(df)
p.patches('x', 'y', fill_color='fill_color', line_color='line_color', name="1", line_width=2, source=source)

End result looked like this:

Neat! Hope it’s close to what you’re going for. :slight_smile:

⌁   Link to post
Bryan
Bryan

FYI most of Bokeh’s glyphs are “vectorized” (patch is one of the few exceptions). There are always special cases and exceptions, but in general it will always be more efficient to load all the data up front to one vectorized glyph function call, rather than looping and calling the glyph function over and over with individual data items.

⌁   Link to post

End of archived discussion · Replies are disabled