title: discord bot stocks price plotted from yfinance using pandas and save with matplotlib's savefig stacked up
body: <p>I'm a grade 11 student so I'm new with both python and pandas and yahoo finance so I tried to make a discord bot that can get the closed price of stocks and plotted it to send in discord for my investment discord server(best bot to use(Alpha) can't get my country stock data(Thailand - .bk) so I need to make one myself)</p>
  <p>firstly I made data_visualization to do the job of data handling (download, plot, save, etc..)
  well just</p>
  <pre><code>#this is data_visualization.py
  import yfinance as yf
  import pandas as pd
  import datetime
  from datetime import date
  import numpy as np
  import matplotlib.pyplot as plt
  from dateutil.relativedelta import relativedelta
  import os
  from readable_table import print_info
  from readable_table import print_table
  
  def save_pic(pricegraph):
      pricefig = pricegraph.get_figure()
      pricefig.savefig('image1'+'.png')
      print('Save รูป Graph ราคา')
      return
  
  def get_stock_price_history_and_plot_graph(ticker, range, timeframe):
      try:
          thisday = date.today()
   
          if (timeframe.lower() == &quot;y&quot;):
   
              start = thisday - relativedelta(years=int(range))
              _ticker = yf.download((ticker.lower()+'.bk'), start, thisday)
   
              pricegraph = _ticker['Adj Close'].plot(color=colors)
              save_pic(pricegraph)
   
              return
   
          elif(timeframe.lower() == &quot;m&quot;):
   
              start = thisday - relativedelta(months=int(range))
              _ticker = yf.download((ticker.lower()+'.bk'), start, thisday)
   
              pricegraph = _ticker['Adj Close'].plot(color=colors)
              save_pic(pricegraph)
              return
   
          elif(timeframe.lower() == &quot;d&quot;):
   
              start = thisday - relativedelta(days=int(range))
              _ticker = yf.download((ticker.lower()+'.bk'), start, thisday)
   
              pricegraph = _ticker['Adj Close'].plot(color=colors)
              save_pic(pricegraph)
              return
   
      except ValueError:
          print('Error Some Shit in Data data_visualization : get_stock_price_history_and_plot_graph')
          return
  </code></pre>
  <p>and then I build the bot</p>
  <pre><code>#this is bot.py
  import discord
  from data_visualization import get_stock_price_history_and_plot_graph as get_Stock
  from data_visualization import delete_graph_pic as del_pic
  from data_visualization import save_pic
  from readable_table import print_info
  from readable_table import print_table
   
  client = discord.Client()
   
   
  @client.event
  async def on_ready():
      print('ล๊อกอินในชื่อ{0.user}'.format(client))
   
   
  @client.event
  async def on_message(message):
      if message.author == client.user:
          return
   
      else:
          lowercasemsg = message.content.lower()
          splitmsg = lowercasemsg.split(' ')
   
          if (('makima' in splitmsg[0]) or 'มากิมะ' in (splitmsg[0])):
   
              #main function
               if (len(splitmsg) &gt; 1):
                  if (splitmsg[1] == ('price') or splitmsg[1] == ('ราคา')):
                      try:
                          get_Stock(splitmsg[2], splitmsg[3], splitmsg[4])
                          await message.channel.send(
                            splitmsg[1]+splitmsg[2] + splitmsg[3]+splitmsg[4])
                          await message.channel.send(file=discord.File('image1.png'))
   
                      except ValueError:
                          message.channel.send('ข้อมูลที่กรอกมามันผิดนะ')
                          message.channel.send('เจ้าหมาโง่...')
   
                #bot run here
  client.run('TOKENS')
  </code></pre>
  <p>everything works fine</p>
  <p><img src="https://i.stack.imgur.com/rXmYQ.png" alt="graph that was sent in discord" /></p>
  <p>but when I called it again</p>
  <p><img src="https://i.stack.imgur.com/aB0tV.png" alt="graph stacked up" /></p>
  <p>my graph is stacked up!!!</p>
  <p>and I think the trouble lies in data_visualization that downloaded data from yfinance stacked up in the same dataframe  but I don't know how to fix it, I can't find a solution at all</p>
  <pre><code>    def save_pic(pricegraph):
      pricefig = pricegraph.get_figure()
      pricefig.savefig('image1'+'.png')
      print('Save รูป Graph ราคา')
      return
   
  #declare-basic-function
   
   
  def delete_graph_pic(files):
      if os.path.exists(files):
          os.remove(files)
          return
      else:
        print(files, &quot;does not exist&quot;)
   
   
  def get_stock_price_history_and_plot_graph(ticker, range, timeframe):
      try:
          thisday = date.today()
   
          if (timeframe.lower() == &quot;y&quot;):
   
              start = thisday - relativedelta(years=int(range))
              _ticker = yf.download((ticker.lower()+'.bk'), start, thisday)
   
              pricegraph = _ticker['Adj Close'].plot(color=colors)
              save_pic(pricegraph)
   
              return
   
          elif(timeframe.lower() == &quot;m&quot;):
   
              start = thisday - relativedelta(months=int(range))
              _ticker = yf.download((ticker.lower()+'.bk'), start, thisday)
   
              pricegraph = _ticker['Adj Close'].plot(color=colors)
              save_pic(pricegraph)
              return
   
          elif(timeframe.lower() == &quot;d&quot;):
   
              start = thisday - relativedelta(days=int(range))
              _ticker = yf.download((ticker.lower()+'.bk'), start, thisday)
   
              pricegraph = _ticker['Adj Close'].plot(color=colors)
              save_pic(pricegraph)
              return
   
      except ValueError:
          print('Error Somethings in Data data_visualization : get_stock_price_history_and_plot_graph')
          return
  </code></pre>