How is it possible to draw a quadratic bi-variate expression in Python? For example, the following expression:
-0.5x^2 - 0.5y^2 +0.5 xy + x + y + 0.3 = 0
Is it necessary to convert it to Polar system?
How is it possible to draw a quadratic bi-variate expression in Python? For example, the following expression:
-0.5x^2 - 0.5y^2 +0.5 xy + x + y + 0.3 = 0
Is it necessary to convert it to Polar system?
Here is an approach using sympy, Python's symbolic math library:
from sympy import symbols, Eq
from sympy.plotting import plot_implicit
x, y = symbols('x y')
plot_implicit(Eq(-0.5*x**2 - 0.5*y**2 + 0.5*x*y + x + y + 0.3, 0))
Using numpy and matplotlib, you can create a grid of coordinates and call plt.contour
with a contour level of 0:
import matplotlib.pyplot as plt
import numpy as np
x1d = np.linspace(-1, 5, 50)
y1d = np.linspace(-1, 5, 50)
x, y = np.meshgrid(x1d, y1d)
f = -0.5 * x ** 2 - 0.5 * y ** 2 + 0.5 * x * y + x + y + 0.3
fig, ax = plt.subplots()
ax.contour(x, y, f, levels=[0], colors='dodgerblue')
ax.scatter(x=[0.24881, 3.75119], y=[0.24881, 3.75119], color='crimson') # draw two points in matplotlib
ax.set_aspect('equal')
plt.show()