Matplotlib Agg渲染复杂度E

2024-10-02 02:34:23 发布

您现在位置:Python中文网/ 问答频道 /正文

我尝试使用Python matplotlib打印一个600 dpi的图形。但是Python绘制了8个图形中的2个,并输出错误:

OverflowError: Agg rendering complexity exceeded. Consider downsampling or decimating your data.

我正在绘制一个巨大的数据块(每列7500000个数据),所以我想要么这将是一些重载问题,要么我需要设置一个大的单元格块的限制。在

我试图寻找解决方案,以改变谷歌的细胞块限制,但没有结果。什么是好方法?在

代码为以下内容:-在

^{pr2}$

Tags: or数据图形matplotlib错误绘制aggcomplexity
2条回答

除了@Lennart认为不需要完整的分辨率之外,您还可以考虑一个类似于下面的图。在

如果使用原始数组的二维视图和axis关键字arg到x.min()x.max()等,计算“分块”版本的最大/平均/最小值非常简单和高效

即使使用了过滤,绘制它也比绘制整个数组快得多。在

(注:要想画出这么多点,你得把噪音调小一点。否则你会得到你提到的OverflowError。如果要比较绘制“完整”数据集,请将y += 0.3 * y.max() np.random...行改为更像0.1或完全删除它。)

import matplotlib.pyplot as plt
import numpy as np
np.random.seed(1977)

# Generate some very noisy but interesting data...
num = 1e7
x = np.linspace(0, 10, num)
y = np.random.random(num) - 0.5
y.cumsum(out=y) 
y += 0.3 * y.max() * np.random.random(num)

fig, ax = plt.subplots()

# Wrap the array into a 2D array of chunks, truncating the last chunk if 
# chunksize isn't an even divisor of the total size.
# (This part won't use _any_ additional memory)
chunksize = 10000
numchunks = y.size // chunksize 
ychunks = y[:chunksize*numchunks].reshape((-1, chunksize))
xchunks = x[:chunksize*numchunks].reshape((-1, chunksize))

# Calculate the max, min, and means of chunksize-element chunks...
max_env = ychunks.max(axis=1)
min_env = ychunks.min(axis=1)
ycenters = ychunks.mean(axis=1)
xcenters = xchunks.mean(axis=1)

# Now plot the bounds and the mean...
ax.fill_between(xcenters, min_env, max_env, color='gray', 
                edgecolor='none', alpha=0.5)
ax.plot(xcenters, ycenters)

fig.savefig('temp.png', dpi=600)

enter image description here

如果使用600dpi,则必须使绘图宽度为13米才能绘制数据,而不会造成数据损失。:-)

我建议将数据分成几百个甚至一千个样本,然后从中提取最大值。在

像这样:

def chunkmax(data, chunk_size):
    source = iter(data)
    chunk = []
    while True:
        for i in range(chunk_size):
            chunk.append(next(source))

        yield max(chunk)

然后,如果chunk_的大小为1000,就可以得到7500个点来绘制,在那里你可以很容易地看到数据中的冲击来自何处。(除非数据非常嘈杂,否则您必须将其平均,以查看是否存在阻塞。但这也很容易解决)。在

相关问题 更多 >

    热门问题