如何制作没有标记点的 Plotly 散点图?

How to make a Plotly scatter plot without marker dots?

我正在尝试创建一系列带阴影线的方形 PNG - 类似于页面末尾 here 显示的样本。

这些不能在网络上使用 - 所以我认为使用 textures.js 会太迂回,我偶然发现了 Plotly,特别是 this

我做到了这一点

import plotly.express as px
import plotly.graph_objects as go

xy = [
    [0, 0], [1, 0], [1, 1], [0, 1], [0, 0]
]


fig = go.Figure(go.Scatter(x=[ co[0] for co in xy ], y=[ co[1] for co in xy ],
                           fill="toself", marker={'size': 0 }
))

fig.update_layout(showlegend=False)
fig.update_xaxes(visible=False)
fig.update_yaxes(visible=False)

img_bytes = fig.to_image(format="png")


fig.write_image("foo.png")

生成这个:

但我努力不显示矩形角上的点。

我该怎么做?我知道没有点的散点图有点荒谬,所以如果有更清晰的解决方案也很好。

(我想我会弄清楚如何没有线条和背景以及如何用影线填充它 - 但也欢迎提供帮助)

尝试使用标记不透明度:

fig = go.Figure(go.Scatter(x=[ co[0] for co in xy ], y=[ co[1] for co in xy ],
                           fill="toself", marker={'opacity': 0}
))

绘制无线无标记

fig = go.Figure(go.Scatter(x=[ co[0] for co in xy ], y=[ co[1] for co in xy ],
                           fill="toself", mode='text'
))

不带标记但带线的绘图

fig = go.Figure(go.Scatter(x=[ co[0] for co in xy ], y=[ co[1] for co in xy ],
                           fill="toself", mode='lines'
))

只需添加以下行:

mode ="lines",

查看总代码:

import plotly.express as px
import plotly.graph_objects as go

xy = [    [0, 0], [1, 0], [1, 1], [0, 1], [0, 0]]

fig = go.Figure(go.Scatter(x=[ co[0] for co in xy ], y=[ co[1] for co in xy ],
                           fill="toself",
                           mode ="lines",
                        #    marker={'size': 0 }
))

fig.update_layout(showlegend=False)
fig.update_xaxes(visible=False)
fig.update_yaxes(visible=False)

img_bytes = fig.to_image(format="png")
fig.write_image("foo.png")