您的位置:首页 > 编程语言 > PHP开发

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

2017-01-01 09:56 876 查看
对边框和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()





内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: