matplotlib - increase resolution to see details


I have a big process that is composed of tasks (about 600), and I created a figure to watch the order they are launched with and the time they take. To do this, I used matplotlib and a barh.

The figure is ok (my 1st matplotlib success !), but:

  • I would like to see the details and zoom on the picture when exported (as PNG, for instance), as the zoom option allows when matplotlib displays the result with the show() command
  • the legends of the Y axis are too close and unreadable

I tried to increase the resolution as said in this other SO post, this is better but details are not precise enough. Here are my results so far:

  • full result


  • zoom with matplotlib


Do you know how I could improve readability ? Thanks a lot (else, all my efforts would be useless, I'm afraid...)

PS: I'm using matplotlib 1.1.1 and python 2.7.

5/23/2017 11:47:04 AM

Accepted Answer

Just for the record, I will put the suggestion done in my second comment here as a possible answer as well. This may not always work, but a test shows good results:

import pylab as pl
pl.figure(figsize=(7, 7))  # Don't create a humongous figure
pl.annotate(..., fontsize=1, ...)   # probably need the annotate line *before* savefig
pl.savefig('test.pdf', format='pdf')   # no need for DPI setting, assuming the fonts and figures are all vector based

It would appear even fractional fontsizes (e.g. fontsize=0.1) works. Your mileage may vary: I have tested this only with the PDF backend, not the EPS one.

Also: I have left out the DPI setting. When printing this on a high resolution printer, you may need it again. Then again, you shouldn't, as this likely is a printer setting instead: how the printer rasterizes your (vector) PDF image. I simply don't know if these kind of "hints" can be coded into postscript/PDF.

8/12/2015 1:25:39 PM

I managed to do so, on Evert's advice, by using a very big resolution with a very small font. Here are the most important steps:

import pylab as pl
pl.figure(figsize=(70, 70)) # This increases resolution
pl.savefig('test.eps', format='eps', dpi=900) # This does, too
pl.annotate(..., fontsize='xx-small', ...)

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow