表情符号错误plotly kaleido静态图片导出不支持表情符号

问题描述 投票:0回答:1

https://github.com/misrori/goldhandyoutube/blob/main/aranykez.ipynb 在 Colab 中,它在显示时起作用。

但是当你导出它时并没有

from goldhand import *
tw = Tw()
t = GoldHand('TSLA')
p = t.plotly_last_year(tw.get_plotly_title('TSLA'))
p.update_layout(height=1080, width=1920)
p.write_image("fig1.png")
python plotly emoji
1个回答
0
投票

我做了一些测试:https://colab.research.google.com/drive/1lA29VpoH-CefxR1sCPsCX54fe1q-vQsL#scrollTo=9kO91brNR5Xx

我的预感为什么直接将绘图导出为 PNG 是不会导出 unicode,如下所示:

chart exported to png, emojis are rendering as []

理由:https://www.quora.com/Why-do-emojis-show-up-as-boxes-on-my-computer

系统没有要渲染的字体或文档字符集中未定义的任何字符都会在屏幕上显示为一个框。表情符号是 Unicode 字符,最多具有 4 字节代码,因此文档的字符编码必须至少为 UTF-8 才能正确呈现它们。如果文档标题指定 ASCII 编码,例如 ISO-8859–1(西欧拉丁字符集),则不会显示表情符号。此外,Unicode 一直在修订以添加新的字符代码,因此不升级的旧系统将无法显示新的字符代码。

我认为这可能与此无法在静态图像#157中显示字符有关,因为这涉及使用中文语言集中的字符并且它呈现相同的[]。但这只是猜测。

我发现的当前解决方法是将绘图保存为 SVG

t = GoldHand('TSLA')
p = t.plotly_last_year(tw.get_plotly_title('TSLA'))
p.update_layout(height=1080, width=1920)
p.write_image("fig1.svg")

screenshot of SVG from web browser

或者作为 HTML 文档,然后进入内部并将其导出为 PNG。

import plotly
t = GoldHand('TSLA')
p = t.plotly_last_year(tw.get_plotly_title('TSLA'))
plotly.offline.plot(p, filename='chart.html')

screenshot of chart saved as html document with export to pdf tooltip active

注意,我还尝试使用here提到的库(html2image),但我一直遇到输出文件

screenshot.png
无法写入磁盘的问题。这个问题可能仅限于我进行测试的 colab。

© www.soinside.com 2019 - 2024. All rights reserved.