Your code runs fine on my system.
This error has popped up several time in this post, for instance at Segmentation fault upon importing matplotlib into a dolfinx . Consider using the search button for more results. Overall, this sort of problem is typically related to how you installed dolfinx and matplotlib, so you’ll need to provide us more details on that.