数据可视化matplotlib的应用(二)

对边框和Horizontal 一些设置:

     ax1.spines['left'].set_color('c')     #将左边框栏设置c颜色
    ax1.spines['right'].set_visible(False)   #将右边框栏设置不可见
    ax1.spines['top'].set_visible(False)    #将上边框栏设置为不可见
    ax1.spines['left'].set_linewidth(5)    #将左边框栏的宽度设置为5


    ax1.tick_params(axis='x', colors='#f06215')  #将x轴的标签颜色设置成#f06215
    
    ax1.axhline(closep[0], color='k', linewidth=5)   #将Horizontal 就是横轴颜色设置K,宽度设置为5

ohlc和candlestick的应用:

from matplotlib.ticker as mticker
from matplotlib.finance import candlestick_ohlc

    x = 0
    y = len(date)
    ohlc = []

    while x < y:
        append_me = date[x], openp[x], highp[x], lowp[x], closep[x], volume[x]
        ohlc.append(append_me)
        x+=1
 
   candlestick_ohlc(ax1, ohlc, width=0.4, colorup='#77d879', colordown='#db3f3f')


    for label in ax1.xaxis.get_ticklabels():
        label.set_rotation(45)

    ax1.xaxis.set_major_formatter(mdates.DateFormatter('%Y-%m-%d'))
    ax1.xaxis.set_major_locator(mticker.MaxNLocator(10))
    ax1.grid(True)


    

用style订制matplotlib

from matplotlib import style

style.use('ggplot')

style.use('fivethirtyeight')

    ax1.plot(date,closep)
    ax1.plot(date,openp)

#还可以使用的sytle如下:

#['seaborn-white', 'classic', 'seaborn-ticks', 'grayscale', 'seaborn-colorblind', 'ggplot', 'seaborn-dark', 'seaborn-darkgrid', 'seaborn-pastel', 'dark_background', 'seaborn-whitegrid', 'bmh', 'seaborn-dark-palette', 'seaborn-notebook', 'seaborn-bright', 'fivethirtyeight', 'seaborn-deep', 'seaborn-talk', 'seaborn-paper', 'seaborn-muted', 'seaborn-poster']



Animation的使用:

import matplotlib.pyplot as plt
import matplotlib.animation as animation
from matplotlib import style

style.use('fivethirtyeight')

fig = plt.figure()
ax1 = fig.add_subplot(1,1,1)

def animate(i):
    graph_data = open('kk.txt','r').read()
    lines = graph_data.split('\n')
    xs = []
    ys = []
    for line in lines:
        if len(line) >1:
            x, y = line.split(',')
            xs.append(x)
            ys.append(y)
    ax1.clear()
    ax1.plot(xs, ys)

ani = animation.FuncAnimation(fig, animate, interval=1000)
plt.show()


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值