Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#64173 closed defect (fixed)

py39-matplotlib @3.5.0_1 breaks saving a figure to PDF

Reported by: aaronm6 Owned by: reneeotten (Renee Otten)
Priority: Normal Milestone:
Component: ports Version: 2.7.1
Keywords: Cc: reneeotten (Renee Otten), dershow
Port: py-matplotlib

Description

(sorry to post a new ticket so soon, Renee! Thanks for all your hard work!) Saving a figure as PNG works fine with py39-matplotlib @3.5.0_1. However, saving it as PDF causes an import error this time related to fontTools. Hopefully this is a simple update to the dependencies.

Installing py39-fonttools @4.28.3 fixes this problem

Python 3.9.9 (main, Nov 16 2021, 07:33:57) 
[Clang 12.0.5 (clang-1205.0.22.11)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from matplotlib import pyplot as plt
>>> plt.figure()
<Figure size 1280x960 with 0 Axes>
>>> plt.plot([1,2,3],'.')
[<matplotlib.lines.Line2D object at 0x12d740d60>]
>>> plt.gcf().savefig('myplot.png',format='png')  # <---- this works
>>> plt.gcf().savefig('myplot.pdf',format='pdf')  # <---- this does not
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/matplotlib/figure.py", line 3012, in savefig
    self.canvas.print_figure(fname, **kwargs)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/matplotlib/backend_bases.py", line 2254, in print_figure
    canvas = self._get_output_canvas(backend, format)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/matplotlib/backend_bases.py", line 2179, in _get_output_canvas
    canvas_class = get_registered_canvas_class(fmt)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/matplotlib/backend_bases.py", line 144, in get_registered_canvas_class
    backend_class = importlib.import_module(backend_class).FigureCanvas
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 850, in exec_module
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/matplotlib/backends/backend_pdf.py", line 47, in <module>
    from . import _backend_pdf_ps
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/matplotlib/backends/_backend_pdf_ps.py", line 8, in <module>
    from fontTools import subset
ModuleNotFoundError: No module named 'fontTools'

Change History (4)

comment:1 Changed 3 years ago by dershow

I see the error a little differently, but I suspect that it's the same issue.

If I do:

from matplotlib.backends.backend_pdf import PdfPages

I get this error:

/opt/local/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/matplotlib/backends/_backend_pdf_ps.py in <module>
      6 import functools
      7 
----> 8 from fontTools import subset
      9 
     10 import matplotlib as mpl

ModuleNotFoundError: No module named 'fontTools'

comment:2 Changed 3 years ago by dershow

Cc: dershow added

comment:3 Changed 3 years ago by reneeotten (Renee Otten)

Owner: set to reneeotten
Resolution: fixed
Status: newclosed

In 97490c3312a997b79095db62050addfbc002728a/macports-ports (master):

py-matplotlib: add missing dependency

Closes: #64173

comment:4 Changed 3 years ago by reneeotten (Renee Otten)

I am sorry... this update wasn't my greatest work ;) I *think* I have now added all the new dependencies and hope everything will work now as expected. Thanks for the report(s) and your patience!

Note: See TracTickets for help on using tickets.