]> git.cworth.org Git - cworth.org/blob - src/matplotlib.mdwn
Add Robert Haight as another solver
[cworth.org] / src / matplotlib.mdwn
1 [[!meta title="Looking at matplotlib's cairo backend"]]
2
3 [[!tag cairo exa xorg]]
4
5 The [matplotlib](http://matplotlib.sourceforge.net/) project looks
6 like an interesting approach for generating charts and things. I used
7 it (and its cairo backend, plus a couple of patches to snap lines to
8 pixel boundaries), to generate the following chart:
9
10 [[exa/i965/avoiding_rmw/i965.png]]
11
12 That chart still isn't perfect as I'd really prefer the spacing
13 between each of the bars to be consistent, (if you look closely at the
14 above, you'll notice that some are spaced by 1 pixel and some are
15 spaced by 2 pixels). Maybe that's a bug in the python script I wrote
16 to generate the chart, (I'm totally python-clueless).
17
18 I sent the pixel-snapping patches up to the matplotlib project, so
19 maybe they'll go somewhere.
20
21 In the meantime, there's been a recent [discussion][1] of how good
22 matplotlib's cairo backend is compared to some of the others. Here are
23 some files generated by the unicode_demo example script with
24 matplotlib 0.87.7, (apparently old, as I see mention of 0.90.1 on the
25 matplotlib website), and cairo 1.4.10 (or something very close to
26 it). Note: This is without any of my pixel-snapping patches.
27
28 Cairo backend
29 =============
30  * PNG (19023 bytes): [[unicode_demo-cairo.png]]
31
32  * PDF (15786 bytes): [[unicode_demo-cairo.pdf]]
33
34  * PostScript (49279 bytes): [[unicode_demo-cairo.ps]]
35
36  * SVG (89560 bytes): [[unicode_demo-cairo.svg]]
37
38 All four of those seem to render fine for me, (with evince, gv, and
39 rsvg-view, for example). For comparison here are files generated with
40 other existing matplotlib backends.
41
42 AGG backend
43 ===========
44  * PNG (19769 bytes): [[unicode_demo-agg.png]]
45
46 PDF backend
47 ===========
48  * PDF (43539): [[unicode_demo-pdf.pdf]]
49
50 PS backend
51 ==========
52  * PostScript (136021 bytes): [[unicode_demo-ps.ps]]
53
54 SVG backend
55 ===========
56  * SVG (7660 bytes): [[unicode_demo-svg.svg]]
57
58 Results
59 =======
60 All of the cairo results appear to render correctly for me, (using
61 firefox, evince, gv, and rsvg-view). The PDF generated by the builtin
62 PDF backend renders with ? characters instead of any of the non-ASCII
63 glyphs. Also, when rendering the SVG generated by the builtin SVG
64 backend, the text is not scaled/positioned correctly, (the numbers
65 overlap the axes, the title at the bottom extends beyond the right
66 edge instead of being centered, etc.).
67
68 Meanwhile, there are a few notable deviations in size from the
69 backends:
70
71  * Using cairo for PostScript or PDF output results in a file that is
72    2.75x smaller than using the builtin PS or PDF backends.
73
74  * Using cairo for SVG output results in a file that is more than 10
75    times larger, (it's actually embedding the glyph data for all of the
76    text characters that appear in the file).
77
78 [1]: http://sourceforge.net/mailarchive/forum.php?thread_name=88e473830707051126uab036cfl2e5bd91bcad72df4%40mail.gmail.com&forum_name=matplotlib-devel