Can we specify bokeh exported png file size / resolution?

蹲街弑〆低调 提交于 2019-12-02 04:45:22

In recent enough versions, export_png accepts width and height parameters:

https://bokeh.pydata.org/en/latest/docs/reference/io.html#bokeh.io.export_png

If they are not available in your current install then you will need to update your Bokeh installation to something newer.

There is a way to increase the resolution when the plot is exported with export_png (which @bigreddot says in his answer), that is setting width and height directly in the method:

export_png(p2, filename="plot.png", height=300, width=300)

The problem is that the axis and font size keep always the same size, no matter how big the plot is:

export_png(p2, filename="plot.png", height=1200, width=1200)

The possible solution right now is to update the axis attributes manually. I think that an easy fix would be to increase, in proportion, the size of the axis and fonts before exporting.

Also, if you want to save many canvas (each canvas element has a plot) at the same time you can use the JavaScript method canvas.toDataUrl() to convert the canvas to png as base64. When you get all the images you can do whatever you want with them. These images have 96dpi and it cannot be changed, so if you want more resolution you will have to update the sizes of all the elements of the plot before the convertion as well: fonts, axis, plot size...

If you use the last approach you do not need to install selenium and phantomjs dependencies

Anyway if you wait for the 2.0 version you will get this for gridplots:

At bokeh 2.0, gridplot() will produce an instance of a single canvas GridPlot model. The old behavior will still be possible with an existing GridBox layout.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!