繁体   English   中英

plotly:大量数据点

[英]plotly: huge number of datapoints

我正在尝试使用 plotly 绘制具有大量数据点(2mm-3mm)的东西。

当我跑

py.iplot(fig, filename='test plot')

我收到以下错误:

Woah there! Look at all those points! Due to browser limitations, the Plotly SVG drawing functions have a hard time graphing more than 500k data points for line charts, or 40k points for other types of charts. Here are some suggestions:
(1) Use the `plotly.graph_objs.Scattergl` trace object to generate a WebGl graph.
(2) Trying using the image API to return an image instead of a graph URL
(3) Use matplotlib
(4) See if you can create your visualization with fewer data points

If the visualization you're using aggregates points (e.g., box plot, histogram, etc.) you can disregard this warning.

那么我尝试用这个保存它:

py.image.save_as(fig, 'my_plot.png')

但是后来我收到了这个错误:

PlotlyRequestError: Unknown Image Server Error

我该如何正确执行此操作? 我不在乎它是我笔记本中的静止图像还是交互式显示。

一种选择是对您的数据进行下采样,不确定您是否愿意: https : //github.com/devoxi/lttb-py

我在浏览器中有大数据集的 plotly 也有问题 - 如果有人有解决方案,请写! 谢谢!

Plotly 在这方面似乎真的很糟糕。 我只是想创建一个有 500 万个点的箱线图,这在简单的 R 函数“箱线图”中没有问题,但情节图为此无休止地计算。

改善这一点应该是一个主要问题。 并非所有数据都必须保存(和显示)在 plotly 对象中。 这是我猜的主要问题。

您可以尝试使用render_mode参数。 例子:

import plotly.express as px
import pandas as pd
import numpy as np

N = int(1e6) # Number of points

df = pd.DataFrame(dict(x=np.random.randn(N),
                       y=np.random.randn(N)))

fig = px.scatter(df, x="x", y="y", render_mode='webgl')
fig.update_traces(marker_line=dict(width=1, color='DarkSlateGray'))
fig.show()

在我的电脑中N=1e6大约需要 5 秒才能看到情节,“交互性”仍然非常好。 N=10e6时,大约需要 1 分钟,并且绘图不再响应(即缩放、平移或任何操作都非常慢)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM