必要库导入
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
import pandas as pd
import matplotlib
matplotlib.rc("font",family='DengXian') # 中文显示
折线图 plt.plot
#-------------------------------------------------文件操作-------------------------------------------------#
# 文件读取
data = pd.read_csv('000001.csv')
dates = pd.to_datetime(data['Date'])
open, close = np.loadtxt('000001.csv',delimiter=',', skiprows=1, usecols=(1,4), unpack=True)
#-------------------------------------------------绘图操作-------------------------------------------------#
# 绘图参数设置
linestyle = '-.' # 设置线的类型
color = 'green' # 设置线的颜色
linewidth = 1.5 # 设置线的宽度
marker = 'o' # 设置点的形状
markerfacecolor = 'blue' # 设置点的颜色
markersize = 3 # 设置点的大小
alpha = 0.6 # 设置点的透明度
# 绘图
plt.figure(figsize=(13, 3), dpi = 300) # 设置画布大小
plt.grid(color = 'gray', ls = '-.', alpha = 0.3)
plt.plot(dates, close, color = color, linestyle = linestyle, linewidth = linewidth, # 线参数设置
marker = marker, markerfacecolor = markerfacecolor, markersize = markersize, alpha = alpha) # 点参数设置
plt.plot(dates, open, color = 'red', linestyle = linestyle, linewidth = linewidth, # 线参数设置
marker = 'v', markerfacecolor = 'yellow', markersize = markersize, alpha = alpha)
plt.legend(['close', 'open'])
plt.show()