matplotlib/matplotlib — Issue #719: Bad font hinting / quality with Agg renderer
Author: jimparis
Created: 2012-02-27 00:09:24+00:00
State: open

When using the `agg` backend to create PNGs, fonts are poorly hinted, and always look blurry. Setting `text.hinting = True` has no effect.

The below script creates two images that demonstrate the problem. It generates some text in multiple sizes, with both the `agg` and the `cairo` backends. While the progression of sizes generally looks smoother with the `agg` backend, there seems to be no way to replicate the crispness of the `cairo` backend, particularly around sizes 9, 10, 11, and 12.

I have copies of the images, and zoomed-in versions for comparision, available at
http://jim.sh/~jim/tmp/matplotlib-font

```python
# Test rendering of different font sizes with Cairo vs. Agg backend

import sys, os
if "DISPLAY" in os.environ:
del os.environ["DISPLAY"]

for backend in [ 'cairo', 'agg' ]:
# Reload with proper backend
print "Rendering with " + backend
for module in list(sys.modules):
if module.startswith(('matplotlib','pylab')):
sys.modules.pop(module)
import matplotlib
matplotlib.use(backend)
import pylab

# This has no effect, but try it anyway
matplotlib.rcParams['text.hinting'] = True

# Make plot
fig = pylab.figure(figsize=[2,5])
ax = fig.add_subplot(1,1,1)
ax.set_frame_on(False)
ax.axes.get_xaxis().set_visible(False)
ax.axes.get_yaxis().set_visible(False)
ax.set_xlim([0, 1])
ax.set_ylim([15, 0])
pylab.title(backend)

for size in range(1,25):
ax.text(0.1, (size ** 1.6) / 10, "hello " + str(size),
fontdict = { "size" : size, "family" : "arial" })
pylab.savefig("test-" + backend + ".png", format="png")
pylab.clf()
```