Har*_*wel 7 python matplotlib python-3.x
我正在尝试使用Python matplotlib打印600 dpi图表.但是,Python绘制了8个图中的2个,并输出错误:
OverflowError: Agg rendering complexity exceeded. Consider downsampling or decimating your data.
Run Code Online (Sandbox Code Playgroud)
我正在绘制一大块数据(每列7,500,000个数据)所以我想这要么是一些重载问题,要么我需要设置一个大的cell_block_limit.
我试图在Google上搜索更改cell_block_limit的解决方案,但无济于事.什么是好方法?
代码如下: -
import matplotlib.pyplot as plt
from matplotlib.ticker import MultipleLocator, FormatStrFormatter
majorLocator = MultipleLocator(200)
majorFormatter = FormatStrFormatter('%d')
minorLocator = MultipleLocator(20)
fig = plt.figure()
ax = fig.add_subplot(111)
ax.xaxis.set_major_locator(majorLocator)
ax.xaxis.set_major_formatter(majorFormatter)
ax.xaxis.set_minor_locator(minorLocator)
ax.xaxis.set_ticks_position('bottom')
ax.xaxis.grid(True,which='minor')
ax.yaxis.grid(True)
plt.plot(timemat,fildata)
plt.xlabel(plotxlabel,fontsize=14)
plt.ylabel(plotylabel,fontsize=14)
plt.title(plottitle,fontsize=16)
fig.savefig(plotsavetitle,dpi=600)
Run Code Online (Sandbox Code Playgroud)
Joe*_*ton 15
除了@Lennart指出不需要全分辨率之外,您还可以考虑类似于以下的情节.
如果使用原始数组的2D视图和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)
Run Code Online (Sandbox Code Playgroud)
