Elementary data visualization matplotlib

import pandas as pd
ChinaBank=pd.read_csv('ChinaBank.csv',index_col='Date')
ChinaBank
Unnamed: 0 Open High Low Close Volume
Date
2014-01-02 1 2.62 2.62 2.59 2.61 41632500
2014-01-03 2 2.60 2.61 2.56 2.56 45517700
2014-01-06 3 2.57 2.57 2.50 2.53 68674700
2014-01-07 4 2.51 2.52 2.49 2.52 53293800
2014-01-08 5 2.51 2.54 2.49 2.51 69087900
... ... ... ... ... ... ...
2015-04-24 341 4.71 4.73 4.60 4.66 1619024500
2015-04-27 342 4.66 4.82 4.66 4.81 1841766000
2015-04-28 343 4.83 5.29 4.81 5.06 4017962400
2015-04-29 344 5.00 5.01 4.85 4.97 1872648800
2015-04-30 345 4.96 4.96 4.83 4.84 1471072900

345 rows × 6 columns

ChinaBank=ChinaBank.iloc[:,1:]
ChinaBank.index=pd.to_datetime(ChinaBank.index)
Close=ChinaBank.Close
Open=ChinaBank.Open
import matplotlib.pyplot as plt
#超级神奇的一句话,图片可编辑
%matplotlib qt
#图片可显示中文
plt.rcParams['font.sans-serif']=['SimHei']
#图片可显示正负号
plt.rcParams['axes.unicode_minus'] = False

import matplotlib.pyplot as plt

plt.plot(Close['2014'],label='收盘价')
plt.plot(Open['2014'],label='开盘价')
plt.legend() 
d:\Anaconda3\lib\site-packages\pandas\plotting\_matplotlib\converter.py:103: FutureWarning: Using an implicitly registered datetime converter for a matplotlib plotting method. The converter was registered by pandas on import. Future versions of pandas will require you to explicitly register matplotlib converters.

To register the converters:
	>>> from pandas.plotting import register_matplotlib_converters
	>>> register_matplotlib_converters()
  warnings.warn(msg, FutureWarning)





<matplotlib.legend.Legend at 0xafb9408>
plt.plot(Close['2014'],label='收盘价',linestyle='solid')
plt.plot(Open['2014'],label='开盘价',ls='-.')
plt.legend()
plt.xlabel('日期')
plt.ylabel('价格')
plt.title('中国银行2014年开盘与收盘价曲线')
plt.grid(True,axis='y')
plt.plot(Close['2014'],c='r',label='收盘价')
plt.plot(Open['2014'],c='b',ls='--',label='开盘价')
plt.legend(loc='best')
plt.xlabel('日期')
plt.ylabel('价格')
plt.title('中国银行2014年开盘与收盘价曲线')
plt.grid(True,axis='both')
plt.plot(Close['2015'],marker='o',label='收盘价')
plt.plot(Open['2015'],marker='*',label='开盘价')
plt.legend(loc='best')
plt.xlabel('日期')
plt.ylabel('价格')
plt.title('中国银行2015年开盘与收盘价曲线')
plt.grid(True,axis='both')
plt.rcParams['axes.unicode_minus'] = False
plt.title('中国银行2014年收盘价曲线')
plt.xlabel('日期')
plt.ylabel('收盘价')
plt.grid(True,axis='both')

plt.plot([1,1,0,0,-1,0,1,1,-1]) 
plt.ylim(-1.5,1.5)
plt.xticks(range(9),\
            ['2015-02-01','2015-02-02',\
            '2015-02-03','2015-02-04',\
            '2015-02-05','2015-02-06',\
            '2015-02-07','2015-02-08','2015-02-09']) 

plt.title('中国银行2014年收盘价曲线',loc='right')
plt.show()
a=[0,0,0,0]
for i in Close:
    if (i>2)&(i<=3):
        a[0]+=1
    elif (i>3)&(i<=4):
        a[1]+=1 
    elif (i>4)&(i<=5):
        a[2]+=1
    else:
        a[3]+=1
        
plt.bar([2,3,4,5],a)
plt.bar([2,3,4,5],height=a,width=1.0,bottom=2.0)
plt.title('中国银行收盘价分布柱状图')


Text(0.5, 1.0, '中国银行收盘价分布柱状图')
plt.bar([2,3,4,5],height=a,width=1.0,bottom=2.0,color='red',edgecolor='k')
plt.title('中国银行收盘价分布柱状图')


Text(0.5, 1.0, '中国银行收盘价分布饼图')
plt.barh([2,3,4,5],a,height=1.0,color='red',edgecolor='k')
plt.title('中国银行收盘价分布柱状图')


Text(0.5, 1.0, '中国银行收盘价分布饼图')
plt.hist(Close,bins=12)
plt.title('中国银行收盘价分布直方图')


Text(0.5, 1.0, '中国银行收盘价分布直方图')
plt.hist(Close,range=(2.3,5.5),orientation='horizontal',color='red',edgecolor='blue')
plt.title('中国银行收盘价分布直方图')


Text(0.5, 1.0, '中国银行收盘价分布直方图')
plt.pie(a,labels=('(2,3]','(3,4]','(4,5]','(5,6]'),\
        colors=('b', 'g', 'r', 'c'),shadow=True)
plt.title('中国银行收盘价分布饼图')
Text(0.5, 1.0, '中国银行收盘价分布饼图')
Published 145 original articles · won praise 6 · views 8053

Guess you like

Origin blog.csdn.net/sinat_23971513/article/details/105060534