Reputation: 179
I am going to embed bokeh plots into a powerpoint presentation. However, when I try to create a smaller chart by reducing plot height, the plot is not entirely shown. Here is the code:
d={'name':['a','b','c','d'],
'value':[800,1800,400,30]}
df=pd.DataFrame(d)
src=ColumnDataSource(df)
pl=figure(plot_height=350,
plot_width=500,
x_range=src.data['name'].tolist())
labels = LabelSet(x='name', y='value', text='value', level='glyph',
x_offset=-13.5, y_offset=5, source=src, render_mode='canvas')
pl.vbar(x='name', top='value', width=.8, source=src)
pl.add_layout(labels)
export_png(pl, filename=OUTFILE+'slide_4.png')
And here is the result:
Bar chart
Is there a way to make smaller bokeh charts? If not, maybe there is a way to resize images in python-pptx?
Upvotes: 1
Views: 115
Reputation: 10697
The plot is shown in its entirety. The clipping that you see is due to the fact that LabelSet
is an annotation, and annotations are not taken into account when computing data ranges.
To fix the issue, either provide a larger padding to the default DataRange1d
instance that is Y range, or just set the end of the range manually.
Upvotes: 1