阴谋Python如何绘制无界线和跨度? [英] Plotly python how to draw unbounded lines and spans?
本文介绍了阴谋Python如何绘制无界线和跨度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在IPython笔记本中使用plotly(脱机版本),我非常喜欢它.但是我找不到绘制垂直线或垂直带的方法.
I am using plotly (the offline version) within an IPython notebook and I like it a lot. However I couldn't find a way to plot a vertical line or a vertical band.
matplotlib中的等效项是:
The equivalents in matplotlib are:
import matplotlib.plyplot as plt
plt.axvline(x=0)
plt.axvspan(xmin=0, xmax=1)
预先感谢
推荐答案
您可以在图形布局中添加形状.形状可以包括线或矩形.也可以通过相对于绘图区域而不是特定轴进行绘制来使它们无边界.浏览绘制形状文档中的示例.
You can add shapes to your plotly layout. Shapes can include lines or rectangles. They can also be made unbounded by drawing them relative to the plotting area rather than a particular axis. Have a look through the examples in the 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如何绘制无界线和跨度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文