Trying to use jitter with categorical plot, no plot!

Hi

I’m trying to create a categorical scatter plot with jitter, but getting a blank browser page, no plot, no error messages.

I started with a numeric x-axis and jitter, which worked fine. Then I changed the code to give me a categorical plot and this works fine without jitter. When I add jitter I get a blank browser page, athough no errors thrown. Sure I’m doing something stupid, but would very much appreciate help to find out what!

Copy of code below, with simplified test data.

import bokeh

from bokeh.models import (ColorBar, ColumnDataSource, Legend, PanTool, Plot, SaveTool, BoxZoomTool,
    Label, LabelSet, Range1d)
from bokeh.plotting import figure, output_file, show
from bokeh.transform import linear_cmap, jitter
from bokeh.core.enums import LegendLocation
from bokeh.io import export_png
from bokeh.layouts import column, row,gridplot

#simplified test data
pmaxtoplot=[0.5,0.6,0.4,0.7]
pmaxtemplabs=["23C","23C","24C","24C"]
xaxiscats=["23C","24C"]   

#####
    
pmaxplotsource=ColumnDataSource(data=dict(pmax=pmaxtoplot,templab=pmaxtemplabs))

pmplot1 = figure(title = "categorical plot",x_range=xaxiscats, y_range=(0.0,1.04), plot_width=1000, plot_height=600)
 
pmplot1.circle(x=jitter("templab",width=0.2), y="pmax", size=4,source=pmaxplotsource)

#the commented plot.circle command below, without jitter, works 
#pmplot1.circle(x="templab", y="pmax", size=4,source=pmaxplotsource)

show (pmplot1)

Hi @PennyL please edit your post to use code formatting so that the code is intelligible (either with the </> icon on the editing toolbar, or triple backtick ``` fences around the code blocks)

Thanks Bryan,

Thank you for the guidance. Have edited the code in my question as you suggested and think I have it all properly formatted now.(?) I have also gone through taking out as much additional code as possible, checking that what’s left still works without jitter and still doesn’t work when I try to use jitter.

Meanwhile I have temporarily generated a useable plot by formatting a numeric axis to look like a categorical axis, but I’d still very much like to know how to get this working.

Thanks again for your patience and your help with the basic mechanics of asking my question.

See this similar topic on discourse. It looks like the solution should address your problem.

1 Like

Yes! Thank you! I changed the code to x=jitter(“templab”,width=0.2,range=pmplot1.x_range) and it works fine.
I had seen the example in the link, but because everything worked without the ‘range’ component in my original, non-categorical file, I didn’t think to try it once things failed. I knew it was somethig stupid!

Thank You!!

2 Likes