Home > Net >  Piecewise impclit functions in matplotlib (Python)
Piecewise impclit functions in matplotlib (Python)

Time:01-19

I would like to plot the function x^3 - 3xy y^3 = 0 (Folium of Descartes) but with different colors in quadrant 2 and 4, and at the peak of the leaf I want the colors to change. I was thinking about converting to a piecewise parametric equation to make the plotting in different colors easier, but I don't know how to convert into a parametric form.

I was originally using a contour to plot the function only in one color, but I have no idea how to get the color changes.

Below is what I have for the single color, but I would like to have separate colors for each of the segments listed above.

import matplotlib.pyplot as plt
import numpy as np


xrange = np.arange(-5, 5, .025)
yrange = np.arange(-5, 5, .025)
X, Y = np.meshgrid(xrange, yrange)

plt.contour(X, Y, X**3 - 3*X*Y   Y**3, levels=[0], colors=['#000000'])

plt.show()

CodePudding user response:

visualizing the folium of Descartes

Copying the leave 4 times, and filling them in decreasing order creates the following plot.

import matplotlib.pyplot as plt
import numpy as np

for a in np.linspace(1, 0.001, 50):
    theta = np.linspace(0, np.pi / 2, 500)
    rho = 3 * a * np.sin(theta) * np.cos(theta) / (np.cos(theta) ** 3   np.sin(theta) ** 3)
    x = rho * np.cos(theta)
    y = rho * np.sin(theta)
    for i in [-1, 1]:
        for j in [-1, 1]:
            plt.fill(i * x, j * y, c=plt.cm.summer(1 - a))
plt.axis('equal')
plt.axis('off')
plt.show()

Descartes' folium filled and repeated

  • Related