Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Investigate alternative svg renderers for the test suite #8242

Copy link
Copy link
Closed
@anntzer

Description

@anntzer
Issue body actions

Using rsvg as SVG renderer in the tests is much faster than using inkscape: with the following simple patch:

diff --git a/lib/matplotlib/testing/compare.py b/lib/matplotlib/testing/compare.py
index ab2f26fc0..a90a75901 100644
--- a/lib/matplotlib/testing/compare.py
+++ b/lib/matplotlib/testing/compare.py
@@ -138,9 +138,16 @@ def _update_converter():
         converter['eps'] = make_external_conversion_command(cmd)
 
     if matplotlib.checkdep_inkscape() is not None:
-        def cmd(old, new):
-            return [str('inkscape'), '-z', old, '--export-png', new]
-        converter['svg'] = make_external_conversion_command(cmd)
+        import cairo
+        from gi.repository import Rsvg
+        def convert(old, new):
+            svg = Rsvg.Handle().new_from_file(old)
+            svg.set_dpi(96)
+            surf = cairo.ImageSurface(
+                cairo.FORMAT_ARGB32, svg.props.width, svg.props.height)
+            svg.render_cairo(cairo.Context(surf))
+            surf.write_to_png(new)
+        converter['svg'] = convert
 
 
 #: A dictionary that maps filename extensions to functions which

the entire test suite runs in 594s instead of 787s on my laptop. (There's also a ton of image comparison failures, but that's because my cache (which I did not regenerate in either case) is generated by inkscape and there seems to be pixel-level differences between the two renderers -- but that won't be a problem in practice as all we'll want to do is to compare svgs rendered by the same engine.)

There are also a few constructs that are not correctly rendered by rsvg but perhaps it's a good opportunity to try to generate slightly less demanding svgs... and again in any case we're still comparing the same misrendering by the same engine :-)

The real problem right now is whether there is an easy way to install rsvg on Windows. There is an official .exe installer on Windows (https://wiki.gnome.org/action/show/Projects/PyGObject?action=show&redirect=PyGObject) which I haven't tried; I haven't found a pip package; there are a few user-submitted conda packages (search for pygobject/pygobject3) but none of them seem to work on Py3.

Alternatively, I have tried two other renderers: QtSVG (http://doc.qt.io/qt-5/qtsvg-index.html) and cairosvg (http://cairosvg.org/, which only supports Py3, but could be used as a standalone script that lives in its own environment, similarly to inkscape). QtSVG is a very, very limited SVG renderer so I'd rather not use it (unless we can make our svg output compatible with it); cairosvg seems to freeze(?) on at least one of our constructs.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.