1

I'm still a little new to Matplotlib and the code below is just in a Jupiter Notebook for quick n' dirty practicing, so please forgive the sloppy variable naming and structure.

I have a list of categories (74 in total) but I'm starting off small to see if my code is correct before just loading in all the categories. When I just try any 2 categories everything works as expected, but when I load in a third one (or just > 2), I get this error.

The error: 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

M4cJunk13
  • 419
  • 8
  • 22
  • 2
    The number sequence `21x` in your `add_subplot` call means that you expect two rows of subplots in 1 column. You are providing `x=3` meaning that you are exceeding the expected number of plots to be seen in your figure by specifying a third plot to appear. That's why it's throwing the error of `num = 3` as it is not expecting you to provide a third plot. – rayryeng Jan 28 '18 at 02:14
  • @ rayryeng Ahhh, that makes so much sense! Thanks for catching that. It fixed it! – M4cJunk13 Jan 28 '18 at 02:42

0 Answers0