matplotlib绘制所有列的csv文件 [英] matplotlib plot csv file of all columns

查看:118
本文介绍了matplotlib绘制所有列的csv文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含20列的csv文件.现在,我可以使用此代码绘制图表,其中第一列为x轴,其余为y轴.

I have a csv file which contains 20 columns. Right now I can plot using this code taking first column as x axis and rest of them as y axis.

import numpy as np
import matplotlib.pyplot as plt
data = np.genfromtxt('cs.csv',delimiter=',', dtype = float)

a = [row[0] for row in data]
b = [row[1] for row in data]
c = [row[2] for row in data]

fig = plt.figure()
ax = fig.add_subplot(111, axisbg = 'w')
ax.plot(a,b,'g',lw=1.3)
ax.plot(a,c,'r',lw=1.3)
plt.show()

问题出在这里,我必须使用

The problem is here I have to define all the columns by using

a = [row [0] for data in row]

a = [row[0] for row in data]

此代码一一列出所有列.我实际上想要有一些方法,以便它可以绘制所有 19 列,将第一列作为 x 轴常量并将它们绘制在单个窗口中.请任何帮助.

this code for all columns one by one. What I want actually to have some method so that it can plot all 19 columns taking first column as x axis constant and plot them in a single window. Any help please.

推荐答案

这是怎么回事:

[plt.plot(data[0],data[x]) for x in range(1,len(data[:,0]))]

这篇关于matplotlib绘制所有列的csv文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆