Md. Zakir Hossan
Md. Zakir Hossan

Reputation: 537

how to solve text potting with bokeh?

Consider the flowing lines of code...

from bokeh.plotting import figure, save
text = 'I eat rice'
p = figure(title="Bokeh Markers", toolbar_location=None)
p.text(50, 50, text=[text], text_color="firebrick", text_align="center", text_font_size="10pt")
save(p, filename='test.png')

Buit it gives lines of warnnings given below

C:\Users\~\Anaconda3\lib\site-packages\bokeh\io.py:430: UserWarning: save() called but no resources were supplied and output_file(...) was never called, defaulting to resources.CDN
warnings.warn("save() called but no resources were supplied and output_file(...) was never called, defaulting to resources.CDN")

C:\Users\~\Anaconda3\lib\site-packages\bokeh\io.py:440: UserWarning: save() called but no title was supplied and output_file(...) was never called, using default title 'Bokeh Plot'
warnings.warn("save() called but no title was supplied and output_file(...) was never called, using default title 'Bokeh Plot'")

Its saving a .png file but which contains nothing.

Upvotes: 1

Views: 822

Answers (2)

bigreddot
bigreddot

Reputation: 34568

If your intent is to save an actual PNG image, then this is not how to do it. The save function saves a standard fully interactive Bokeh plot, which is actually HTML and JavaScript, and not a static PNG image.

If you want a PNG, then you need to export the plot, as described in the Exporting Plots section of the User's Guide. Basically you must first install a few optional dependencies (selenium, pillion, and phantomJS) then the necessary code would be more like:

export_png(plot, filename="plot.png")

Upvotes: 0

Hiroyuki Taniichi
Hiroyuki Taniichi

Reputation: 436

You should add this code.

from bokeh.plotting import output_file
output_file('test.png')

There it the related code in output_file.

    self._file = {
        'filename'  : filename,
        'resources' : Resources(mode=mode, root_dir=root_dir),
        'title'     : title
    }

Upvotes: 1

Related Questions