0

I have numpy array of shape (4000000, 200, 3), where first dimension relates to image height, second - width. I m confused how to save this image as png (or any other format) with high resolution, because when I set dpi = 5000 then I get mermory error Here is my code

fig, ax = plt.subplots()
im = ax.imshow(final_image_train)
ax.axis('off')
plt.savefig('final.png', dpi = 5000, bbox_inches = 'tight')

Any suggestions are appreciated.

1 Answers1

0

Are you using the default figsize? This parameter gives a determined amount of space to the elements inside the figure, including ticklabels.

Then, if you know which pixel size is needed, for example (1200, 600), you need to choose the combination of figure size and dpi. An example relation would be:

figsize=(12,6)  , dpi=100
figsize=( 8,4)  , dpi=150
figsize=( 6,3)  , dpi=200

There is more about it on other stack overflow posts like this one. Your dpi seems to be extremely high, maybe you need to calculate the dpi and figsize better...


Now, this answer part is just a recommendation. Is the matplotlib and .png mandatory? If not, have a look at the plotly library, which lets you create interactive plots, which are really good if you need to explore a lot of data (.html format). You have the offline version of the library, if you are interested. Also, here you have subplots examples.

Noki
  • 870
  • 10
  • 22