title: Multiple Sns plot distort in flask using savefig and sendfile
body: <p>I have a html file that displays the images sent from the flask backend.</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;body&gt;
      
      &lt;h3&gt; Count plot of data according to Lead origin.&lt;/h3&gt;
  
      &lt;img src = "/graph_visualization/" alt = "graph it is" height = "300" width = "300"&gt;
  
      &lt;h3&gt; Count plot of data according to cities&lt;/h3&gt;
  
      &lt;img src = "/graph_visualization2/" alt = "graph it is" height = "300" width = "300"&gt;
  
      &lt;h3&gt; Count plot of data according to Countries&lt;/h3&gt;
  
      &lt;img src = "/graph_visualization3/" alt = "graph it is" height = "300" width = "300"&gt;
  
  &lt;/body&gt;</code></pre>
  </div>
  </div>
  </p>
  <p>The three plots are sent as a png file from multiple functions in flask backend as below:</p>
  <pre><code>@app.route('/graph_visualization/')
  def graph_visualization():
      fig, ax = plt.subplots()
      df = pd.read_csv(r'C:\Users\Admin\Downloads\export.csv')
      sns.countplot(x=&quot;Lead Origin&quot;, hue=&quot;Converted&quot;, data=df)
      canvas = FigureCanvas(fig)
      img = BytesIO()
      fig.savefig(img, format='png')
      img.seek(0)
      return send_file(img, mimetype='image/png', cache_timeout=-1)
  
  
  @app.route('/graph_visualization2/')
  def graph_visualization2():
      fig1, ax = plt.subplots()
      df = pd.read_csv(r'C:\Users\Admin\Downloads\export.csv')
      sns.countplot(x=&quot;Cities&quot;, hue=&quot;Converted&quot;, data=df)
      xticks(rotation=90)
      plt.tight_layout()
      canvas = FigureCanvas(fig1)
      img1 = BytesIO()
      fig1.savefig(img1, format='png')
      img1.seek(0)
  
      return send_file(img1, mimetype='image/png', cache_timeout=-1)
  
  
  @app.route('/graph_visualization3/')
  def graph_visualization3():
      fig2, ax = plt.subplots()
      df = pd.read_csv(r'C:\Users\Admin\Downloads\export.csv')
      sns.barplot(x=&quot;Countries&quot;, y=&quot;Converted&quot;, data=df)
      xticks(rotation=90)
      plt.tight_layout()
      plt.ylabel('Converted')
      plt.xlabel('Countries')
      canvas = FigureCanvas(fig2)
      img2 = BytesIO()
      fig2.savefig(img2, formar='png')
      img2.seek(0)
  
      return send_file(img2, mimetype='image/png', cache_timeout=-1)
  </code></pre>
  <p><a href="https://i.stack.imgur.com/ch6wd.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ch6wd.png" alt="The output is like this:" /></a></p>
  <p><strong>Note: Individual graph shows when i comment any two functions and only keep one. The problem is when i uncomment all of them.</strong></p>
  <p>I have tried following methods:</p>
  <ol>
  <li>Changing the figurename and image name in each functions.</li>
  <li><code>plt.clf()</code> below <code>fig.savefig()</code></li>
  <li><code>ax.clear()</code> below <code>fig, ax = plt.subplots()</code></li>
  <li>Run in Incognito mode.</li>
  </ol>
  <p><strong>Note: I don't want to make multiple subplots.</strong></p>
  <p>Please let me know if my approach to the problem is incorrect.</p>