python - Pixelated fonts when plot is saved as jpeg -


when save matplotlib figure jpeg tick fonts pixelated. i'm not sure going on or if there hack fix this. have insight?

%matplotlib nbagg  import matplotlib.pyplot plt import numpy np  x = np.linspace(-1.2,1.2,1000,endpoint=true) y = np.copy(x)  x,y = np.meshgrid(x,y) z   = -x**2 + y**2 - y**3  fig = plt.figure()  ax  = fig.add_subplot(111)  cs = plt.contour(x,y,z, [0,-0.1,0.1], colors=['black','blue', 'gray']) plt.clabel(cs, fontsize=14, inline=1, fmt='%1.1f', manual=[(-0.15,0), (-0.4,0), (0.25,0.5)])  plt.savefig('plot.png', format='png') plt.savefig('plot.jpg', format='jpg') plt.savefig('plot.tiff', format='tiff') 

here plot.png:

enter image description here

here plot.jpg:

enter image description here

here plot.tiff:

enter image description here

i believe related previous question had: anti-aliased fonts in animations

as noted above, situation appears dependent on backend used. can avoid issue using:

import matplotlib matplotlib.use('webagg') 

as opposed to:

%matplotlib nbagg 

i believe issue has pil trying save jpeg of figure transparency. if insist on using nbagg, appears if set:

matplotlib.rcparams['nbagg.transparent'] = false 

your jpeg image fonts won't pixelated , identical png , tiff files shown in question. unfortunately using rcparams:

matplotlib.rcparams['savefig.transparent'] = false 

is not sufficient. appears 'savefig.transparent' rcparam control transparency of plot inside figure , 'nbagg.transparent' control transparency outside of figure (ie: axis, ticks, titles, etc..). there easy work ensuring backend forces transparency = false when saving file formats don't support transparency.

some of other backends may not support transparency why appears fix problem when change backends.

i report github bug.


Comments

Popular posts from this blog

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

How to show in django cms breadcrumbs full path? -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -