使用许多数据点散布图会产生模糊的 svg

Plotly scatter with many datapoints yield blurry svg

当我将包含 10000 个数据点的散点图导出为 fig.write_image("filename.svg")recommended by plotly 的 svg 时,我得到了一个模糊的 svg。将数据下采样到 1000 个数据点确实会产生一个保持清晰的漂亮矢量图像。清晰图像和像素化图像之间的界限介于 1000 和 1500 个散点之间,因为下采样到 1500 会再次产生像素化图像。

我想导出包含超过 1000 个数据点的图形,我该如何避免这种情况。

import pandas as pd
import plotly.express as px
import numpy as np
df = pd.DataFrame(np.random.randn(10000, 2), columns=list('XY'))
fig =px.scatter(df, x='X', y='Y')
fig.write_image("images/fig1.svg")

10000 点

1500 点

1000 点

(由于 Whosebug 不允许 .svg 图片,我不得不截屏)

它在我的桌面上看起来很好,有 10000 分: 有没有可能是显卡问题?

我相信答案是 here in the plotly documentation px.scatter...

render_mode (str) – One of 'auto', 'svg' or 'webgl', default 'auto' Controls the browser API used to draw marks. 'svg’ is appropriate for figures of less than 1000 data points, and will allow for fully-vectorized output. 'webgl' is likely necessary for acceptable performance above 1000 points but rasterizes part of the output. 'auto' uses heuristics to choose the mode.

如果您添加 render_mode = 'svg',您应该会看到这种像素化消失。

fig =px.scatter(df, x='X', y='Y', render_mode = 'svg')