title: Display matplotlib graph in browser
body: <p>I am using matplotlib library of python for plotting graphs. My program is to detect the outliers in the system. I am making an interface for this. I have to show this graph in browser on clicking the button. Here is my php file code :- </p>
  
  <pre><code>&lt;?php
      if (isset($_POST['button']))
      {
           echo shell_exec("python3 /var/www/html/python/anomalies.py 2&gt;&amp;1");
      }
  ?&gt;
  &lt;html&gt;
  
  &lt;body&gt;
  &lt;center&gt;
  
  
      &lt;form method="post"&gt;
      &lt;table&gt;
          &lt;tr&gt;
              &lt;td&gt;
                  Enter CSV file path:
              &lt;/td&gt;
              &lt;td&gt;
                  &lt;input type="text" name="path"&gt;
              &lt;/td&gt;
          &lt;/tr&gt;
      &lt;/table&gt;
      &lt;p&gt;
          &lt;button name="button"&gt;Identify Anomalies&lt;/button&gt;
      &lt;/p&gt;
      &lt;/form&gt;
      &lt;/center&gt;
  &lt;/body&gt;
  </code></pre>
  
  <p>on clicking this button a python script runs which gives the output as graph. The problem is that if i run it by command line, the script generates the graph as output. but when i run this script through browser button click, it generates the following error:</p>
  
  <pre><code>Traceback (most recent call last): File "/var/www/html/python/anomalies.py", line 72, in plt.xlabel('RelativeTime (ms)') File "/usr/local/lib/python3.4/dist-packages/matplotlib/pyplot.py", line 1512, in xlabel return gca().set_xlabel(s, *args, **kwargs) File "/usr/local/lib/python3.4/dist-packages/matplotlib/pyplot.py", line 984, in gca return gcf().gca(**kwargs) File "/usr/local/lib/python3.4/dist-packages/matplotlib/pyplot.py", line 601, in gcf return figure() File "/usr/local/lib/python3.4/dist-packages/matplotlib/pyplot.py", line 548, in figure **kwargs) File "/usr/local/lib/python3.4/dist-packages/matplotlib/backend_bases.py", line 161, in new_figure_manager return cls.new_figure_manager_given_figure(num, fig) File "/usr/local/lib/python3.4/dist-packages/matplotlib/backends/_backend_tk.py", line 1044, in new_figure_manager_given_figure window = Tk.Tk(className="matplotlib") File "/usr/lib/python3.4/tkinter/__init__.py", line 1854, in __init__ self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use) _tkinter.TclError: no display name and no $DISPLAY environment variable
  </code></pre>
  
  <p>Here is my python code snippet:- </p>
  
  <pre><code>plt.xlabel('R_Time (ms)')
  plt.ylabel('A_Time (ms)')
  plt.title('R-A Combinations')
  plt.plot(tr_data[:,0],tr_data[:,1],'bx')
  plt.plot(tr_data[outliers,0],tr_data[outliers,1],'ro')
  
  plt.show()
  </code></pre>
  
  <p>I tried using <code>mpld3</code> but found no resolution.
  Please suggest where i am missing it in.</p>