1. import matplotlib.pyplot as plt
    2. import numpy as np
    3. import urllib
    4. import matplotlib.dates as mdates
    5. def bytespdate2num(fmt, encoding='utf-8'):
    6. strconverter = mdates.strpdate2num(fmt)
    7. def bytesconverter(b):
    8. s = b.decode(encoding)
    9. return strconverter(s)
    10. return bytesconverter
    11. def graph_data(stock):
    12. source_code = urllib.request.urlopen(stock_price_url).read().decode()
    13. stock_data = []
    14. split_source = source_code.split('\n')
    15. for line in split_source:
    16. split_line = line.split(',')
    17. if len(split_line) == 6:
    18. if 'values' not in line and 'labels' not in line:
    19. stock_data.append(line)
    20. date, closep, highp, lowp, openp, volume = np.loadtxt(stock_data,
    21. delimiter=',',
    22. unpack=True,
    23. # %Y = full year. 2015
    24. # %y = partial year 15
    25. # %m = number month
    26. # %H = hours
    27. # %M = minutes
    28. # %S = seconds
    29. # 12-06-2014
    30. # %m-%d-%Y
    31. converters={0: bytespdate2num('%Y%m%d')})
    32. plt.plot_date(date, closep,'-', label='Price')
    33. plt.xlabel('Date')
    34. plt.ylabel('Price')
    35. plt.title('Interesting Graph\nCheck it out')
    36. plt.legend()
    37. plt.show()
    38. graph_data('TSLA')