Plot Function Error in Fastbook version 0.0.21

Hi All,

I was using fastbook version 0.0.21 and faced an error regarding plot_function method. The error seemed like

TypeError: linspace() missing 1 required positional arguments: "steps"

On checking the current implementation, I could see that linspace did require an extra “steps” argument which was not passed in current implementation. Hence, the error.

Here is the temporary fix I did to get rid of the error.

def plot_function(f, tx=None, ty=None, title=None, min=-2, max=2, figsize=(6,4)):
    x = torch.linspace(min,max, steps=**20**)
    #print("These are the stepped points", x)
    fig,ax = plt.subplots(figsize=figsize)
    ax.plot(x,f(x))
    if tx is not None: ax.set_xlabel(tx)
    if ty is not None: ax.set_ylabel(ty)
    if title is not None: ax.set_title(title)

Let me know if this is an actual issue or I missed anything.

1 Like

I’m getting the same error. Thanks for including the solution!

Like you said, I also checked the documentation and the steps argument is not included in plot_function()

To check the documentation:

doc(plot_function)
2 Likes

Hi @jeremy , @muellerzr

Do we need a fix for this issue for this version of fastbook?

Kindly, let me know!

Thanks for confirming!!

I had also got same error. Many thanks @Amay for above solution .
You saved my day.As fast.ai team should merge your solution into their main branch @fastai_geek

I just double-checked and it’s working for me with the latest version of fastbook. I’ve just pushed another release just in case. Can you upgrade and try again please?

1 Like

Sure, will try with the upgrade.

Thanks for confirming!!

Thanks for the reply @jeremy

I was having the same issue as @Amay and I believe the latest version you released fixed the problem.

I was able to fix the problem with the following steps:

  1. Uncomment and run !pip install -Uqq fastbook in the first cell.
  2. Restart and run the kernel (I’m using a GPU on Azure ML).

This should fix the TypeError: linspace() missing 1 required positional arguments: "steps" error from plot_function().

Hope this helps :slight_smile:

Hi guys, for some who want a workaround, I fix the parameter -stepsize- of the torch’s linespace function to 100 (in the plot_function method located in utils.py file) value that based on what I read was the default, and it works now