方法一:
import numpy as np
import datetime
import matplotlib.pyplot as mp
import matplotlib.dates as md
def dmy2ymd(mdy):
mdy = str(mdy, encoding='utf8')
date_object = datetime.datetime.strptime(mdy, '%Y/%m/%d').date()
return date_object
dates, open_prices, high_prices, low_prices, close_prices = np.loadtxt(
'./sock.csv',
delimiter=',',
usecols=(1, 3, 4, 5, 6),
converters={1: dmy2ymd},
dtype='M8[D],f,f,f,f',
unpack=True)
mp.figure('APP', facecolor='lightgray')
mp.title("AAA")
mp.xlabel('Date', fontsize=14)
mp.ylabel('closeing price', fontsize=14)
ax = mp.gca()
ax.xaxis.set_major_locator(md.WeekdayLocator(byweekday=md.MO))
ax.xaxis.set_major_formatter(md.DateFormatter('%Y-%m-%d'))
ax.xaxis.set_minor_locator(md.DayLocator())
mp.grid(linestyle=':')
mp.plot(dates, close_prices, label='APP PRICE', linewidth=2, color='dodgerblue')
mp.legend()
mp.gcf().autofmt_xdate()
mp.show()