如何跳过2或3行在matplotlib python上绘制图形

时间:2015-02-02 07:58:06

标签: python numpy graph matplotlib

这是我想通过跳过第一行标题来绘制的示例文件。这是来自.txt文件的输入,

性别,体重(lbs),随机

21,171.0,884.29

22,179.6,82.234

23,174.7,7949

24,172.5,239.974

25,161.4,913.57

我只想绘制21,23和25的线,间隔为3秒。这是编码,

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
import time


contohfile = 'weight.txt'
fig = plt.figure()

def animate(i):
    weight = np.genfromtxt(contohfile, dtype=np.float, delimiter=',',\
                       skiprows=1, names=['x', 'y', 'z'])
    x1 = weight['x']
    y1 = weight['y']
    y2 = weight['z']


    ax1 = fig.add_subplot(3,1,1)
    ax1.plot(x1,y1, linewidth=2.2)
    ax1.set_title('graf X Y Z', color='yellow')
    ax1.set_ylabel('nilai x')

    ax2 = fig.add_subplot(3,1,2)
    ax2.plot(x1,y2, linewidth=2.2)


    ax2.set_ylabel('nilai y')

    ax3 = fig.add_subplot(3,1,3)
    ax3.plot(x1,y2, linewidth=2.2)
    ax3.set_title('graf 3', color='c')
    ax3.set_xlabel('timing')


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

希望你们能提供帮助。抱歉我的英文不好

0 个答案:

没有答案