Dear all,
I tried for hours to find a solution to my problem but I was not able to get anywhere. I finally decided to write a mail here.
I?m an Italian engineer student using matplotlib for my master thesis. I would like to print some figures with Matplotlib using a Latex font. I looked everywhere in the internet for simular problems, but no solution was posted.
I?m trying to run the test code demo_tex.py which I found at http://matplotlib.org/users/usetex.html, but i get the following huge error (in blue). This is the first time I have an error using Matplotlib, it has always worked perfectly.
runfile('/Users/Filippo/AnacondaProjects/Python/Advanced_Solids_Mechanics/demo_tex.py', wdir='/Users/Filippo/AnacondaProjects/Python/Advanced_Solids_Mechanics')
Traceback (most recent call last):
File "<ipython-input-3-ba7a7930e0e4>", line 1, in <module>
runfile('/Users/Filippo/AnacondaProjects/Python/Advanced_Solids_Mechanics/demo_tex.py', wdir='/Users/Filippo/AnacondaProjects/Python/Advanced_Solids_Mechanics')
File "/anaconda3/lib/python3.6/site-packages/spyder/utils/site/sitecustomize.py", line 705, in runfile
execfile(filename, namespace)
File "/anaconda3/lib/python3.6/site-packages/spyder/utils/site/sitecustomize.py", line 102, in execfile
exec(compile(f.read(), filename, 'exec'), namespace)
File "/Users/Filippo/AnacondaProjects/Python/Advanced_Solids_Mechanics/demo_tex.py", line 42, in <module>
plt.savefig('tex_demo')
File "/anaconda3/lib/python3.6/site-packages/matplotlib/pyplot.py", line 710, in savefig
res = fig.savefig(*args, **kwargs)
File "/anaconda3/lib/python3.6/site-packages/matplotlib/figure.py", line 2035, in savefig
self.canvas.print_figure(fname, **kwargs)
File "/anaconda3/lib/python3.6/site-packages/matplotlib/backend_bases.py", line 2263, in print_figure
**kwargs)
File "/anaconda3/lib/python3.6/site-packages/matplotlib/backends/backend_agg.py", line 513, in print_png
FigureCanvasAgg.draw(self)
File "/anaconda3/lib/python3.6/site-packages/matplotlib/backends/backend_agg.py", line 433, in draw
self.figure.draw(self.renderer)
File "/anaconda3/lib/python3.6/site-packages/matplotlib/artist.py", line 55, in draw_wrapper
return draw(artist, renderer, *args, **kwargs)
File "/anaconda3/lib/python3.6/site-packages/matplotlib/figure.py", line 1475, in draw
renderer, self, artists, self.suppressComposite)
File "/anaconda3/lib/python3.6/site-packages/matplotlib/image.py", line 141, in _draw_list_compositing_images
a.draw(renderer)
File "/anaconda3/lib/python3.6/site-packages/matplotlib/artist.py", line 55, in draw_wrapper
return draw(artist, renderer, *args, **kwargs)
File "/anaconda3/lib/python3.6/site-packages/matplotlib/axes/_base.py", line 2607, in draw
mimage._draw_list_compositing_images(renderer, self, artists)
File "/anaconda3/lib/python3.6/site-packages/matplotlib/image.py", line 141, in _draw_list_compositing_images
a.draw(renderer)
File "/anaconda3/lib/python3.6/site-packages/matplotlib/artist.py", line 55, in draw_wrapper
return draw(artist, renderer, *args, **kwargs)
File "/anaconda3/lib/python3.6/site-packages/matplotlib/axis.py", line 1192, in draw
renderer)
File "/anaconda3/lib/python3.6/site-packages/matplotlib/axis.py", line 1130, in _get_tick_bboxes
extent = tick.label1.get_window_extent(renderer)
File "/anaconda3/lib/python3.6/site-packages/matplotlib/text.py", line 922, in get_window_extent
bbox, info, descent = self._get_layout(self._renderer)
File "/anaconda3/lib/python3.6/site-packages/matplotlib/text.py", line 309, in _get_layout
ismath=ismath)
File "/anaconda3/lib/python3.6/site-packages/matplotlib/backends/backend_agg.py", line 232, in get_text_width_height_descent
s, fontsize, renderer=self)
File "/anaconda3/lib/python3.6/site-packages/matplotlib/texmanager.py", line 501, in get_text_width_height_descent
dvifile = self.make_dvi(tex, fontsize)
File "/anaconda3/lib/python3.6/site-packages/matplotlib/texmanager.py", line 365, in make_dvi
texfile], tex)
File "/anaconda3/lib/python3.6/site-packages/matplotlib/texmanager.py", line 335, in _run_checked_subprocess
stderr=subprocess.STDOUT)
File "/anaconda3/lib/python3.6/subprocess.py", line 336, in check_output
**kwargs).stdout
File "/anaconda3/lib/python3.6/subprocess.py", line 403, in run
with Popen(*popenargs, **kwargs) as process:
File "/anaconda3/lib/python3.6/subprocess.py", line 709, in __init__
restore_signals, start_new_session)
File "/anaconda3/lib/python3.6/subprocess.py", line 1344, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'latex': 'latex'
Error in callback <function install_repl_displayhook.<locals>.post_execute at 0x10735e840> (for post_execute):
Traceback (most recent call last):
File "/anaconda3/lib/python3.6/site-packages/matplotlib/pyplot.py", line 149, in post_execute
draw_all()
File "/anaconda3/lib/python3.6/site-packages/matplotlib/_pylab_helpers.py", line 136, in draw_all
f_mgr.canvas.draw_idle()
File "/anaconda3/lib/python3.6/site-packages/matplotlib/backend_bases.py", line 2055, in draw_idle
self.draw(*args, **kwargs)
File "/anaconda3/lib/python3.6/site-packages/matplotlib/backends/backend_agg.py", line 433, in draw
self.figure.draw(self.renderer)
File "/anaconda3/lib/python3.6/site-packages/matplotlib/artist.py", line 55, in draw_wrapper
return draw(artist, renderer, *args, **kwargs)
File "/anaconda3/lib/python3.6/site-packages/matplotlib/figure.py", line 1475, in draw
renderer, self, artists, self.suppressComposite)
File "/anaconda3/lib/python3.6/site-packages/matplotlib/image.py", line 141, in _draw_list_compositing_images
a.draw(renderer)
File "/anaconda3/lib/python3.6/site-packages/matplotlib/artist.py", line 55, in draw_wrapper
return draw(artist, renderer, *args, **kwargs)
File "/anaconda3/lib/python3.6/site-packages/matplotlib/axes/_base.py", line 2607, in draw
mimage._draw_list_compositing_images(renderer, self, artists)
File "/anaconda3/lib/python3.6/site-packages/matplotlib/image.py", line 141, in _draw_list_compositing_images
a.draw(renderer)
File "/anaconda3/lib/python3.6/site-packages/matplotlib/artist.py", line 55, in draw_wrapper
return draw(artist, renderer, *args, **kwargs)
File "/anaconda3/lib/python3.6/site-packages/matplotlib/axis.py", line 1192, in draw
renderer)
File "/anaconda3/lib/python3.6/site-packages/matplotlib/axis.py", line 1130, in _get_tick_bboxes
extent = tick.label1.get_window_extent(renderer)
File "/anaconda3/lib/python3.6/site-packages/matplotlib/text.py", line 922, in get_window_extent
bbox, info, descent = self._get_layout(self._renderer)
File "/anaconda3/lib/python3.6/site-packages/matplotlib/text.py", line 309, in _get_layout
ismath=ismath)
File "/anaconda3/lib/python3.6/site-packages/matplotlib/backends/backend_agg.py", line 232, in get_text_width_height_descent
s, fontsize, renderer=self)
File "/anaconda3/lib/python3.6/site-packages/matplotlib/texmanager.py", line 501, in get_text_width_height_descent
dvifile = self.make_dvi(tex, fontsize)
File "/anaconda3/lib/python3.6/site-packages/matplotlib/texmanager.py", line 365, in make_dvi
texfile], tex)
File "/anaconda3/lib/python3.6/site-packages/matplotlib/texmanager.py", line 335, in _run_checked_subprocess
stderr=subprocess.STDOUT)
File "/anaconda3/lib/python3.6/subprocess.py", line 336, in check_output
**kwargs).stdout
File "/anaconda3/lib/python3.6/subprocess.py", line 403, in run
with Popen(*popenargs, **kwargs) as process:
File "/anaconda3/lib/python3.6/subprocess.py", line 709, in __init__
restore_signals, start_new_session)
File "/anaconda3/lib/python3.6/subprocess.py", line 1344, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'latex': 'latex'
Traceback (most recent call last):
File "/anaconda3/lib/python3.6/site-packages/IPython/core/formatters.py", line 341, in __call__
return printer(obj)
File "/anaconda3/lib/python3.6/site-packages/IPython/core/pylabtools.py", line 241, in <lambda>
png_formatter.for_type(Figure, lambda fig: print_figure(fig, 'png', **kwargs))
File "/anaconda3/lib/python3.6/site-packages/IPython/core/pylabtools.py", line 125, in print_figure
fig.canvas.print_figure(bytes_io, **kw)
File "/anaconda3/lib/python3.6/site-packages/matplotlib/backend_bases.py", line 2212, in print_figure
**kwargs)
File "/anaconda3/lib/python3.6/site-packages/matplotlib/backends/backend_agg.py", line 513, in print_png
FigureCanvasAgg.draw(self)
File "/anaconda3/lib/python3.6/site-packages/matplotlib/backends/backend_agg.py", line 433, in draw
self.figure.draw(self.renderer)
File "/anaconda3/lib/python3.6/site-packages/matplotlib/artist.py", line 55, in draw_wrapper
return draw(artist, renderer, *args, **kwargs)
File "/anaconda3/lib/python3.6/site-packages/matplotlib/figure.py", line 1475, in draw
renderer, self, artists, self.suppressComposite)
File "/anaconda3/lib/python3.6/site-packages/matplotlib/image.py", line 141, in _draw_list_compositing_images
a.draw(renderer)
File "/anaconda3/lib/python3.6/site-packages/matplotlib/artist.py", line 55, in draw_wrapper
return draw(artist, renderer, *args, **kwargs)
File "/anaconda3/lib/python3.6/site-packages/matplotlib/axes/_base.py", line 2607, in draw
mimage._draw_list_compositing_images(renderer, self, artists)
File "/anaconda3/lib/python3.6/site-packages/matplotlib/image.py", line 141, in _draw_list_compositing_images
a.draw(renderer)
File "/anaconda3/lib/python3.6/site-packages/matplotlib/artist.py", line 55, in draw_wrapper
return draw(artist, renderer, *args, **kwargs)
File "/anaconda3/lib/python3.6/site-packages/matplotlib/axis.py", line 1192, in draw
renderer)
File "/anaconda3/lib/python3.6/site-packages/matplotlib/axis.py", line 1130, in _get_tick_bboxes
extent = tick.label1.get_window_extent(renderer)
File "/anaconda3/lib/python3.6/site-packages/matplotlib/text.py", line 922, in get_window_extent
bbox, info, descent = self._get_layout(self._renderer)
File "/anaconda3/lib/python3.6/site-packages/matplotlib/text.py", line 309, in _get_layout
ismath=ismath)
File "/anaconda3/lib/python3.6/site-packages/matplotlib/backends/backend_agg.py", line 232, in get_text_width_height_descent
s, fontsize, renderer=self)
File "/anaconda3/lib/python3.6/site-packages/matplotlib/texmanager.py", line 501, in get_text_width_height_descent
dvifile = self.make_dvi(tex, fontsize)
File "/anaconda3/lib/python3.6/site-packages/matplotlib/texmanager.py", line 365, in make_dvi
texfile], tex)
File "/anaconda3/lib/python3.6/site-packages/matplotlib/texmanager.py", line 335, in _run_checked_subprocess
stderr=subprocess.STDOUT)
File "/anaconda3/lib/python3.6/subprocess.py", line 336, in check_output
**kwargs).stdout
File "/anaconda3/lib/python3.6/subprocess.py", line 403, in run
with Popen(*popenargs, **kwargs) as process:
File "/anaconda3/lib/python3.6/subprocess.py", line 709, in __init__
restore_signals, start_new_session)
File "/anaconda3/lib/python3.6/subprocess.py", line 1344, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'latex': 'latex'
<Figure size 432x288 with 1 Axes>
I don?t understand why. I tried to do everything that was reported in the site. I?m using Matplotlib version 2.2.2, on Python version 3.6, launched from Spyder 3.2.8, lauched from Anaconda (Anaconda Navigator 1.8.7).
Some other useful information:
Operating system: macOS High Sierra version 10.13.5 (MacBook Pro). The result of name -a is:
Darwin MacBook-Pro-di-Filippo-3.local 17.6.0 Darwin Kernel Version 17.6.0: Tue May 8 15:22:16 PDT 2018; root:xnu-4570.61.1~1/RELEASE_X86_64 x86_64
Matplotlib installing location: '/anaconda3/lib/python3.6/site-packages/matplotlib/__init__.py?
My matplotlib configuration and cache directories are both located in '/Users/Filippo/.matplotlib?, where I also tried to remove the file tex.cache (without any success).
I obtained Matplotlib from Anaconda, I didn?t add any customizations to my matplotlibrc (in fact, I don?t know how to use matplotlilrc).
I installed Latex using the latest version of MacTex and TexMaker. I verified that dvipng was installed too. I used home-brew to install the latest version of ghostscript (9.23). Ghostscript is now installed in the following location:
/usr/local/Cellar/ghostscript/9.23
These are the locations of the previous files:
I?m not really sure if latex, dvipng and ghostscript are really working on my PATH. They work whenever I call them from the command line, as in the following example:
I don?t know if this was useful but I tried to link them to my PATH modifying my .bash_profile in the following way (I have the same error using Matplotlib even If don?t link them in this way)(Anaconda wrote automatically the first two lines when I installed it):
I tried to do everything that I could, but I still unable to run Matplotlib and have a Latex font.
What can I do?
If you need more information just tell me.
Thank you very much for your help.
Best regards,
Luigi Filippo Chiara
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/matplotlib-users/attachments/20180715/28a13fd1/attachment-0007.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: demo_tex.py
Type: text/x-python-script
Size: 1158 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/matplotlib-users/attachments/20180715/28a13fd1/attachment-0001.bin>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/matplotlib-users/attachments/20180715/28a13fd1/attachment-0008.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Screen Shot 2018-07-15 at 16.34.07.png
Type: image/png
Size: 56883 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/matplotlib-users/attachments/20180715/28a13fd1/attachment-0005.png>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/matplotlib-users/attachments/20180715/28a13fd1/attachment-0009.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Screen Shot 2018-07-15 at 16.39.13.png
Type: image/png
Size: 64824 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/matplotlib-users/attachments/20180715/28a13fd1/attachment-0006.png>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/matplotlib-users/attachments/20180715/28a13fd1/attachment-0010.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Screen Shot 2018-07-15 at 16.39.21.png
Type: image/png
Size: 97309 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/matplotlib-users/attachments/20180715/28a13fd1/attachment-0007.png>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/matplotlib-users/attachments/20180715/28a13fd1/attachment-0011.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Screen Shot 2018-07-15 at 16.39.18.png
Type: image/png
Size: 518753 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/matplotlib-users/attachments/20180715/28a13fd1/attachment-0008.png>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/matplotlib-users/attachments/20180715/28a13fd1/attachment-0012.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Screen Shot 2018-07-15 at 16.41.45.png
Type: image/png
Size: 204584 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/matplotlib-users/attachments/20180715/28a13fd1/attachment-0009.png>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/matplotlib-users/attachments/20180715/28a13fd1/attachment-0013.html>