Python Matplotlib ValueError'num必须为1< = num< = 2,而不是3'

时间:2018-01-28 02:11:49

标签: python matplotlib

我对Matplotlib还是一个新手,下面的代码只是在Jupiter笔记本中进行快速的肮脏练习,所以请原谅邋variable的变量命名和结构。

我有一个类别列表(总共74个),但是我开始时很小,看看我的代码是否正确,然后加载所有类别。当我尝试任何两个类别时,一切都按预期工作,但当我加载第三个(或只是> 2)时,我收到此错误。

错误:ValueError: num must be 1 <= num <= 2, not 3 enter image description here

def time_stamp_count(category):
    tst = []
    for i in cc_key_val_num:
        for k,v in i.items():
            if k == 'Time':
                ti = v[:-2]
                tst.append({ti:0})
            if k == 'LIWC_lib':
                for x in v:
                    z,q = x
                    if z == category:
                        tst.pop()
                        tst.append({ti:q})
    return tst



style.use('dark_background')
fig = plt.figure(figsize=(16, 10))

category_name = ['focusfuture', 'focusfuture', 'focuspresent']

def create_plots(xan):
    xs = []
    ys = []
    for i in xan:
        for k,v in i.items():
            xs.append(k)
            ys.append(v)
    return xs,ys


for i,step in zip(range(len(category_name)), category_name):
    i += 1

    xox = '21{0}'.format(i)
    xox = int(xox)

    ax = fig.add_subplot(xox)

    xan = time_stamp_count(step)
    x,y = create_plots(xan)

    x_freq = 15
    x_axis = range(len(x))
    my_xticks = np.array(x)
    plt.xticks(x_axis[::x_freq], my_xticks[::x_freq])

    ax.plot(x_axis,y, label=step, color='#1dcaff')
    plt.legend(bbox_to_anchor=(1, 1), loc=2, borderaxespad=0.)
plt.show()

enter image description here

0 个答案:

没有答案