No module named 'matplotlib'

(macOS, macports, python3.11)
The notebook used to work under jupyter (that I formerly had installed using anaconda3/conda). Since I removed the latter, and relied on the macport installation (python 3.11) things got weird.
In the notebook I’m getting:

import matplotlib.pyplot as plt
import numpy as np
import csv
import math

---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
Cell In[4], line 2
      1 #%matplotlib inline
----> 2 import matplotlib.pyplot as plt
      3 import numpy as np
      4 import csv

ModuleNotFoundError: No module named 'matplotlib'
$ port installed | grep matplotlib
  py311-matplotlib-inline @0.1.7_0 (active)
  py313-matplotlib-inline @0.1.7_0 (active)
$ 

There’s nothing weird. You uninstalled a reliable option and installed new things where you haven’t set things up yet.
This is why uninstalling and going with something completely different is often a chore you want to consider undertaking carefully.

Anaconda/conda comes with all sorts of project management that helps keep things running smoothly with different projects if you adopt the style of work expected there.
Opting into managing things yourself, you have to take more of active role.

Luckily in this case matplotlib is easy to ensure it installs in the correct location by running the install inside the notebook where you wish to use it.
So make a new cell at the top of this notebook and run in that cell %pip install matplotlib and when that completes successfully, restart the kernel and you should be all set. The magic symbol is important so make sure you include it.
The magic pip command variation was added in 2019 to ensure the install occurs in the environment where the kernel is running that backs the active notebook. See more about the modern %pip install command here.

Your macports is installing where Jupyter doesn’t utilize so you can either connect it to that or do what I suggest here to ensure you install to where the Jupyter kernel expects.