python - Plotly python 如何绘制无界线和跨度?

标签 python plotly

我在 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/

相关文章:

python - 在 Python 中从 SWIG 实例化 shared_ptr 对象

python - 如何使用 `argparse` 从命令行和代码传递参数?

Python - 如果列名包含特定字符串,则更改该列中的值,否则值保留

Python:生成所有长度为 N 的唯一有序列表

python - 在 Python 中绘制 : How to add legend when using matplotlib?

r - 同时使用 formattable 和 plotly

python - 仅实时更新 Dash/plotly 中的数据

python - 让 Django 和 Buildout 工作,但是 PIL 和 Postgres 呢?

plotly - 在 Plotly/Dash 下拉列表中添加 'Select All' 选项