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")
The problem you are facing is that Kaleido, the library used by Plotly to export static images, does not currently support emojis. This is a known limitation, and there isn't a direct solution within Kaleido itself.
However, there are some workarounds you can use to include emojis in your exported images:
1. Using a different image export library:
-
Plotly Orca:
Orca is another image export library that Plotly supports. It has better emoji support than Kaleido. You can try switching to Orca by installing it (
pip install plotly-orca
) and then setting theplotly.io.orca.config.executable
option to the path of your Orca executable.python import plotly.io as pio pio.orca.config.executable = '/path/to/orca'
- Selenium or other browser automation: You can use libraries like Selenium to open the Plotly chart in a browser and then take a screenshot. This method relies on the browser's emoji rendering capabilities.
2. Replacing emojis with images before export:
- You can replace the emoji characters in your data with image URLs that represent the emojis. This will ensure they are rendered correctly in the exported image.
Example (using image replacement):
import plotly.graph_objects as go
# Sample data with an emoji
labels = ['A', 'B', 'C
标签:python,plotly,emoji
From: 77466394