使用Python在Plotly中的绘图上添加常规文本标签

使用Python在Plotly中的绘图上添加常规文本标签,python,matplotlib,plot,histogram,plotly,Python,Matplotlib,Plot,Histogram,Plotly,在Matplotlib中,可以使用以下代码: import matplotlib.pyplot as plt import numpy as np np.random.seed(1234) fig, ax = plt.subplots(1) x = 30*np.random.randn(10000) mu = x.mean() median = np.median(x) sigma = x.std() textstr = '$\mu=%.2f$\n$\mathrm{median}=%.2f$\n

在Matplotlib中,可以使用以下代码:

import matplotlib.pyplot as plt
import numpy as np
np.random.seed(1234)
fig, ax = plt.subplots(1)
x = 30*np.random.randn(10000)
mu = x.mean()
median = np.median(x)
sigma = x.std()
textstr = '$\mu=%.2f$\n$\mathrm{median}=%.2f$\n$\sigma=%.2f$'%(mu, median, sigma)

ax.hist(x, 50)
# these are matplotlib.patch.Patch properties
props = dict(boxstyle='round', facecolor='wheat', alpha=0.5)

# place a text box in upper left in axes coords
ax.text(0.05, 0.95, textstr, transform=ax.transAxes, fontsize=14,
        verticalalignment='top', bbox=props)
要创建以下直方图,请使用文本标签

但是,在Plotly中,我找不到如何在绘图上创建类似的标签。似乎任何注释都必须附加到数据点。
是否可以使用Plotly向绘图中添加常规文本标签(如上例所示)?

您可以为要显示的图例命名跟踪。请注意,如果只有一个跟踪,还需要添加到布局中

标签可以包含LaTeX代码。您需要导入MathJax库并转义每个反斜杠

或者,您可以向布局中添加注释,例如:

annotations: [
    {
      x: -0.7,
      y: 800 ,
      text: '$\\mu = 0\\\\ \\sigma = 1$',
      showarrow: false,
    }]
var number=[];
风险价值总额=100000;
对于(变量i=0;i

未来的注意:cdn.mathjax.org即将结束,请查看迁移提示。