【问题标题】:Is there a way to add a margin line in Python-Plotly charts?有没有办法在 Python-Plotly 图表中添加边线?
【发布时间】:2020-02-10 04:25:52
【问题描述】:

默认情况下,Plotly 图表的绘图区域边缘没有“线条”。

我可以在 X 轴和 Y 轴上定义线,但不能在所有绘图区域中定义。

在布局中使用"template": "simple_white",可以得到如下图。

import numpy as np
import plotly.graph_objs as go
x = np.linspace(0,10,1000)
y = np.sin(x)
layout = {"template":"simple_white"}
data = go.Scatter(x=x,y=y)
fig = go.Figure(data,layout)
fig.show()

使用 Plotly 获得的图像

有没有办法用 Plotly 获得像下面这样的图像,即在绘图区域周围有线条?

它是用 matplotlib 包制作的。我的意思是:我可以有这样的图像,但使用 Plotly 包吗?

import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(0,10,1000)
y = np.sin(x)
plt.plot(x,y)
plt.show()

使用 Matplotlib 获得的图像

编辑:

可以在以下位置找到类似的问题:

Plotly: How to add borders and sidelabels to subplots, and syncronize panning?

但是,我想为其他用户维护这个,因为它直接到将边界放在一个情节中的地步。另一个问题包括其他功能。

【问题讨论】:

    标签: python matplotlib plotly plotly-python


    【解决方案1】:

    关键是使用另一个隐藏良好的 Plotly 属性mirror。像这样更新你的布局:

    import numpy as np
    import plotly.graph_objs as go
    
    x = np.linspace(0, 10, 1000)
    y = np.sin(x)
    layout = dict(
        template="simple_white",
        xaxis=dict(ticks="outside", mirror=True, showline=True),
        yaxis=dict(ticks="outside", mirror=True, showline=True),
    )
    data = go.Scatter(x=x, y=y)
    fig = go.Figure(data, layout)
    
    fig.show()
    

    这表明:

    【讨论】:

      猜你喜欢
      • 2022-11-10
      • 1970-01-01
      • 1970-01-01
      • 2019-09-01
      • 2021-05-08
      • 1970-01-01
      • 2020-12-14
      • 1970-01-01
      • 2023-02-15
      相关资源
      最近更新 更多