python怎么用csv文件绘制图_使用csv文件中的matplotlib在python中绘制时间序列图

1586010002-jmsa.png

I have some csv data in the following format.

Ln Dr Tag Lab 0:01 0:02 0:03 0:04 0:05 0:06 0:07 0:08 0:09

L0 St vT 4R 0 0 0 0 0 0 0 0 0

L2 Tx st 4R 8 8 8 8 8 8 8 8 8

L2 Tx ss 4R 1 1 9 6 1 0 0 6 7

I want to plot a timeseries graph using the columns (Ln , Dr, Tg,Lab) as the keys and the 0:0n field as values on a timeseries graph.

I have the following code.

#!/usr/bin/env python

import matplotlib.pyplot as plt

import datetime

import numpy as np

import csv

import sys

with open("test.csv", 'r', newline='') as fin:

reader = csv.DictReader(fin)

for row in reader:

key = (row['Ln'], row['Dr'], row['Tg'],row['Lab'])

#code to extract the values and plot a timeseries.

How do I extract all the values in columns 0:0n without induviduall specifying each one of them. I want all the timeseries to be plotted on a single timeseries?

解决方案

I'd suggest using pandas:

import pandas as pd

a=pd.read_csv('yourfile.txt',delim_whitespace=True)

for x in a.iterrows():

x[1][4:].plot(label=str(x[1][0])+str(x[1][1])+str(x[1][2])+str(x[1][3]))

plt.ylim(-1,10)

plt.legend()

IC0LJ.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值