0

Try to save extra large array (~5 000 000 , 200) as an image but matplotlib raise ValueError: Image size of 4741988x210 pixels is too large. It must be less than 2^16 in each direction

Here is the code:

from matplotlib.ticker import FixedLocator, FixedFormatter
fig = plt.figure(figsize = (4741988,210), frameon=False, dpi = 1)

ax = fig.gca()
ax.imshow(final_image_train)

y_formatter = FixedFormatter(np.arange(start_len_train,end_len_train+1,1))
y_locator = FixedLocator(np.linspace(0, final_image_train.shape[0], end_len_train - start_len_train))

ax.yaxis.set_major_formatter(y_formatter)
ax.yaxis.set_major_locator(y_locator)

ax.tick_params(axis="y", labelsize=1, length = 2, width = 0.1, grid_linewidth = 0.01, pad = 0.1)
plt.xticks([])

ax.patch.set_visible(False)
plt.box(on=None)

plt.savefig('test.svg', bbox_inches='tight', pad_inches = 0)

So I wonder is there way to save such image in a high quality? Why mpl constrain max size by 2^16. My machine equipped with 32gb RAM. Maybe we have any other packages except matplotlib to handle such large arrays? Any suggestions will be appreciated

0 Answers0