title: PyCharm Matplotlib "UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure. plt.show()"
body: <p>I am having problems with <code>matplotlib.pyplot.show()</code> function. I am using <strong>PyCharm</strong> on <strong>Linux</strong>, and i have a <strong>VirtualEnv</strong>. When i execute the file <em>x.py</em> in the built terminal in PyCharm (using venv) like this</p>
  
  <blockquote>
    <p>$ python x.py</p>
  </blockquote>
  
  <p>everything works fine, the function <code>plt.show()</code> renders and shows the plotted graph well. i did add <code>print(matplotlib.get_backend())</code> to see which backend was used by default and the result was <strong>GTK3Agg</strong>.</p>
  
  <p>The problem starts when i use the option Run and not the terminal. Then i get an error message  </p>
  
  <blockquote>
    <p>UserWarning: Matplotlib is currently using agg, which is a non-GUI
    backend, so cannot show the figure. plt.show()</p>
  </blockquote>
  
  <p>Anyways, i searched online and according to <a href="https://matplotlib.org/faq/usage_faq.html#what-is-a-backend" rel="nofollow noreferrer">this</a> and other links, i had to add <code>backend: GTK3Agg</code> in <em>.config/matplotlib/matplotlibrc</em> . The file did not exist so i created it myself. Now when i run again, i get the following error messages:</p>
  
  <blockquote>
  <pre><code>raise ImportError('backend Gtk3Agg requires cairo') from e ImportError: backend Gtk3Agg requires cairo
  </code></pre>
  </blockquote>
  
  <p>How can i fix this ?</p>