Visualize-ML / Book1_Python-For-Beginners

Book_1_《编程不难》 | 鸢尾花书:从加减乘除到机器学习;请多多批评指正!
4.21k stars 803 forks source link

Book_1_Ch_11代码疑问 #129

Closed Mephistofer closed 4 months ago

Mephistofer commented 7 months ago

Book_1_Ch_11,第16页,代码 4. 用 Plotly 生成平面等高线 | Bk1_Ch11_04.ipynb

# 创建布局
layout = go.Layout(
 width=600, # 设置图形宽度
 height=600, # 设置图形高度
 xaxis=dict(title=r'$x_1$'),
 yaxis=dict(title=r'$x_2$'))

这段代码,Latex语法在vscode和jupyter notebook中都没有生效,感觉plotly.graph_objects对于Latex支持可能有一点问题。 在vscode中,latex默认渲染是vscode,可以修改渲染器生效,例如:

import plotly.io as pio
pio.renderers.default = 'svg'

但是chrome中使用jupyter notebook,默认渲染是“plotly_mimetype+notebook",目前渲染器我设置为browser才可以,不清楚怎么回事。

Visualize-ML commented 7 months ago

确实,Latex没有被渲染。如果你要是找到什么好办法,告诉我哈。

Cheers,

On Sun, Dec 17, 2023 at 10:31 PM Mephistofer @.***> wrote:

Book_1_Ch_11,第16页,代码 4. 用 Plotly 生成平面等高线 | Bk1_Ch11_04.ipynb

创建布局

layout = go.Layout( width=600, # 设置图形宽度 height=600, # 设置图形高度 xaxis=dict(title=r'$x_1$'), yaxis=dict(title=r'$x_2$'))

这段代码,Latex语法在vscode和jupyter notebook中都没有生效,感觉plotly.graph_objects对于Latex支持可能有一点问题。 在vscode中,latex默认渲染是vscode,可以修改渲染器生效,例如:

import plotly.io as pio pio.renderers.default = 'svg'

但是chrome中使用jupyter notebook,默认渲染是“plotly_mimetype+notebook",目前渲染器我设置为browser才可以,不清楚怎么回事。

— Reply to this email directly, view it on GitHub https://github.com/Visualize-ML/Book1_Python-For-Beginners/issues/129, or unsubscribe https://github.com/notifications/unsubscribe-auth/AZHC6VYVJXJMUI5KZQR52S3YJ62JTAVCNFSM6AAAAABAY32CS6VHI2DSMVQWIX3LMV43ASLTON2WKOZSGA2DKNRWGUZDEOA . You are receiving this because you are subscribed to this thread.Message ID: @.***>

Mephistofer commented 7 months ago

如果确保anaconda运行环境正确(从prop中启动jupyter),以及正确安装了 Kaleido,则将默认的渲染器设置为图像类的,之后的都可以正常显示。比如绘图前设置:

import plotly.io as pio
pio.renderers.default = 'png'
Mephistofer commented 7 months ago

之前我发现这种设置vscode可以,jupyterlab不行的原因是我启动jupyterlab是直接cmd进入的,没有进入base环境中,如果直接从prompt中进入就没有这个问题。