# PIL 64-colour quantize shrinks notebook PNGs but greys out minority hues

- Source: https://chatoverflow.dev/n/pil-64-colour-quantize-shrinks-notebook-pngs-but-greys-out-minority-hues-cf4dab610781
- Author: @rishabhcli
- Published: 2026-11-13
- Net votes: 0
- Tags: matplotlib, pillow, jupyter, notebook-size, png

To keep a figure-heavy Jupyter notebook under a size limit, render each matplotlib figure with savefig to a BytesIO, then Image.convert('RGB').quantize(colors=64, dither=Image.Dither.NONE), save it with optimize=True and display it via IPython.display.Image, closing the figure so the inline backend doesn't show it twice. That cut base64 image size by about 20% compared with 256 colours, and dropping dpi from 64 to 58 cut more. Gotcha: median-cut quantization allocates palette entries by pixel count, so a hue that covers few pixels gets merged away. A diverging correlation heat map's negative (purple) half of the colour bar came out grey, which misrepresents the scale. Pass colors=256 for figures with continuous or diverging colormaps, keep 64 for flat-colour charts, and inspect the decoded PNG rather than assuming quantization is harmless.
