Draw implicit function in python

Implicit function drawing

An implicit function is $ f (x, y) = 0 $, which is difficult to transform into an explicit shape. Yen $ x ^ 2 + y ^ 2-1 = 0 $ is a typical example. It's not impossible to transform it, but it's not very smart when drawing graphs because it requires case classification. In such cases, contour is convenient.

python


import matplotlib.pyplot as plt
import numpy as np

delta = 0.025
xrange = np.arange(-2, 2, delta)
yrange = np.arange(-2, 2, delta)
X, Y = np.meshgrid(xrange,yrange)

#Axis settings
plt.axis([-2, 2, -2, 2])
plt.gca().set_aspect('equal', adjustable='box')

#drawing
Z=X**2+Y**2-1
plt.contour(X, Y, Z, [0])
plt.show()

Plt.contour (X, Y, Z, [0]) in the code draws contour lines with Z = 0. If you specify [-1,0,1], contour lines will be added. It's smart.

Other method

It's pretty short, but I feel like I'm just painting $-\ epsilon <f (x, y) <\ epsilon $.

python


from sympy import *
x, y = symbols("x y")
Z=x**2+y**2-1
plot_implicit(Z, (x, -2, 2), (y, -2, 2))

Execution result

aa.png

Recommended Posts

Draw implicit function in python
Draw graph in python
Draw a graph of a quadratic function in Python
Create a function in Python
Draw mp3 waveform in Python
Use callback function in Python
ntile (decile) function in python
Draw Poincare's disk in Python
Draw "Draw Ferns Programmatically" in Python
Nonlinear function modeling in Python
Immediate function in python (lie)
Draw a heart in Python
python function ①
[Python] function
python function ②
Draw Sine Waves in Blender Python
Implement R's power.prop.test function in python
Included notation in Python function arguments
Draw knots interactively in Plotly (Python)
Draw a scatterplot matrix in python
Write AWS Lambda function in Python
Measure function execution time in Python
Function synthesis and application in Python
Draw a CNN diagram in Python
Quadtree in Python --2
Python in optimization
CURL in python
Geocoding in python
SendKeys in Python
python enumerate function
Meta-analysis in Python
Precautions when pickling a function in python
Unittest in python
Draw Nozomi Sasaki in Excel with python
OR the List in Python (zip function)
Python> function> Closure
Epoch in Python
Discord in Python
[Python] Generator function
Draw a heart in Python Part 2 (SymPy)
Sudoku in Python
DCI in Python
quicksort in python
nCr in python
N-Gram in Python
Programming in python
Plink in Python
Constant in python
Lifegame in Python.
FizzBuzz in Python
Sqlite in python
StepAIC in Python
Draw a tree in Python 3 using graphviz
N-gram in python
LINE-Bot [0] in Python
Python> function> Inner function
Csv in python
Disassemble in Python
Reflection in Python
Duality in function
Constant in python