0

Using Python, is it possible to plot implicit equations in x and y?

E.g.,
                                  x³ y² + 3 x y + 9 x + x⁴ y⁴ + x⁴ + 3 = 0

or, using a Python-like notation

x**3*y**2 + 3*x*y + 9*x + x**4*y**4 + 3 = 0
2
  • 1
    have you tried it? Commented Apr 16, 2020 at 5:29
  • You probably want to look at Plotting a polynomial in python Commented Apr 16, 2020 at 5:29

1 Answer 1

1

You can plot an implicit function using the external library SymPy, namely using sympy.plot_implicit that in turn uses Matplotlib under the hood:

from sympy import symbols, plot_implicit
x, y = symbols('x y')
plot_implicit(x**3*y**2+3*x*y+9*x+x**4*y**4+x**4+3, x, y)

enter image description here

Another option, less direct than the use of SymPy, is to stretch the usage of plt.contour in Matplotlib

In [1]: import matplotlib.pyplot as plt 
   ...: import numpy as np 
   ...:  
   ...: %matplotlib 
   ...:  
   ...: X = np.linspace(-4, 4, 201) 
   ...:  
   ...: x, y = np.meshgrid(X, X)                                                          

In [2]: z = x**3*y**2+3*x*y+9*x+x**4*y**4+x**4+3                                          

In [3]: plt.contour(x, y, z, (0,))                                                        
Out[3]: <matplotlib.contour.QuadContourSet at 0x7fb866c805d0>

(note that (0,) is a tuple containing all the values for which you want to draw an isoline)

enter image description here

Sign up to request clarification or add additional context in comments.

2 Comments

Okay, I will definitely try this out, thank you so much!
Two weeks later. Have you tried my solutions? Did it work for you?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.