Probabilistic-Programming-and-Bayesian-Methods-for-Hackers icon indicating copy to clipboard operation
Probabilistic-Programming-and-Bayesian-Methods-for-Hackers copied to clipboard

Chapter 6 issue: ValueError: num must be 1 <= num <= 4, not 0

Open attibalazs opened this issue 9 years ago • 4 comments

Hi, found this issue in Chapter 6, changing plt.subplot(2, 2, i) to plt.subplot(2, 2, i+1) fixes the issue with the indexes, but you might want to adopt a different approach not sure why it doesn`t accept 0 for an index.

ValueError Traceback (most recent call last) in () 13 for i, (name, params) in enumerate(expert_prior_params.iteritems()): 14 print name, i ---> 15 plt.subplot(2, 2, i) 16 y = normal.pdf(x, params[0], scale=params[1]) 17 #plt.plot( x, y, c = colors[i] )

... missing stack trace subplots.pyc in init(self, fig, _args, _kwargs) 62 raise ValueError( 63 "num must be 1 <= num <= {maxn}, not {num}".format( ---> 64 maxn=rowscols, num=num)) 65 self._subplotspec = GridSpec(rows, cols)[int(num) - 1] 66 # num - 1 for converting from MATLAB to python indexing

ValueError: num must be 1 <= num <= 4, not 0

attibalazs avatar Apr 04 '16 14:04 attibalazs

you have to add 1 to this line

plt.subplot(2, 2, i + 1)

rodriguesra avatar May 20 '16 22:05 rodriguesra

data[['type']].astype(np.int0) .hist(figsize = (10, 5))

jasonfghx avatar Dec 18 '18 05:12 jasonfghx

@rodriguesra

you have to add 1 to this line

plt.subplot(2, 2, i + 1)

this works thank you.

Nikk-27 avatar May 28 '20 20:05 Nikk-27

Please check the no of the subplots created (rows x columns) and the total no. of plots? They should be equal.

Sushma7870-git avatar Oct 05 '21 05:10 Sushma7870-git