# Tutorial 1 - How to run a model plotting function

**URL:** <https://pybamm.discourse.group/t/tutorial-1-how-to-run-a-model-plotting-function/302>\
**Category:** PyBaMM Q&A\
**Created:** [10 April 2025 17:46 UTC](https://pybamm.discourse.group/t/tutorial-1-how-to-run-a-model-plotting-function/302 "2025-04-10T17:46:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![piercarmine](https://avatars.discourse-cdn.com/v4/letter/p/4bbf92/32.png) [@piercarmine](https://pybamm.discourse.group/u/piercarmine)\
**Post date:** [10 April 2025 17:46 UTC](https://pybamm.discourse.group/t/tutorial-1-how-to-run-a-model-plotting-function/302/1 "2025-04-10T17:46:47Z")

</div>

Hi all!  
I tried running the Tutorial 1 notebook on a fresh PyBamm installation, but I am getting an error upon plotting with `sim.plot()`, as the most recent version of `scipy` does not have an `interp2d` function anymore.  
Is this because the function used in the tutorial was substituted by something else?

Full error message:

```auto
---------------------------------------------------------------------------
NotImplementedError Traceback (most recent call last)
Cell In[16], line 1
----> 1 sim.plot()

File c:\Users\Utente\miniconda3\envs\pybamm\Lib\site-packages\pybamm\simulation.py:560, in Simulation.plot(self, output_variables, quick_plot_vars, **kwargs)
    557 if output_variables is None:
    558 output_variables = self.output_variables
--> 560 self.quick_plot = pybamm.dynamic_plot(
    561 self._solution, output_variables=output_variables, **kwargs
    562 )

File c:\Users\Utente\miniconda3\envs\pybamm\Lib\site-packages\pybamm\plotting\dynamic_plot.py:20, in dynamic_plot(*args, **kwargs)
      8 """
      9 Creates a :class:`pybamm.QuickPlot` object (with arguments 'args' and keyword
     10 arguments 'kwargs') and then calls :meth:`pybamm.QuickPlot.dynamic_plot`.
   (...)
     17 The 'QuickPlot' object that was created
     18 """
     19 kwargs_for_class = {k: v for k, v in kwargs.items() if k != "testing"}
---> 20 plot = pybamm.QuickPlot(*args, **kwargs_for_class)
     21 plot.dynamic_plot(kwargs.get("testing", False))
     22 return plot

File c:\Users\Utente\miniconda3\envs\pybamm\Lib\site-packages\pybamm\plotting\quick_plot.py:244, in QuickPlot. __init__ (self, solutions, output_variables, labels, colors, linestyles, figsize, time_unit, spatial_unit, variable_limits)
    239 except TypeError:
    240 raise TypeError(
    241 "variable_limits must be 'fixed', 'tight', or a dict"
    242 )
--> 244 self.set_output_variables(output_variable_tuples, solutions)
    245 self.reset_axis()

File c:\Users\Utente\miniconda3\envs\pybamm\Lib\site-packages\pybamm\plotting\quick_plot.py:270, in QuickPlot.set_output_variables(self, output_variables, solutions)
    268 variables[i] = []
    269 for var in variable_tuple:
--> 270 sol = solution[var]
    271 # Check variable isn't all-nan
    272 if np.all(np.isnan(sol.entries)):

File c:\Users\Utente\miniconda3\envs\pybamm\Lib\site-packages\pybamm\solvers\solution.py:201, in _BaseSolution. __getitem__ (self, key)
    198 return self._variables[key]
    199 else:
    200 # otherwise create it, save it and then return it
--> 201 self.update(key)
    202 return self._variables[key]

File c:\Users\Utente\miniconda3\envs\pybamm\Lib\site-packages\pybamm\solvers\solution.py:168, in _BaseSolution.update(self, variables)
    164 var = pybamm.ProcessedSymbolicVariable(self.model.variables[key], self)
    166 # Otherwise a standard ProcessedVariable is ok
    167 else:
--> 168 var = pybamm.ProcessedVariable(
    169 self.model.variables[key], self, self._known_evals
    170 )
    172 # Update known_evals in order to process any other variables faster
    173 for t in var.known_evals:

File c:\Users\Utente\miniconda3\envs\pybamm\Lib\site-packages\pybamm\solvers\processed_variable.py:109, in ProcessedVariable. __init__ (self, base_variable, solution, known_evals, warn)
    107 # Try some shapes that could make the variable a 1D variable
    108 if base_shape in [n, n + 1]:
--> 109 self.initialise_1D()
    110 else:
    111 # Try some shapes that could make the variable a 2D variable
    112 first_dim_nodes = self.mesh.nodes

File c:\Users\Utente\miniconda3\envs\pybamm\Lib\site-packages\pybamm\solvers\processed_variable.py:249, in ProcessedVariable.initialise_1D(self, fixed_t)
    245 self._interpolation_function = interp_fun
    246 else:
    247 # function of space and time. Note that the order of 't' and 'space'
    248 # is the reverse of what you'd expect
--> 249 self._interpolation_function = interp.interp2d(
    250 self.t_pts,
    251 pts_for_interp,
    252 entries_for_interp,
    253 kind="linear",
    254 fill_value=np.nan,
    255 bounds_error=False,
    256 )

File c:\Users\Utente\miniconda3\envs\pybamm\Lib\site-packages\scipy\interpolate\_interpolate.py:129, in interp2d. __init__ (self, x, y, z, kind, copy, bounds_error, fill_value)
    127 def __init__ (self, x, y, z, kind='linear', copy=True, bounds_error=False,
    128 fill_value=None):
--> 129 raise NotImplementedError(err_mesg)

NotImplementedError: `interp2d` has been removed in SciPy 1.14.0.

For legacy code, nearly bug-for-bug compatible replacements are
`RectBivariateSpline` on regular grids, and `bisplrep`/`bisplev` for
scattered 2D data.

In new code, for regular grids use `RegularGridInterpolator` instead.
For scattered data, prefer `LinearNDInterpolator` or
`CloughTocher2DInterpolator`.

For more details see
https://scipy.github.io/devdocs/tutorial/interpolate/interp_transition_guide.html

```

---

<div class="post-metadata">

**Author:** ![Marc](https://avatars.discourse-cdn.com/v4/letter/m/8dc957/32.png) [@Marc](https://pybamm.discourse.group/u/Marc)\
**Post date:** [10 April 2025 20:45 UTC](https://pybamm.discourse.group/t/tutorial-1-how-to-run-a-model-plotting-function/302/2 "2025-04-10T20:45:05Z")

</div>

Hi @piercarmine, try updating to the latest PyBaMM version. This bug was fixed some time ago.

---

<div class="post-metadata">

**Author:** ![piercarmine](https://avatars.discourse-cdn.com/v4/letter/p/4bbf92/32.png) [@piercarmine](https://pybamm.discourse.group/u/piercarmine)\
**Post date:** [11 April 2025 06:54 UTC](https://pybamm.discourse.group/t/tutorial-1-how-to-run-a-model-plotting-function/302/3 "2025-04-11T06:54:32Z")

</div>

Hi @Marc!

I found that on Python 3.13.2 `pip install `ing PyBaMM installs the 0.2.4.post3 version (which explains why I was getting the old bug I mention in the post). `pip install --upgrade` didn’t seem to work, as it returned requirement already satisfied.

Reverting to Python 3.10.16 `pip install `s correctly PyBaMM 25.4.0 (and the bug no longer appears); `conda install `ing gets version 24.11.2, which also works.

Thank you for your help, not sure what’s going on with Python 3.13.
