3

When using Matplotlib to generate figures with hatching (e.g. pie, bar, bubble charts), I'm having some trouble getting decent resolution out of the PDF version of the figure. Saving as EPS is fine, but as soon as I use epstopdf or MPL's savefig(*.pdf), the hatching becomes pixellated and distored... the vector nature of the image appears to have been lost.

See minimal code below.

from matplotlib import pyplot as plt

# Define hatching styles
hatching = ["/", "o"]

fig, ax = plt.subplots()
wedges, texts = ax.pie([0.4, 0.6], colors=("SteelBlue", "Tomato"))

# Apply the hatching
for j, patch in enumerate(wedges): patch.set_hatch(hatching[j])

fig.savefig("hatchtest.pdf")

I've used Gimp to zoom in on a part of the plot to illustrate the difference...

Zoomed in on the EPS figure Generated with EPS terminal

Zoomed in on the PDF figure Generated with PDF terminal

As for system specific details, I'm using Ubuntu 13.04, Python 2.7.4 with MPL 1.2.1. I've tried different backends but nothing seems to resolve this. I'd ideally like to have nice vector images in EPS and PDF so that it's all journal-friendly. Any pointers would be much appreciated.

William Menz
  • 131
  • 1
  • 8

1 Answers1

5

Just a problem with Evince PDF viewer. Viewing in Adobe Reader or printing the plot gives the desired result.

William Menz
  • 131
  • 1
  • 8
  • reminds me of an issue I had, where a contour plot was showing thin white lines in some PDF viewers, outlining the polygon mesh structure on which the contour plot was constructed. Turned out that some PDF viewers anti-alias the patches against the white paper colour in the background, not against the adjacent coloured patch. Solved by creating a mesh plot with mesh lines coloured by the same contour levels as the main plot, and putting that in the background of each figure ... – Zak Jan 11 '23 at 14:41