MatPlotLab和条形图csv文件

时间:2016-11-06 05:15:22

标签: python matplotlib

我正在尝试将csv文件转换为条形图,但我只想将每个单独的行用作数据集。我想制作一个条形图。我需要为每个月创建代表其当月价值的单独栏,但我不断收到转换错误。 This is the data

这是我的代码,

  >>> import matplotlib.pyplot as plt
import numpy as np

data = np.loadtxt('11m2015.csv', delimiter=',', skiprows = (0,2,3,4,5,6,7,8,9,10,11), usecols = range(1,7))
data = data.transpose()

xt = np.loadtxt('11m2015.csv', dtype='str', delimiter=',', skiprows = (1,2,3,4,5,6,7,8,9,10,11), usecols = range(1,7))

import matplotlib.pyplot as plt
import numpy as np

data = np.loadtxt('11m2015.csv', delimiter=',', skiprows = 1, usecols = range(1,7))
data = data.transpose()

xt = np.loadtxt('11m2015.csv', dtype='str', delimiter=',', usecols = range(1,7))



width = 0.45
ind = np.arange(7) + 0.75


fig, ax = plt.subplots(1,1)
p0 = ax.bar(ind, data[0],  width, color = 'cyan')


ax.set_ylabel('')
ax.set_xlabel('month')
ax.set_xticks (ind + width/2.)
ax.set_xticklabels( xt, rotation = 70 )

fig.legend( (p0[0]))
fig.tight_layout()
fig.show()

width = 0.45
ind = np.arange(7) + 0.75


fig, ax = plt.subplots(1,1)
p0 = ax.bar(ind, data[0],  width, color = 'cyan')


ax.set_ylabel('')
ax.set_xlabel('month')
ax.set_xticks (ind + width/2.)
ax.set_xticklabels( xt, rotation = 70 )

fig.legend( (p0[0]))
fig.tight_layout()
fig.show()

0 个答案:

没有答案