☰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

Different sizing_mode for output_file

Community Supportbokehjsbokeh
somebody
somebody

Hi,
I’m looking for a feature to change sizing_mode when output_file is called.
I can of course change it manually directly in the html file when it isaved but don’t think it is a smart solution.

fig = figure(sizing_mode="stretch_width")
...
output_file(filename=path_to_file)
save(fig)
# This is what I use now 
# but want more smarter solution within bokeh library if there is one
with open(path_to_file, 'r') as f:
    stretch_width = f.read().replace('stretch_width', 'stretch_both')
with open(path_to_file, 'w') as f:
    f.write(stretch_width)

Thanks

⌁   Link to post
somebody
somebody

hi Bryan
I have sizing_mode="stretch_width" on the web page.
If I change it write before calling output_file(filename=path_to_file) like this:

fig = figure(sizing_mode="stretch_width")
fig.sizing_mode = "stretch_both"
output_file(filename=path_to_file)
save(fig)

then the web page will display the change as well but I need only change it in the file but not on the webpage.

⌁   Link to post
Bryan
Bryan

Sorry, I am still not understanding. What does “on the webpage” mean here, exactly? Do you mean you are also passing the figure to one of the bokeh.embed APIs first before saving? Then you should be able to change the sizing mode after the embedding, but before saving. Are you saying that does not work? Then we need a complete Minimal Reproducible Example to actually run and investigate directly. Otherwise, please describe all the steps you are taking more fully and in more detail.

⌁   Link to post
somebody
somebody

Sorry for confusing you. I’ll try to explain what I mean.
I have a Flask app with dinamically creating Bokeh graphs based on user’s input. Those plots are displayed using "stretch_width" mode. When the plot is displayed on the webpage I want to save it as well as a html file output_file(filename=path_to_file) but with different sizing_mode. This is a simplified snippet from the code:

@app.route("/")
def some_route():
fig = figure(sizing_mode="stretch_width")
fig.line(0, 0)
output_file(filename=path) # here I need to save the plot with diffferent sizing_mode but not change it when template is rendered
save(fig)
js_resources = INLINE.render_js()
css_resources = INLINE.render_css()
script, div = components(fig)
return render_template('index.html', plot_script=script, plot_div=div, js_resources=js_resources, css_resources=css_resources)
⌁   Link to post

End of archived discussion · Replies are disabled