在Plotly中,使用HTML,为什么一些希腊字母与十进制一起工作,而与实体名称不一起工作?

2024-04-19 20:46:19 发布

您现在位置:Python中文网/ 问答频道 /正文

在绘图图形标题中,我需要使用希腊字母,对于某些字母,我可以直接使用实体名称,如下所示: μ并呈现正确的希腊字母mu。然而,当我用ωψ对欧米茄或psi做同样的操作时,我只会用带有“&;”的拉丁字符来写单词和“;”但不是对应的希腊语。以下是结果的图像:

enter image description here

但是,使用十进制代码可以按预期工作:layout = go.Layout(title='ω #968;')

enter image description here


Tags: 代码图像实体名称图形绘图标题字母
1条回答
网友
1楼 · 发布于 2024-04-19 20:46:19

认为它与javascript后端有关,特别是在svg_text_utils.js中的entityToUnicode

所以我认为$mu;是唯一有效的希腊字母(因为它是由entityToUnicode和一手其他字符一起处理的)

从svg_text_utils.js:

/*
 * N.B. HTML entities are listed without the leading '&' and trailing ';'
 * https://www.freeformatter.com/html-entities.html
 *
 * FWIW if we wanted to support the full set, it has 2261 entries:
 * https://www.w3.org/TR/html5/entities.json
 * though I notice that some of these are duplicates and/or are missing ";"
 * eg: "&", "&amp", "&", and "&AMP" all map to "&"
 * We no longer need to include numeric entities here, these are now handled
 * by String.fromCodePoint/fromCharCode
 *
 * Anyway the only ones that are really important to allow are the HTML special
 * chars <, >, and &, because these ones can trigger special processing if not
 * replaced by the corresponding entity.
 */
var entityToUnicode = {
    mu: 'μ',
    amp: '&',
    lt: '<',
    gt: '>',
    nbsp: ' ',
    times: '×',
    plusmn: '±',
    deg: '°'
};

相关问题 更多 >