<h3 dir="auto">Bug report</h3>
<p dir="auto"><strong>Bug summary</strong><br>
I have a pcolormesh that has shading='gouraud', and I am trying to save it to an .eps. Saving it to a pdf works fine, but trying to save to an eps gives an error.</p>
<p dir="auto"><strong>Code for reproduction</strong></p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import matplotlib.pyplot as plt
import numpy as np
plt.pcolormesh(np.random.randn(10,10), shading='gouraud')
plt.gcf().savefig('test.eps')"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-s1">matplotlib</span>.<span class="pl-s1">pyplot</span> <span class="pl-k">as</span> <span class="pl-s1">plt</span>
<span class="pl-k">import</span> <span class="pl-s1">numpy</span> <span class="pl-k">as</span> <span class="pl-s1">np</span>
<span class="pl-s1">plt</span>.<span class="pl-en">pcolormesh</span>(<span class="pl-s1">np</span>.<span class="pl-s1">random</span>.<span class="pl-en">randn</span>(<span class="pl-c1">10</span>,<span class="pl-c1">10</span>), <span class="pl-s1">shading</span><span class="pl-c1">=</span><span class="pl-s">'gouraud'</span>)
<span class="pl-s1">plt</span>.<span class="pl-en">gcf</span>().<span class="pl-en">savefig</span>(<span class="pl-s">'test.eps'</span>)</pre></div>
<p dir="auto"><strong>Actual outcome</strong></p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="    168 def quote_ps_string(s):
    169     &quot;Quote dangerous characters of S for use in a PostScript string constant.&quot;
--&gt; 170     s=s.replace(&quot;\\&quot;, &quot;\\\\&quot;)
    171     s=s.replace(&quot;(&quot;, &quot;\\(&quot;)
    172     s=s.replace(&quot;)&quot;, &quot;\\)&quot;)

TypeError: a bytes-like object is required, not 'str'"><pre class="notranslate"><code class="notranslate">    168 def quote_ps_string(s):
    169     "Quote dangerous characters of S for use in a PostScript string constant."
--&gt; 170     s=s.replace("\\", "\\\\")
    171     s=s.replace("(", "\\(")
    172     s=s.replace(")", "\\)")

TypeError: a bytes-like object is required, not 'str'
</code></pre></div>
<p dir="auto"><strong>Matplotlib version</strong><br>
matplotlib 1.5.1<br>
'3.5.1 |Anaconda 2.4.1 (x86_64)| (default, Dec  7 2015, 11:24:55) \n[GCC 4.2.1 (Apple Inc. build 5577)]'<br>
OS X</p>
<p dir="auto">I fixing this might just require adding a 'b' before these strings.</p>
<p dir="auto">I'm running python 3.4 on Debian 8.3, and am using the Qt5Agg backend. When I call savefig() or use the toolbar widget to save a figure that has a gouraud shaded triangulation, I get the following stacktrace:</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="Traceback (most recent call last):
  File &quot;/home/tps/PyCharmProjects/test/test_PlotWindow.py&quot;, line 323, in saveFigRButtonClicked
    savefig(fname)
  File &quot;/usr/local/lib/python3.4/dist-packages/matplotlib/pyplot.py&quot;, line 688, in savefig
    res = fig.savefig(*args, **kwargs)
  File &quot;/usr/local/lib/python3.4/dist-packages/matplotlib/figure.py&quot;, line 1565, in savefig
    self.canvas.print_figure(*args, **kwargs)
  File &quot;/usr/local/lib/python3.4/dist-packages/matplotlib/backends/backend_qt5agg.py&quot;, line 196, in print_figure
    FigureCanvasAgg.print_figure(self, *args, **kwargs)
  File &quot;/usr/local/lib/python3.4/dist-packages/matplotlib/backend_bases.py&quot;, line 2232, in print_figure
    **kwargs)
  File &quot;/usr/local/lib/python3.4/dist-packages/matplotlib/backends/backend_ps.py&quot;, line 995, in print_eps
    return self._print_ps(outfile, 'eps', *args, **kwargs)
  File &quot;/usr/local/lib/python3.4/dist-packages/matplotlib/backends/backend_ps.py&quot;, line 1023, in _print_ps
    **kwargs)
  File &quot;/usr/local/lib/python3.4/dist-packages/matplotlib/backends/backend_ps.py&quot;, line 1113, in _print_figure
    self.figure.draw(renderer)
  File &quot;/usr/local/lib/python3.4/dist-packages/matplotlib/artist.py&quot;, line 61, in draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File &quot;/usr/local/lib/python3.4/dist-packages/matplotlib/figure.py&quot;, line 1159, in draw
    func(*args)
  File &quot;/usr/local/lib/python3.4/dist-packages/matplotlib/artist.py&quot;, line 61, in draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File &quot;/usr/local/lib/python3.4/dist-packages/matplotlib/axes/_base.py&quot;, line 2324, in draw
    a.draw(renderer)
  File &quot;/usr/local/lib/python3.4/dist-packages/matplotlib/artist.py&quot;, line 61, in draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File &quot;/usr/local/lib/python3.4/dist-packages/matplotlib/collections.py&quot;, line 1694, in draw
    renderer.draw_gouraud_triangles(gc, verts, colors, transform.frozen())
  File &quot;/usr/local/lib/python3.4/dist-packages/matplotlib/backends/backend_ps.py&quot;, line 867, in draw_gouraud_triangles
    stream = quote_ps_string(streamarr.tostring())
  File &quot;/usr/local/lib/python3.4/dist-packages/matplotlib/backends/backend_ps.py&quot;, line 170, in quote_ps_string
    s=s.replace(&quot;\\&quot;, &quot;\\\\&quot;)
TypeError: expected bytes, bytearray or buffer compatible object"><pre class="notranslate"><span class="pl-v">Traceback</span> (<span class="pl-s1">most</span> <span class="pl-s1">recent</span> <span class="pl-s1">call</span> <span class="pl-s1">last</span>):
  <span class="pl-v">File</span> <span class="pl-s">"/home/tps/PyCharmProjects/test/test_PlotWindow.py"</span>, <span class="pl-s1">line</span> <span class="pl-c1">323</span>, <span class="pl-s1">in</span> <span class="pl-s1">saveFigRButtonClicked</span>
    <span class="pl-en">savefig</span>(<span class="pl-s1">fname</span>)
  <span class="pl-v">File</span> <span class="pl-s">"/usr/local/lib/python3.4/dist-packages/matplotlib/pyplot.py"</span>, <span class="pl-s1">line</span> <span class="pl-c1">688</span>, <span class="pl-s1">in</span> <span class="pl-s1">savefig</span>
    <span class="pl-s1">res</span> <span class="pl-c1">=</span> <span class="pl-s1">fig</span>.<span class="pl-en">savefig</span>(<span class="pl-c1">*</span><span class="pl-s1">args</span>, <span class="pl-c1">**</span><span class="pl-s1">kwargs</span>)
  <span class="pl-v">File</span> <span class="pl-s">"/usr/local/lib/python3.4/dist-packages/matplotlib/figure.py"</span>, <span class="pl-s1">line</span> <span class="pl-c1">1565</span>, <span class="pl-s1">in</span> <span class="pl-s1">savefig</span>
    <span class="pl-s1">self</span>.<span class="pl-s1">canvas</span>.<span class="pl-en">print_figure</span>(<span class="pl-c1">*</span><span class="pl-s1">args</span>, <span class="pl-c1">**</span><span class="pl-s1">kwargs</span>)
  <span class="pl-v">File</span> <span class="pl-s">"/usr/local/lib/python3.4/dist-packages/matplotlib/backends/backend_qt5agg.py"</span>, <span class="pl-s1">line</span> <span class="pl-c1">196</span>, <span class="pl-s1">in</span> <span class="pl-s1">print_figure</span>
    <span class="pl-v">FigureCanvasAgg</span>.<span class="pl-en">print_figure</span>(<span class="pl-s1">self</span>, <span class="pl-c1">*</span><span class="pl-s1">args</span>, <span class="pl-c1">**</span><span class="pl-s1">kwargs</span>)
  <span class="pl-v">File</span> <span class="pl-s">"/usr/local/lib/python3.4/dist-packages/matplotlib/backend_bases.py"</span>, <span class="pl-s1">line</span> <span class="pl-c1">2232</span>, <span class="pl-s1">in</span> <span class="pl-s1">print_figure</span>
    <span class="pl-c1">**</span><span class="pl-s1">kwargs</span>)
  <span class="pl-v">File</span> <span class="pl-s">"/usr/local/lib/python3.4/dist-packages/matplotlib/backends/backend_ps.py"</span>, <span class="pl-s1">line</span> <span class="pl-c1">995</span>, <span class="pl-s1">in</span> <span class="pl-s1">print_eps</span>
    <span class="pl-k">return</span> <span class="pl-s1">self</span>.<span class="pl-en">_print_ps</span>(<span class="pl-s1">outfile</span>, <span class="pl-s">'eps'</span>, <span class="pl-c1">*</span><span class="pl-s1">args</span>, <span class="pl-c1">**</span><span class="pl-s1">kwargs</span>)
  <span class="pl-v">File</span> <span class="pl-s">"/usr/local/lib/python3.4/dist-packages/matplotlib/backends/backend_ps.py"</span>, <span class="pl-s1">line</span> <span class="pl-c1">1023</span>, <span class="pl-s1">in</span> <span class="pl-s1">_print_ps</span>
    <span class="pl-c1">**</span><span class="pl-s1">kwargs</span>)
  <span class="pl-v">File</span> <span class="pl-s">"/usr/local/lib/python3.4/dist-packages/matplotlib/backends/backend_ps.py"</span>, <span class="pl-s1">line</span> <span class="pl-c1">1113</span>, <span class="pl-s1">in</span> <span class="pl-s1">_print_figure</span>
    <span class="pl-s1">self</span>.<span class="pl-s1">figure</span>.<span class="pl-en">draw</span>(<span class="pl-s1">renderer</span>)
  <span class="pl-v">File</span> <span class="pl-s">"/usr/local/lib/python3.4/dist-packages/matplotlib/artist.py"</span>, <span class="pl-s1">line</span> <span class="pl-c1">61</span>, <span class="pl-s1">in</span> <span class="pl-s1">draw_wrapper</span>
    <span class="pl-en">draw</span>(<span class="pl-s1">artist</span>, <span class="pl-s1">renderer</span>, <span class="pl-c1">*</span><span class="pl-s1">args</span>, <span class="pl-c1">**</span><span class="pl-s1">kwargs</span>)
  <span class="pl-v">File</span> <span class="pl-s">"/usr/local/lib/python3.4/dist-packages/matplotlib/figure.py"</span>, <span class="pl-s1">line</span> <span class="pl-c1">1159</span>, <span class="pl-s1">in</span> <span class="pl-s1">draw</span>
    <span class="pl-en">func</span>(<span class="pl-c1">*</span><span class="pl-s1">args</span>)
  <span class="pl-v">File</span> <span class="pl-s">"/usr/local/lib/python3.4/dist-packages/matplotlib/artist.py"</span>, <span class="pl-s1">line</span> <span class="pl-c1">61</span>, <span class="pl-s1">in</span> <span class="pl-s1">draw_wrapper</span>
    <span class="pl-en">draw</span>(<span class="pl-s1">artist</span>, <span class="pl-s1">renderer</span>, <span class="pl-c1">*</span><span class="pl-s1">args</span>, <span class="pl-c1">**</span><span class="pl-s1">kwargs</span>)
  <span class="pl-v">File</span> <span class="pl-s">"/usr/local/lib/python3.4/dist-packages/matplotlib/axes/_base.py"</span>, <span class="pl-s1">line</span> <span class="pl-c1">2324</span>, <span class="pl-s1">in</span> <span class="pl-s1">draw</span>
    <span class="pl-s1">a</span>.<span class="pl-en">draw</span>(<span class="pl-s1">renderer</span>)
  <span class="pl-v">File</span> <span class="pl-s">"/usr/local/lib/python3.4/dist-packages/matplotlib/artist.py"</span>, <span class="pl-s1">line</span> <span class="pl-c1">61</span>, <span class="pl-s1">in</span> <span class="pl-s1">draw_wrapper</span>
    <span class="pl-en">draw</span>(<span class="pl-s1">artist</span>, <span class="pl-s1">renderer</span>, <span class="pl-c1">*</span><span class="pl-s1">args</span>, <span class="pl-c1">**</span><span class="pl-s1">kwargs</span>)
  <span class="pl-v">File</span> <span class="pl-s">"/usr/local/lib/python3.4/dist-packages/matplotlib/collections.py"</span>, <span class="pl-s1">line</span> <span class="pl-c1">1694</span>, <span class="pl-s1">in</span> <span class="pl-s1">draw</span>
    <span class="pl-s1">renderer</span>.<span class="pl-en">draw_gouraud_triangles</span>(<span class="pl-s1">gc</span>, <span class="pl-s1">verts</span>, <span class="pl-s1">colors</span>, <span class="pl-s1">transform</span>.<span class="pl-en">frozen</span>())
  <span class="pl-v">File</span> <span class="pl-s">"/usr/local/lib/python3.4/dist-packages/matplotlib/backends/backend_ps.py"</span>, <span class="pl-s1">line</span> <span class="pl-c1">867</span>, <span class="pl-s1">in</span> <span class="pl-s1">draw_gouraud_triangles</span>
    <span class="pl-s1">stream</span> <span class="pl-c1">=</span> <span class="pl-en">quote_ps_string</span>(<span class="pl-s1">streamarr</span>.<span class="pl-en">tostring</span>())
  <span class="pl-v">File</span> <span class="pl-s">"/usr/local/lib/python3.4/dist-packages/matplotlib/backends/backend_ps.py"</span>, <span class="pl-s1">line</span> <span class="pl-c1">170</span>, <span class="pl-s1">in</span> <span class="pl-s1">quote_ps_string</span>
    <span class="pl-s1">s</span><span class="pl-c1">=</span><span class="pl-s1">s</span>.<span class="pl-en">replace</span>(<span class="pl-s">"<span class="pl-cce">\\</span>"</span>, <span class="pl-s">"<span class="pl-cce">\\</span><span class="pl-cce">\\</span>"</span>)
<span class="pl-v">TypeError</span>: <span class="pl-s1">expected</span> <span class="pl-s1">bytes</span>, <span class="pl-s1">bytearray</span> <span class="pl-c1">or</span> <span class="pl-s1">buffer</span> <span class="pl-s1">compatible</span> <span class="pl-s1">object</span></pre></div>