title: TypeError: cannot unpack non-iterable AxesSubplot object
body: <p>I am trying to chart stock price data using python, mysql and matplotlib.
  The code gets data from a mysql database. That looks to complete successsfully.</p>
  
  <p>The data is converted into a list, then into a numpy array.</p>
  
  <p>I am completely new to matplotlib. Any help would be greatly appreciated.
  I've tried googling the error message but I've not come across anything useful yet.</p>
  
  <p>The error looks to be coming from this line in the code. Specifically around the fig keyword.</p>
  
  <pre><code>**fig,** ax1 = plt.subplot()
  </code></pre>
  
  <p>Here is the full code:</p>
  
  <pre><code>import numpy as np
  import csv
  import matplotlib.pyplot as plt
  from matplotlib import dates, ticker
  import matplotlib
  from mpl_finance import candlestick_ohlc
  import pymysql
  import pandas as pd
  import sys
  import os
  from os import listdir
  from os.path import isfile, join
  
  ticker = '14D'
  start_date = '20190107'
  end_date = '20190111'
  host = 'localhost'
  user = 'user'
  password = 'password'
  db = 'trading'
  
  def get_data_from_mysql(host, user, password, db, ticker, start_date, end_date):
      # Create empty lists
      date_data = []
      open_data = []
      high_data = []
      low_data = []
      close_data = []
      volume_data = []
  
      '''
      This function load a csv file to MySQL table according to
      the load_sql statement.
      SELECT * FROM asx WHERE Symbol = '14D' AND Date &gt;= '2019-01-02' AND Date &lt;='2019-01-11'
      '''
      query_sql = 'SELECT * FROM asx WHERE Symbol = %s AND Date &gt;= %s AND Date &lt;= %s'
      args = [ticker, start_date, end_date]
      print('You are in get_data_from_mysql')
      print(args)
      try:
          con = pymysql.connect(host=host,
                                  user=user,
                                  password=password,
                                  db=db,
                                  autocommit=True,
                                  local_infile=1)
          print('Connected to DB: {}'.format(host))
          # Create cursor and execute Load SQL
          cursor = con.cursor()
          cursor.execute(query_sql, args)
          results = cursor.fetchall()
          # Print the results
          for row in results:
              date_data.append(row[1])
              open_data.append(row[2])
              high_data.append(row[3])
              low_data.append(row[4])
              close_data.append(row[5])
              volume_data.append(row[6])
          con.close()
  
      except Exception as e:
          print('Error: {}'.format(str(e)))
          sys.exit(1)
  
      # Convert the list items to string before printing them out
      print(' '.join(map(str, date_data)))
      print(' '.join(map(str, open_data)))
      print(' '.join(map(str, high_data)))
      print(' '.join(map(str, low_data)))
      print(' '.join(map(str, close_data)))
      print(' '.join(map(str, volume_data)))
  
      # Convert the list into numpy arrays
      open_val = np.array(open_data[1:], dtype=np.float64)
      high_val = np.array(high_data[1:], dtype=np.float64)
      low_val = np.array(low_data[1:], dtype=np.float64)
      close_val = np.array(close_data[1:], dtype=np.float64)
  
      # Matplotlib needs dates in floating numbers before they can be plotted
      data_dates = []
      for date in date_data[:1]:
          new_date = dates.date2num(date)
          data_dates.append(new_date)
  
      # Create a compacted dataset for the ohlc plot
      i = 0
      ohlc_data = []
      # While i is less that the number of items in the data_dates list
      while i &lt; len(data_dates):
          stats_1_day = data_dates[i], open_val[i], high_val[i], low_val[i], close_val[i]
          print(stats_1_day)
          ohlc_data.append(stats_1_day)
          # Increment the counter
          i += 1
  
      # Day format for the x labels
      dayFormatter = dates.DateFormatter('%d-%b-%Y')
  
      # Create a figure and an axis
      fig, ax1 = plt.subplot()
      # Colorup is green, colordown is red. Alpha  = opacity of the candlestick (80pct opacity)
      candlestick_ohlc(ax1, ohlc_data, width=0.5, colorup='g', colordown='r', alpha='0.8')
      # Data verification check
      '''
      plt.plot(data_dates, open_val)
      plt.plot(data_dates, high_val)
      plt.plot(data_dates, low_val)
      plt.plot(data_dates, close_val)
      '''
  
      # Format the dates
      ax1.xaxis.set_major_formatter(dayFormatter)
      ax1.xaxis.set_major_locator(ticker.MaxNLocator(10)) # specify the number of ticks in the x axis
      plt.xticks(rotation=30) # rotates the x axis titles by 30 degrees
      plt.xlabel('Date')
      plt.ylabel('14D')
      plt.title('Historical Data for the period of 07-01-2019 to 11-01-2019')
      plt.tight_layout
      plt.show
  
  get_data_from_mysql(host, user, password, db, ticker, start_date, end_date)
  </code></pre>
  
  <p>This is the error message:</p>
  
  <pre><code>Traceback (most recent call last):
    File "SimpleJapaneseCandlestick_v0.4.py", line 128, in &lt;module&gt;
      get_data_from_mysql(host, user, password, db, ticker, start_date, end_date)
    File "SimpleJapaneseCandlestick_v0.4.py", line 107, in get_data_from_mysql
      fig, ax1 = plt.subplot()
  TypeError: cannot unpack non-iterable AxesSubplot object
  </code></pre>
  
  <p>Thanks in advance.</p>