【问题标题】:Plotly js: latex not workingPlotly js:乳胶不起作用
【发布时间】:2016-08-04 08:30:58
【问题描述】:

我不能让乳胶在情节上工作。

var trace1 = {
  x: [1, 2, 3, 4],
  y: [1, 4, 9, 16],
  name: '$\alpha_{1c} = 352 \pm 11 \text{ km s}^{-1}$',
  type: 'scatter'
};
var trace2 = {
  x: [1, 2, 3, 4],
  y: [0.5, 2, 4.5, 8],
  name: '$\beta_{1c} = 25 \pm 11 \text{ km s}^{-1}$',
  type: 'scatter'
};
var data = [trace1, trace2];
var layout = {
  xaxis: {title: '$\sqrt{(n_\text{c}(t|{T_\text{early}}))}$'},
  yaxis: {title: '$d, r \text{ (solar radius)}$'}
};
Plotly.newPlot('myDiv', data, layout);

这是一个关于 jsfiddle 的例子:https://jsfiddle.net/gn1nnaup/

示例取自https://plot.ly/javascript/LaTeX/

它会抛出以下错误:plotly-latest.min.js:11 Error: <rect> attribute x: Expected length, "NaN".

【问题讨论】:

  • 现在的价值:我遇到了一个非常相似的问题,但使用当前版本的 Plotly 解决了。
  • @Christof:似乎需要用另一个反斜杠来转义反斜杠,至少在 JSfiddle 上是必需的。

标签: javascript plot plotly


【解决方案1】:

你需要对你的小提琴进行两个微小的改动。

  1. MathJax.js?config=TeX-AMS-MML_SVG 而不是 MathJax.js?config=TeX-MML-AM_CHTML
  2. 在您的代码/导入中,TeX 库必须来自 before Plotly

var trace1 = {
  x: [1, 2, 3, 4],
  y: [1, 4, 9, 16],
  name: '$\\alpha_{1c} = 352 \\pm 11 \\text{ km s}^{-1}$',
  type: 'scatter'
};
var trace2 = {
  x: [1, 2, 3, 4],
  y: [0.5, 2, 4.5, 8],
  name: '$\\beta_{1c} = 25 \\pm 11 \\text{ km s}^{-1}$',
  type: 'scatter'
};
var data = [trace1, trace2];
var layout = {
  xaxis: {title: '$\\sqrt{(n_\\text{c}(t|{T_\\text{early}}))}$'},
  yaxis: {title: '$d, r \\text{ (solar radius)}$'}
};
Plotly.newPlot('myDiv', data, layout);
<div id="myDiv" style="width:100%"></div>
<script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_SVG"></script>
<script src="https://cdn.plot.ly/plotly-latest.min.js"></script>

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2018-06-06
  • 1970-01-01
  • 1970-01-01
  • 2022-08-15
  • 1970-01-01
  • 2019-01-02
  • 1970-01-01
  • 2014-11-28
相关资源
最近更新 更多