NotImplementedError: Axes3D currently only supports the aspect argument 'auto'. You passed in 'equal'

I just recently reinstalled fenics in wsl using conda

conda create -n fenics -c conda-forge fenics

And I am trying to run a sample code in fenics

from __future__ import print_function
# from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
%matplotlib inline

from fenics import *
# from dolfin import *
# from mshr import *
from ufl import nabla_div

# Scaled Variables

L = 1
W = 0.2
mu = 1
rho = 1
delta = W/L
gamma = 0.4*delta**2
beta = 1.25
lambda_ = beta
g = gamma

# Create Mesh and define function space

mesh = BoxMesh(Point(0,0,0), Point(L,W,W), 10, 3, 3)
V = VectorFunctionSpace(mesh, 'P', 1)

# Define Boundary Conditions

tol = 1e-14

def clamped_boundary(x, on_boundary):
    return on_boundary and x[0] < tol

bc = DirichletBC(V, Constant((0,0,0)), clamped_boundary)

# Define Strain and Stress

def epsilon(u):
    return 0.5 * (nabla_grad(u) + nabla_grad(u).T)

def sigma(u):
    return lambda_*nabla_div(u)*Identity(d) + 2*mu*epsilon(u)

# Define variational problem

u = TrialFunction(V)
d = u.geometric_dimension() # space dimension
v = TestFunction(V)
f = Constant((0,0,-rho*g))
T = Constant((0,0,0))
a = inner(sigma(u), epsilon(v))*dx
L = dot(f, v)*dx + dot(T, v)*ds


# Compute Solution

u = Function(V)
solve(a == L, u, bc)

# Plot Solution
plot(u)

I encountered this error,

---------------------------------------------------------------------------
NotImplementedError                       Traceback (most recent call last)
<ipython-input-8-570178011df2> in <module>
     60 
     61 # Plot Solution
---> 62 plot(u)

~/anaconda3/envs/fenics/lib/python3.8/site-packages/dolfin/common/plotting.py in plot(object, *args, **kwargs)
    436     # Plot
    437     if backend == "matplotlib":
--> 438         return _plot_matplotlib(object, mesh, kwargs)
    439     elif backend == "x3dom":
    440         return _plot_x3dom(object, kwargs)

~/anaconda3/envs/fenics/lib/python3.8/site-packages/dolfin/common/plotting.py in _plot_matplotlib(obj, mesh, kwargs)
    280     else:
    281         ax = plt.gca()
--> 282     ax.set_aspect('equal')
    283 
    284     title = kwargs.pop("title", None)

~/anaconda3/envs/fenics/lib/python3.8/site-packages/mpl_toolkits/mplot3d/axes3d.py in set_aspect(self, aspect, adjustable, anchor, share)
    321         """
    322         if aspect != 'auto':
--> 323             raise NotImplementedError(
    324                 "Axes3D currently only supports the aspect argument "
    325                 f"'auto'. You passed in {aspect!r}."

NotImplementedError: Axes3D currently only supports the aspect argument 'auto'. You passed in 'equal'.

I think in the plotting.py file the ax.set_aspect("equal") instead of “auto”.

Can you tell me how to bypass this error?

1 Like

This is an old issue in matplotlib. You should be able to reproduce this outside of FEniCS too!

If you want to hack FEniCS’ plot function, then try changing line 282 to ax.set_aspect("auto"). If not, then I would recommend taking a look at @marcomusy’s Vedo examples, or simply using Paraview.

With vedo, you can start at:

from vedo.dolfin import plot as vplot
vplot(u) 
2 Likes

This issue has also been fixed in the master branch of dolfin: https://bitbucket.org/fenics-project/dolfin/commits/5e86e7e3409a8d9ec4b1f40aa2b361d5de84d2a0

2 Likes

Thanks for the help. Now it is working

Hi

I got same error now. How to solve this?

I also try vedo. however each time I run with vplot(u), the kernel dies.

Thank you so much.

Use the latest version of dolfin (master branch) NotImplementedError: Axes3D currently only supports the aspect argument 'auto'. You passed in 'equal' - #3 by dokken