###########matplotlib
import matplotlib.pyplot as plt
plt.plot([1,2,3,4,5],[2,4,6,1,3],"o",label='LineA') ##折线图,o为点,o-为点加线
plt.plot([5,4,3,2,1],[2,4,6,1,3],color='red',marker='v',label='LineB')
plt.title('who are you')
plt.xlabel('x')
plt.ylabel('y')
#plt.xlim(0,5)
#plt.ylim(0,5)
#plt.xticks([0,2,4])
#plt.xticks(np.arange(0,10,2),['a','b','c','d','e'])
plt.legend()
plt.show()
##pandas与matplotlib
df = pd.read_csv('/Users/terry/Downloads/'+
'数据分析课件资料/FinanceAnalysis/601318.csv',
index_col='date',parse_dates=['date'])[['open','close','high','low']]
df.plot()
plt.show()
#作业绘制y=x,y=x*x,y=3x^3+5x^2+2x+1,使用不同颜色的线加以区别
x = np.linspace(-100,100,10000)
y1 = x
y2 = x ** 2
y3 = 3*x**3+5*x**2+x*2+1
plt.plot(x,y1,color='red',label='y=x')
plt.plot(x,y2,color='green',label='y=x*x')
plt.plot(x,y3,color='blue',label='y=3x^3+5x^2+2x+1')
plt.ylim(-1000,1000)
plt.legend()
plt.show()
#####画布与子图
fig = plt.figure()
ax1 = fig.add_subplot(2,2,1)
ax1.plot([1,2,3,4],[5,6,7,8])
plt.show()
ax2 = fig.add_subplot(2,2,2)
fig.show()
fig = plt.figure()
ax1 = fig.add_subplot(2,1,1)
ax2 = fig.add_subplot(2,1,2)
fig.show()
####柱形图和饼图
plt.bar([1,2,3,4],[5,6,7,8])
plt.show()
data= [32,45,34,65]
labels = ['Jan','Feb','Mar','Apr']
plt.bar(np.arange(len(data)),data,color='red',width=0.3)
plt.xticks(np.arange(len(data)),labels)
plt.show()
plt.pie([10,20,30,40],
labels=['Jan','Feb','Mar','Apr'],
autopct='%.0f%%',
explode=[0,0,0.1,0])
plt.axis('equal')
plt.show()
########K线图
#matplotlib.finanace子包中有许多绘制金融相关图的函数接口
#matplotlib.finanace.candlestick_ochl
import mpl_finance as fin
from matplotlib.dates import date2num
df['time']=date2num(df.index.to_pydatetime())
df
fig = plt.figure()
ax = fig.add_subplot(1,1,1)
arr = df[['time','open','close','high','low']].values
fin.candlestick_ochl(ax, arr)
plt.grid()
fig.show()
plt.show()