Closed
Description
Bug summary
I am unable to save figures as pdf while using Tex. The figures are generated, but just not saved into a pdf file. I don't face the problem while saving files as either jpg's or png's. Everything seems to work fine if I disable Tex.
Code for reproduction
import matplotlib.pyplot as plt
import matplotlib.font_manager as fm
from cycler import cycler
from matplotlib import rc
plt.rcParams['font.size'] = 11
plt.rcParams['figure.autolayout'] = True
plt.rcParams['savefig.dpi'] = 300
plt.rcParams['xtick.labelsize'] = 'medium'
plt.rcParams['ytick.labelsize'] = 'medium'
plt.rcParams['xtick.major.size'] = 8
plt.rcParams['ytick.major.size'] = 8
plt.rcParams['xtick.minor.size'] = 3
plt.rcParams['ytick.minor.size'] = 3
plt.rcParams['xtick.major.width'] = 1
plt.rcParams['ytick.major.width'] = 1
plt.rcParams['xtick.minor.width'] = 1
plt.rcParams['ytick.minor.width'] = 1
plt.rcParams['xtick.top'] = True
plt.rcParams['ytick.right'] = True
plt.rcParams['xtick.minor.visible'] = True
plt.rcParams['ytick.minor.visible'] = True
plt.rcParams['xtick.direction'] = 'in'
plt.rcParams['ytick.direction'] = 'in'
plt.rcParams['lines.markersize'] = 4
plt.rcParams['lines.linewidth'] = 1
plt.rcParams['lines.markeredgewidth'] = 0.2
plt.rcParams['path.simplify'] = True
plt.rcParams['text.usetex'] = True
rc('text.latex', preamble=r'\usepackage[T1]{fontenc}\usepackage{cmbright}')
plt.rcParams['axes.linewidth'] = 0.7
plt.rcParams['axes.labelsize'] = 'large'
plt.rcParams['axes.prop_cycle'] = cycler(color=['k', 'r', 'g', 'b', 'c', 'm', 'y'])
plt.rcParams['legend.numpoints'] = 1
plt.rcParams['legend.frameon'] = False
plt.rcParams['legend.handletextpad'] = 0.3
plt.rcParams['legend.scatterpoints'] = 1
plt.rcParams['legend.handlelength'] = 2
plt.rcParams['legend.handleheight'] = 0.1
plt.plot([10,100], [10,100])
plt.savefig('test.pdf')
Actual outcome
---------------------------------------------------------------------------
FileNotFoundError Traceback (most recent call last)
<ipython-input-6-368972b0f1c2> in <module>
1 plt.plot([10,100], [10,100])
----> 2 plt.savefig('test.pdf')
~/.local/lib/python3.7/site-packages/matplotlib/pyplot.py in savefig(*args, **kwargs)
964 def savefig(*args, **kwargs):
965 fig = gcf()
--> 966 res = fig.savefig(*args, **kwargs)
967 fig.canvas.draw_idle() # need this if 'transparent=True' to reset colors
968 return res
~/.local/lib/python3.7/site-packages/matplotlib/figure.py in savefig(self, fname, transparent, **kwargs)
3013 patch.set_edgecolor('none')
3014
-> 3015 self.canvas.print_figure(fname, **kwargs)
3016
3017 if transparent:
~/.local/lib/python3.7/site-packages/matplotlib/backend_bases.py in print_figure(self, filename, dpi, facecolor, edgecolor, orientation, format, bbox_inches, pad_inches, bbox_extra_artists, backend, **kwargs)
2259 orientation=orientation,
2260 bbox_inches_restore=_bbox_inches_restore,
-> 2261 **kwargs)
2262 finally:
2263 if bbox_inches and restore_bbox:
~/.local/lib/python3.7/site-packages/matplotlib/backend_bases.py in wrapper(*args, **kwargs)
1667 kwargs.pop(arg)
1668
-> 1669 return func(*args, **kwargs)
1670
1671 return wrapper
~/.local/lib/python3.7/site-packages/matplotlib/_api/deprecation.py in wrapper(*inner_args, **inner_kwargs)
429 else deprecation_addendum,
430 **kwargs)
--> 431 return func(*inner_args, **inner_kwargs)
432
433 return wrapper
~/.local/lib/python3.7/site-packages/matplotlib/backends/backend_pdf.py in print_pdf(self, filename, dpi, bbox_inches_restore, metadata)
2723 RendererPdf(file, dpi, height, width),
2724 bbox_inches_restore=bbox_inches_restore)
-> 2725 self.figure.draw(renderer)
2726 renderer.finalize()
2727 if not isinstance(filename, PdfPages):
~/.local/lib/python3.7/site-packages/matplotlib/artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
72 @wraps(draw)
73 def draw_wrapper(artist, renderer, *args, **kwargs):
---> 74 result = draw(artist, renderer, *args, **kwargs)
75 if renderer._rasterizing:
76 renderer.stop_rasterizing()
~/.local/lib/python3.7/site-packages/matplotlib/artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
49 renderer.start_filter()
50
---> 51 return draw(artist, renderer, *args, **kwargs)
52 finally:
53 if artist.get_agg_filter() is not None:
~/.local/lib/python3.7/site-packages/matplotlib/figure.py in draw(self, renderer)
2789 self.patch.draw(renderer)
2790 mimage._draw_list_compositing_images(
-> 2791 renderer, self, artists, self.suppressComposite)
2792
2793 for sfig in self.subfigs:
~/.local/lib/python3.7/site-packages/matplotlib/image.py in _draw_list_compositing_images(renderer, parent, artists, suppress_composite)
130 if not_composite or not has_images:
131 for a in artists:
--> 132 a.draw(renderer)
133 else:
134 # Composite any adjacent images together
~/.local/lib/python3.7/site-packages/matplotlib/artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
49 renderer.start_filter()
50
---> 51 return draw(artist, renderer, *args, **kwargs)
52 finally:
53 if artist.get_agg_filter() is not None:
~/.local/lib/python3.7/site-packages/matplotlib/_api/deprecation.py in wrapper(*inner_args, **inner_kwargs)
429 else deprecation_addendum,
430 **kwargs)
--> 431 return func(*inner_args, **inner_kwargs)
432
433 return wrapper
~/.local/lib/python3.7/site-packages/matplotlib/axes/_base.py in draw(self, renderer, inframe)
2919 renderer.stop_rasterizing()
2920
-> 2921 mimage._draw_list_compositing_images(renderer, self, artists)
2922
2923 renderer.close_group('axes')
~/.local/lib/python3.7/site-packages/matplotlib/image.py in _draw_list_compositing_images(renderer, parent, artists, suppress_composite)
130 if not_composite or not has_images:
131 for a in artists:
--> 132 a.draw(renderer)
133 else:
134 # Composite any adjacent images together
~/.local/lib/python3.7/site-packages/matplotlib/artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
49 renderer.start_filter()
50
---> 51 return draw(artist, renderer, *args, **kwargs)
52 finally:
53 if artist.get_agg_filter() is not None:
~/.local/lib/python3.7/site-packages/matplotlib/axis.py in draw(self, renderer, *args, **kwargs)
1144
1145 for tick in ticks_to_draw:
-> 1146 tick.draw(renderer)
1147
1148 # scale up the axis label box to also find the neighbors, not
~/.local/lib/python3.7/site-packages/matplotlib/artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
49 renderer.start_filter()
50
---> 51 return draw(artist, renderer, *args, **kwargs)
52 finally:
53 if artist.get_agg_filter() is not None:
~/.local/lib/python3.7/site-packages/matplotlib/axis.py in draw(self, renderer)
300 for artist in [self.gridline, self.tick1line, self.tick2line,
301 self.label1, self.label2]:
--> 302 artist.draw(renderer)
303 renderer.close_group(self.__name__)
304 self.stale = False
~/.local/lib/python3.7/site-packages/matplotlib/artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
49 renderer.start_filter()
50
---> 51 return draw(artist, renderer, *args, **kwargs)
52 finally:
53 if artist.get_agg_filter() is not None:
~/.local/lib/python3.7/site-packages/matplotlib/text.py in draw(self, renderer)
723 textrenderer.draw_tex(gc, x, y, clean_line,
724 textobj._fontproperties, angle,
--> 725 mtext=mtext)
726 else:
727 textrenderer.draw_text(gc, x, y, clean_line,
~/.local/lib/python3.7/site-packages/matplotlib/_api/deprecation.py in wrapper(*inner_args, **inner_kwargs)
429 else deprecation_addendum,
430 **kwargs)
--> 431 return func(*inner_args, **inner_kwargs)
432
433 return wrapper
~/.local/lib/python3.7/site-packages/matplotlib/backends/backend_pdf.py in draw_tex(self, gc, x, y, s, prop, angle, ismath, mtext)
2190 for x1, y1, dvifont, glyph, width in page.text:
2191 if dvifont != oldfont:
-> 2192 pdfname = self.file.dviFontName(dvifont)
2193 seq += [['font', pdfname, dvifont.size]]
2194 oldfont = dvifont
~/.local/lib/python3.7/site-packages/matplotlib/backends/backend_pdf.py in dviFontName(self, dvifont)
862 return dvi_info.pdfname
863
--> 864 tex_font_map = dviread.PsfontsMap(dviread.find_tex_file('pdftex.map'))
865 psfont = tex_font_map[dvifont.texname]
866 if psfont.filename is None:
~/.local/lib/python3.7/site-packages/matplotlib/dviread.py in __new__(cls, filename)
849 self._font = {}
850 self._filename = os.fsdecode(filename)
--> 851 with open(filename, 'rb') as file:
852 self._parse(file)
853 return self
FileNotFoundError: [Errno 2] No such file or directory: ''
Expected outcome
Code is expected to produce a pdf file.
Operating system
SUSE Linux Enterprise Server 12 SP5
Matplotlib Version
3.4.3
Matplotlib Backend
module://ipykernel.pylab.backend_inline
Python version
Python 3.7.4
Jupyter version
6.0.1
Other libraries
No response
Installation
pip
Conda channel
No response