我在 IPython 笔记本中使用 plotly(离线版本),我非常喜欢它。但是我找不到绘制垂直线或垂直带的方法。
matplotlib 中的等价物是:
import matplotlib.plyplot as plt
plt.axvline(x=0)
plt.axvspan(xmin=0, xmax=1)
提前致谢
最佳答案
您可以将形状添加到绘图布局中。形状可以包括线条或矩形。也可以通过相对于绘图区域而不是特定轴绘制它们来使它们不受限制。查看 plotly shapes docs 中的示例.
layout = {
'title': "My Chart",
'shapes': [
{ # Unbounded line at x = 4
'type': 'line',
# x-reference is assigned to the x-values
'xref': 'x',
# y-reference is assigned to the plot paper [0,1]
'yref': 'paper',
'x0': 4,
'y0': 0,
'x1': 4,
'y1': 1,
'line': {
'color': 'rgb(55, 128, 191)',
'width': 3,
}
},
{ # Unbounded span at 6 <= x <= 8
'type': 'rect',
# x-reference is assigned to the x-values
'xref': 'x',
# y-reference is assigned to the plot paper [0,1]
'yref': 'paper',
'x0': 6,
'y0': 0,
'x1': 8,
'y1': 1,
'fillcolor': '#d3d3d3',
'opacity': 0.2,
'line': {
'width': 0,
}
}
],
}
关于python - Plotly python 如何绘制无界线和跨度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38150362/