FIG matplotlib K line drawing, FIG daily combination

Reference: https: //blog.csdn.net/u014281392/article/details/73611624

Import matplotlib.pyplot AS PLT # # Import drawing module 
from matplotlib.pylab Import date2num # # Import values correspond to the date of conversion tool 
from dateutil.parser Import the parse # # introduced into the specified date format conversion tools 
Import mpl_finance MPF AS # # import module mpl_finance 
import tushare AS TS
 from matplotlib.pylab import date2num
 import datetime 
code = ' 000001 ' 
wdyx = ts.get_k_data (code, Start = ' 2019-10-01 ' , End = '2020-01-01 ' )
 #          date, opening, closing, high, low, volume, Code 
Print (wdyx [: 3 ]) 

DEF date_to_num (a dates): 
    num_time = []
     for DATE in a dates: 
        date_time = datetime.datetime .strptime (DATE, ' %% Y-M-% D ' ) 
        num_date = date2num (DATE_TIME) 
        num_time.append (num_date) 
    return num_time
 # dataframe converted into a two-dimensional array 
mat_wdyx = wdyx.iloc [:,:]. values 
num_time =  date_to_num (mat_wdyx [:, 0])
mat_wdyx [:, 0] = num_time
 Print (mat_wdyx [:. 3 ])
 # Main parameters introduced: 
# AX: Axes (axis) or Axes objects (axis) array of objects 
# QUOTES: is the incoming data, the first five columns of data to be and as a function of the predetermined holding 
# colorup: closing price represents> = opening price, which color chart provided 
# colordown: closing price represents <opening price, which color chart provided in 
fig, (ax1, ax2) = plt.subplots (2 , figsize = (15,8 )) 
mpf.candlestick_ochl (AX1, mat_wdyx, width = 0.6, colorup = ' G ' , colordown = ' R & lt ' , Alpha = 1.0 )
 # set date scale rotation angle 
# ax1.xticks (rotation 30 =) 
ax1.set_title (code) 
ax1.set_ylabel ( '. Price ' ) 
ax1.grid (True) 
# scale of the x-axis is the date 
ax1.xaxis_date () 
plt.bar (mat_wdyx [:, 0] -0.25, mat_wdyx [:,. 5], width = 0.5 ) 
ax2.set_ylabel ( ' Volume ' )
 # scale of the x-axis is the date 
ax2.xaxis_date () 
ax2.grid (True) 
plt.show ()

 

Guess you like

Origin www.cnblogs.com/-wenli/p/12276000.html