使用 base64 编码内容而不是 HTML 转换的 Zeppelin 图像显示
Zeppelin image display with base64 encoded content instead of HTML conversion
我目前正在使用 Zeppelin 和 Seaborn 进行一些可视化,但是显示机制会自动将图像转换为 HTML,这会立即占用我所有的 RAM。 (数据点太多)。
另一方面,Jupyter 处理起来相当容易,看起来它只是将图像内容编码为 Base64 字符串。
是否可以在 Zeppelin 中模仿这种行为?或者,更好的是,将其配置为默认图像处理机制?
我不知道我是否可以覆盖默认行为,但这可以通过 html 魔法手动实现。例如:
def show(graphics):
graphics.savefig("../tmp.png")
with open("../tmp.png", "rb") as image_file:
encoded_string = base64.b64encode(image_file.read())
return """%html <img src="data:image/png;base64,{}" />""".format(encoded_string.decode())
使用 base64 编码的 png 返回 html 字符串对我的数据更有效率,我可能会在任何地方使用它。
我目前正在使用 Zeppelin 和 Seaborn 进行一些可视化,但是显示机制会自动将图像转换为 HTML,这会立即占用我所有的 RAM。 (数据点太多)。
另一方面,Jupyter 处理起来相当容易,看起来它只是将图像内容编码为 Base64 字符串。
是否可以在 Zeppelin 中模仿这种行为?或者,更好的是,将其配置为默认图像处理机制?
我不知道我是否可以覆盖默认行为,但这可以通过 html 魔法手动实现。例如:
def show(graphics):
graphics.savefig("../tmp.png")
with open("../tmp.png", "rb") as image_file:
encoded_string = base64.b64encode(image_file.read())
return """%html <img src="data:image/png;base64,{}" />""".format(encoded_string.decode())
使用 base64 编码的 png 返回 html 字符串对我的数据更有效率,我可能会在任何地方使用它。