Thursday 15 March 2012

python - .png file not saving correctly matplotlib -



python - .png file not saving correctly matplotlib -

while saving multiple grid figure in png 300 dpi, lose quality

however error not occur while saving figure pdf.

here little portion of code saves image generated:

fig.savefig(filepath, format = 'pdf' ,bbox_inches='tight',dpi=300) fig.savefig(filepath, format = 'png' ,bbox_inches='tight',dpi=300)

is there way obtain resolution png of image such above without having resort using pdf?

.pdf images vector graphics, , preserve information. in other words setting dpi=300 in pdf creation doesn't (unless have set specific objects rasterized using rasterized = true).

.png images raster graphics (e.g. check out). hence have adjust dpi balance of filesize vs. quality want. in other words, image is saving correctly, it's lower quality 'perfect' pdf.

the selection of image output format depends on how utilize it. vector graphics (.pdf, .svg) great if have simple plots want scale (zoom) perfectly. however, if plotting many points (>10,000 or so), can lead big filesizes. in case may improve rasterize figure because person can't see many info points anyway.

"which raster format should use?" .png , .jpg common. former has improve compression images big patches of same color, while latter has improve compression high pixel variability (e.g. photographs). check out more info.

note while .png considered 'lossless', in sense preserves rasterized information. info still lost when saving/converting rasterized format.

python pdf matplotlib png

No comments:

Post a Comment