Skip to content

BUG: TypeError in cairo backend at plt.savefig #12794

Closed
@jor-

Description

@jor-

Saving a figure with plt.savefig in svg file format using the cairo backend results in a TypeError. The Traceback is:

  /sfs/fs5/home-sh/sunip229/opt/miniconda3/envs/py37_forge_jore/lib/python3.7/site-packages/util/plot.py(814)save_and_close_fig()
-> plt.savefig('plot.svg', transparent=True, dpi=800)
  /sfs/fs5/home-sh/sunip229/opt/miniconda3/envs/py37_forge_jore/lib/python3.7/site-packages/matplotlib/pyplot.py(689)savefig()
-> res = fig.savefig(*args, **kwargs)
  /sfs/fs5/home-sh/sunip229/opt/miniconda3/envs/py37_forge_jore/lib/python3.7/site-packages/matplotlib/figure.py(2094)savefig()
-> self.canvas.print_figure(fname, **kwargs)
  /sfs/fs5/home-sh/sunip229/opt/miniconda3/envs/py37_forge_jore/lib/python3.7/site-packages/matplotlib/backend_bases.py(2075)print_figure()
-> **kwargs)
  /sfs/fs5/home-sh/sunip229/opt/miniconda3/envs/py37_forge_jore/lib/python3.7/site-packages/matplotlib/backends/backend_cairo.py(569)print_svg()
-> return self._save(fobj, 'svg', *args, **kwargs)
  /sfs/fs5/home-sh/sunip229/opt/miniconda3/envs/py37_forge_jore/lib/python3.7/site-packages/matplotlib/backends/backend_cairo.py(622)_save()
-> self.figure.draw(renderer)
  /sfs/fs5/home-sh/sunip229/opt/miniconda3/envs/py37_forge_jore/lib/python3.7/site-packages/matplotlib/artist.py(50)draw_wrapper()
-> return draw(artist, renderer, *args, **kwargs)
  /sfs/fs5/home-sh/sunip229/opt/miniconda3/envs/py37_forge_jore/lib/python3.7/site-packages/matplotlib/figure.py(1649)draw()
-> renderer, self, artists, self.suppressComposite)
  /sfs/fs5/home-sh/sunip229/opt/miniconda3/envs/py37_forge_jore/lib/python3.7/site-packages/matplotlib/image.py(138)_draw_list_compositing_images()
-> a.draw(renderer)
  /sfs/fs5/home-sh/sunip229/opt/miniconda3/envs/py37_forge_jore/lib/python3.7/site-packages/matplotlib/artist.py(50)draw_wrapper()
-> return draw(artist, renderer, *args, **kwargs)
  /sfs/fs5/home-sh/sunip229/opt/miniconda3/envs/py37_forge_jore/lib/python3.7/site-packages/matplotlib/axes/_base.py(2628)draw()
-> mimage._draw_list_compositing_images(renderer, self, artists)
  /sfs/fs5/home-sh/sunip229/opt/miniconda3/envs/py37_forge_jore/lib/python3.7/site-packages/matplotlib/image.py(138)_draw_list_compositing_images()
-> a.draw(renderer)
  /sfs/fs5/home-sh/sunip229/opt/miniconda3/envs/py37_forge_jore/lib/python3.7/site-packages/matplotlib/artist.py(50)draw_wrapper()
-> return draw(artist, renderer, *args, **kwargs)
  /sfs/fs5/home-sh/sunip229/opt/miniconda3/envs/py37_forge_jore/lib/python3.7/site-packages/matplotlib/legend.py(646)draw()
-> self.legendPatch.draw(renderer)
  /sfs/fs5/home-sh/sunip229/opt/miniconda3/envs/py37_forge_jore/lib/python3.7/site-packages/matplotlib/artist.py(50)draw_wrapper()
-> return draw(artist, renderer, *args, **kwargs)
  /sfs/fs5/home-sh/sunip229/opt/miniconda3/envs/py37_forge_jore/lib/python3.7/site-packages/matplotlib/patches.py(535)draw()
-> renderer.draw_path(gc, tpath, affine, rgbFace)
  /sfs/fs5/home-sh/sunip229/opt/miniconda3/envs/py37_forge_jore/lib/python3.7/site-packages/matplotlib/backends/backend_cairo.py(239)draw_path()
-> _append_path(ctx, path, transform, clip)
  /sfs/fs5/home-sh/sunip229/opt/miniconda3/envs/py37_forge_jore/lib/python3.7/site-packages/matplotlib/backends/backend_cairo.py(163)_append_path()
-> return _append_paths(ctx, [path], [transform], clip)
> /sfs/fs5/home-sh/sunip229/opt/miniconda3/envs/py37_forge_jore/lib/python3.7/site-packages/matplotlib/backends/backend_cairo.py(104)_append_paths_slow()
-> *np.concatenate([cur / 3 + points[:2] * 2 / 3,
(Pdb) points[:2]
array([404.72 ,  67.472])
(Pdb) cur
(400.71875, 67.47265625)

It seams like the value of cur should be an array and not a tuple.

The versions of the related programs are:

cairo                     1.14.12              h276e583_5    conda-forge
matplotlib                3.0.2                h8a2030e_0    conda-forge
matplotlib-base           3.0.2            py37h20b835b_0    conda-forge
pycairo                   1.18.0           py37h4d1f301_0    conda-forge
python                    3.7.0                h5001a0f_4    conda-forge

The bug occurred at several plots. However, the creation of the plots is rather complex. Thus I have no minimal example that reproduces the bug for now. If this is necessary, however, I can try to construct one.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions