首页 > 解决方案 > 在 Plotly 中,使用 HTML,为什么一些希腊字母可以使用小数,但不能使用实体名称?

问题描述

在我的 Plotly 图形标题中,我需要使用希腊字母,对于某些字母,我可以直接使用实体名称: μ它会呈现正确的希腊字母 mu。ω但是,当我用or对 omega 或 psi 做同样的事情时,ψ我只会得到用拉丁字符写成的单词,带有 '&' 和 ';' 但不是相应的希腊语。这是结果的图像:

在此处输入图像描述

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

在此处输入图像描述

标签: pythonhtmlplotly

解决方案


认为这与 javascript 后端有关,尤其是entityToUnicodesvg_text_utils.js中。

所以我认为这$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: '°'
};

推荐阅读