Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

[Bug]: Text label with empty line causes a "TypeError: cannot unpack non-iterable NoneType object" in PostScript backend #23954

Closed
Milestone
@jpeg13

Description

@jpeg13

Bug summary

When saving a figure with the PostScript backend, a

TypeError: cannot unpack non-iterable NoneType object

happens if the figure contains a multi-line text label with an empty line (see example).

Code for reproduction

frommatplotlib.figureimportFigurefigure=Figure()ax=figure.add_subplot(111)# ax.set_title('\nLower title')  # this would cause an error as wellax.annotate(text='\nLower label',xy=(0,0))figure.savefig('figure.eps')

Actual outcome

$ ./venv/Scripts/python save_ps.py
Traceback (most recent call last):
File "C:\temp\matplotlib_save_ps\save_ps.py", line 7, in
figure.savefig('figure.eps')
File "C:\temp\matplotlib_save_ps\venv\lib\site-packages\matplotlib\figure.py", line 3272, in savefig
self.canvas.print_figure(fname, **kwargs)
File "C:\temp\matplotlib_save_ps\venv\lib\site-packages\matplotlib\backend_bases.py", line 2338, in print_figure
result = print_method(
File "C:\temp\matplotlib_save_ps\venv\lib\site-packages\matplotlib\backend_bases.py", line 2204, in
print_method = functools.wraps(meth)(lambda *args, **kwargs: meth(
File "C:\temp\matplotlib_save_ps\venv\lib\site-packages\matplotlib_api\deprecation.py", line 410, in wrapper
return func(*inner_args, **inner_kwargs)
File "C:\temp\matplotlib_save_ps\venv\lib\site-packages\matplotlib\backends\backend_ps.py", line 869, in _print_ps
printer(fmt, outfile, dpi=dpi, dsc_comments=dsc_comments,
File "C:\temp\matplotlib_save_ps\venv\lib\site-packages\matplotlib\backends\backend_ps.py", line 927, in _print_figure
self.figure.draw(renderer)
File "C:\temp\matplotlib_save_ps\venv\lib\site-packages\matplotlib\artist.py", line 74, in draw_wrapper
result = draw(artist, renderer, *args, **kwargs)
File "C:\temp\matplotlib_save_ps\venv\lib\site-packages\matplotlib\artist.py", line 51, in draw_wrapper
return draw(artist, renderer)
File "C:\temp\matplotlib_save_ps\venv\lib\site-packages\matplotlib\figure.py", line 3069, in draw
mimage._draw_list_compositing_images(
File "C:\temp\matplotlib_save_ps\venv\lib\site-packages\matplotlib\image.py", line 131, in _draw_list_compositing_images
a.draw(renderer)
File "C:\temp\matplotlib_save_ps\venv\lib\site-packages\matplotlib\artist.py", line 51, in draw_wrapper
return draw(artist, renderer)
File "C:\temp\matplotlib_save_ps\venv\lib\site-packages\matplotlib\axes_base.py", line 3106, in draw
mimage._draw_list_compositing_images(
File "C:\temp\matplotlib_save_ps\venv\lib\site-packages\matplotlib\image.py", line 131, in _draw_list_compositing_images
a.draw(renderer)
File "C:\temp\matplotlib_save_ps\venv\lib\site-packages\matplotlib\artist.py", line 51, in draw_wrapper
return draw(artist, renderer)
File "C:\temp\matplotlib_save_ps\venv\lib\site-packages\matplotlib\text.py", line 1995, in draw
Text.draw(self, renderer)
File "C:\temp\matplotlib_save_ps\venv\lib\site-packages\matplotlib\artist.py", line 51, in draw_wrapper
return draw(artist, renderer)
File "C:\temp\matplotlib_save_ps\venv\lib\site-packages\matplotlib\text.py", line 736, in draw
textrenderer.draw_text(gc, x, y, clean_line,
File "C:\temp\matplotlib_save_ps\venv\lib\site-packages\matplotlib\backends\backend_ps.py", line 248, in wrapper
return meth(self, *args, **kwargs)
File "C:\temp\matplotlib_save_ps\venv\lib\site-packages\matplotlib\backends\backend_ps.py", line 673, in draw_text
for ps_name, xs_names in stream:
TypeError: cannot unpack non-iterable NoneType object

Expected outcome

The figure can be saved asfigure.eps without error.

Additional information

  • seems to happen if a text label or title contains a linebreak with an empty line
  • works without error for other backends such as PNG, PDF, SVG, Qt
  • works with matplotlib<=3.5.3
  • addingif curr_stream: before line 669 ofbackend_ps.py seems to fix the bug

Operating system

Windows

Matplotlib Version

3.6.0

Matplotlib Backend

No response

Python version

3.9.13

Jupyter version

No response

Installation

pip

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp