41

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

full

  • zoom with matplotlib

zoom

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.

Community
  • 1
  • 1
Emmanuel
  • 13,935
  • 12
  • 50
  • 72
  • The resolution looks fine. I guess your point is the readability on the axes? Just try decreasing the font size for the axis labels. If something else, you'd have to clearer about what you want. For best resolution, export to postscript or PDF; these formats is vector based, and normally keep the full resolution. Just keep in mind that such files may grow large this way (and take a while to be generated). If you want a PNG, just make it a huge figure with normal resolution (dpi); it's inherent to a rasterized image type like PNG that you can't endlessly zoom in. –  Aug 30 '12 at 09:21
  • I just tried something else: adding annotations instead of labelling on the axis. But the same problem remains: since I have over 600 values, even fontsize 'xx-small' is not enough. What I'd really like is to have the annotation text size the same height as the chart items, is this possible ? Then I'd just generate with a very big resolution, so that I could zoom inside as much as I want. – Emmanuel Aug 30 '12 at 11:47
  • 2
    What if you make a very large figure? That would work if font size doesn't scale (since it's normally defined in points), but the bars do scale with the figure size. Of course, such a figure is a bit awkward to "drag around" or print, but at that point, you can rescale it. Or, for a normal sized figure, try using a fontsize of 1 (integer) instead of a string. That worked for me. –  Aug 30 '12 at 12:21

2 Answers2

43

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', ...)
Community
  • 1
  • 1
Emmanuel
  • 13,935
  • 12
  • 50
  • 72
25

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.