我们可以指定散景导出的png文件大小/分辨率吗? [英] Can we specify bokeh exported png file size / resolution?

查看:196
本文介绍了我们可以指定散景导出的png文件大小/分辨率吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Python Bokeh export_png函数,我们可以将对象导出到png文件.但是,我找不到任何指定结果png文件大小/分辨率的方法.

With Python Bokeh export_png function, we can export an object to png file. However, I cannot find any way to specify the resulted png file size / resolution.

我发现在Windows和Linux中使用相同的代码并获得了不同的png文件.在Windows中,分辨率要低得多.

I found that I used the same code and got different png files in Windows and Linux. In Windows, the resolution is much lower.

我了解我们可以使用export_svgs()获得更好的图形文件.但是与export_png()相比,export_svgs()有很多限制.我们不能在div,列或行对象上使用export_svgs().

I understand we can use export_svgs() to have better figure file. But compared with export_png(), export_svgs() has many limitations. We cannot use export_svgs() on div, column or row objects.

推荐答案

当使用export_png(@bigreddot在他的回答中说)导出图时,有一种提高分辨率的方法.直接在方法中:

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.

此外,如果要同时保存许多画布(每个画布元素都有一个图),则可以使用JavaScript方法canvas.toDataUrl()将画布转换为base64形式的png.当您获得所有图像时,您可以对它们进行任何操作.这些图像的分辨率为96dpi,无法更改,因此,如果要获得更高的分辨率,则还必须在转换之前更新绘图的所有元素的大小:字体,轴,绘图大小...

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...

如果使用最后一种方法,则不需要安装seleniumphantomjs依赖项

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

无论如何,如果您等待2.0版本,将会得到针对网格图的信息:

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

在bokeh 2.0上,gridplot()将产生单个画布GridPlot模型的实例.现有的GridBox布局仍然可以使用旧的行为.

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.

这篇关于我们可以指定散景导出的png文件大小/分辨率吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆