Error on running RollDieDynamic.py // Not using Anaconda
Closed this issue ยท 10 comments
When trying to run it on iPython I get the following error:
File "/Users/lmeinhardt/Programs/Python3/deitel/ch01/RollDieDynamic.py", line 17, in update
axes = sns.barplot(faces, frequencies, palette='bright') # new bars
TypeError: barplot() takes from 0 to 1 positional arguments but 2 positional arguments (and 1 keyword-only argument) were given
Note: Not using anaconda installation - using the standard installation from python.org - all libraries are installed and yet I get this error.
OS: MacOS 10.16
Python: Python 3.9.12
The content of the two parameters are:
Faces: [1, 2, 3, 4, 5, 6]
Frequencies: [0, 0, 0, 1, 0, 0]
Can you tell me what version of Seaborn is installed? Run this at the command line:
conda list seaborn
installed Seaborn-0.12.0 (installed through PIP)
Correct, it does run correctly on Seaborn 0.11. I only get the following warning regarding changes in the positional arguments coming on version 0.12 โ hope this helps you:
/Users/XXX/Library/Python/3.9/lib/python/site-packages/seaborn/_decorators.py:36: FutureWarning: Pass the following variables as keyword args: x, y. From version 0.12, the only valid positional argument will be data
, and passing other arguments without an explicit keyword will result in an error or misinterpretation.
warnings.warn(
Another 2 issues on your code:
- When you run the code, the number of rolls is always with one additional roll. $ipython RollDieDynamic.py 50 1 will result in 51 rolls, and
- When you run $ipython RollDieDynamic.py 50 10 it multiplies the number_of_rolls by the rolls_per_frames+1 - see result below:
What I did to make it work 100% (with a very rookie correction - which is my current Python beginner level) was to change the following lines:
Line 33: number_of_frames = int(sys.argv[1]) - 1
Line 44: fargs=(int((rolls_per_frame)/10), values, frequencies))
Cheers
Turns out that the issue was the sns.barplot
call. I thought I had corrected this a long time ago. The parameter names are required for the faces
and frequency
arguments.
axes = sns.barplot(x=faces, y=frequencies, palette='bright') # new bars
With Seaborn 0.12.0, I get no warnings or errors after this update.
Also, thanks for pointing out the off-by-one error.
code is updated in the repo for Chapter 1, 5 and 6.
You corrected the off-by-one error, but not the number of rolls... There were two errors.
That is correct as is. If you do 50 and 10 as arguments, it should produce 500 rolls.
The second argument is the # of rolls to process in the current frame. This allows you to more easily see the Law of Large Numbers in action by significantly increasing the rolls-per-frame.
Thanks for the fast confirmation... Cheers