在Jupyter笔记本中的Plotly中使用外部CSS字体

问题描述

我想在Jupyter笔记本中制作的Plotly图中使用外部字体。

How do I set custom CSS for my IPython/IHaskell/Jupyter Notebook?中,我创建了一个单元格,添加了我从Google字体页面获取的Poppins字体。

%%html
<style>
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@100;200;300;400;500;600;700;800;900&display=swap" rel="stylesheet">
</style>

接下来以简单的Plotly图为例,我尝试在下一个Jupyter代码单元格中使用Poppins字体

# https://plotly.com/python/figure-labels/
import plotly.graph_objects as go
fig = go.figure()
fig.add_trace(go.Scatter(
    x=list(range(10)),y=[n**2 for n in range(10)]
))
fig.update_layout(
    title="My Plot Title",font=dict(
        family="Poppins,monospace",# only this part should matter
        size=20
    )
)
fig.show()

图形显示的是等宽字体,这意味着Poppins字体无法显示

在Chrome开发工具中,似乎%% HTML单元无法加载字体,因为没有调用googleapis网址。

我正在运行自己的Littlest Jupyter Hub实例,因此我也考虑制作一个custom.css

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...