Home > Software engineering >  How can i draw a line in all the points where i have 0 value with python (sympy)?
How can i draw a line in all the points where i have 0 value with python (sympy)?

Time:06-04

I want to know all the points where i have the value of 0. And i would like it to show on my plot. Have a redline in all the values to make it obviously. I have no idea on how to do it and i could not find any sympy libiraries that did something similarly to this. This is my code:

import inspect
from IPython.display import display, Math

from sympy import *
xi,eta,b,a = symbols("xi,eta,b,a")
Nq = Matrix([[1,xi,eta,xi**2,xi*eta,eta**2,xi**2*eta,xi*eta**2]])
AINV = Matrix([[1,1,1,1,-b,-a,-b,-a],
               [0,0,0,0,0,2*a,0,-2*a],
               [0,0,0,0,-2*b,0,2*b,0],
               [0,0,0,0,0,a,0,a],
               [1,-1,1,-1,0,0,0,0],
               [0,0,0,0,b,0,b,0],
               [-1,-1,1,1,2*b,0,-2*b,0],
               [-1,1,1,-1,0,-2*a,0,2*a]])
N = Nq*AINV
N1 = combsimp(N[0])
N2 = combsimp(N[1])
N3 = combsimp(N[2])
N4 = combsimp(N[3])
N5 = combsimp(N[4])
N6 = combsimp(N[5])
N7 = combsimp(N[6])
N8 = combsimp(N[7])

NN = Matrix([[N1,N2,N3,N4,N5,N6,N7,N8]])
NN


%matplotlib notebook


Xi = Matrix([0,12,16,8,4,2,4,7])
Yi = Matrix([4,0,12,7,3,5,7,8])

J1 = diff(NN,xi)*Xi
J2 = diff(NN,xi)*Yi
J3 = diff(NN,eta)*Xi
J4 = diff(NN,eta)*Yi

J = Matrix([[J1,J2],[J3,J4]])
JDet = J.det()
JDetPLOT = JDet.subs(a,1).subs(b,1)
plotting.plot3d(JDetPLOT,(xi,-1,1),(eta,-1,1))

CodePudding user response:

You can access the matplotlib axes and later create a 3d contour plot, like this:

p = plotting.plot3d(JDetPLOT,(xi,-1,1),(eta,-1,1))
xx, yy, zz = p[0].get_meshes()
p._backend.ax[0].contour(xx, yy, zz, colors="r", levels=[0])

Note that I set a red line for contour, however this is (most likely) what you are going to see. Matplotlib 3D isn't really that great :|

enter image description here

  • Related