Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I have fixed this in my matplotlib source, but it's not a pretty fix. However, if you, like me, are very particular about how the graph looks, it's worth it.</p> <p>The issue seems to be in the rendering backends; they each get the correct values for linewidth, font size, etc., but that comes out slightly larger when rendered as a PDF or PNG than when rendered with show().</p> <p>I added a few lines to the source for PNG generation, in the file matplotlib/backends/backend_agg.py. You could make similar changes for each backend you use, or find a way to make a more clever change in a single location ;)</p> <p>Added to my matplotlib/backends/backend_agg.py file:</p> <pre><code> # The top of the file, added lines 42 - 44 42 # @warning: CHANGED FROM SOURCE to draw thinner lines 43 PATH_SCALAR = .8 44 FONT_SCALAR = .95 # In the draw_markers method, added lines 90 - 91 89 def draw_markers(self, *kl, **kw): 90 # @warning: CHANGED FROM SOURCE to draw thinner lines 91 kl[0].set_linewidth(kl[0].get_linewidth()*PATH_SCALAR) 92 return self._renderer.draw_markers(*kl, **kw) # At the bottom of the draw_path method, added lines 131 - 132: 130 else: 131 # @warning: CHANGED FROM SOURCE to draw thinner lines 132 gc.set_linewidth(gc.get_linewidth()*PATH_SCALAR) 133 self._renderer.draw_path(gc, path, transform, rgbFace) # At the bottom of the _get_agg_font method, added line 242 and the *FONT_SCALAR 241 font.clear() 242 # @warning: CHANGED FROM SOURCE to draw thinner lines 243 size = prop.get_size_in_points()*FONT_SCALAR 244 font.set_size(size, self.dpi) </code></pre> <p>So that suits my needs for now, but, depending on what you're doing, you may want to implement similar changes in other methods. Or find a better way to do the same without so many line changes!</p> <p><strong>Update:</strong> After posting an issue to the matplotlib project at Github, I was able to track down the source of my problem: I had changed the figure.dpi setting in the matplotlibrc file. If that value is different than the default, my savefig() images come out different, even if I set the savefig dpi to be the same as the figure dpi. So, instead of changing the source as above, I just kept the figure.dpi setting as the default 80, and was able to generate images with savefig() that looked like images from show(). </p> <p>Leon, had you also changed that setting?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload