2

If I want to plot something like y=x^2 then I can do something like

x = np.linspace(-10, 10, 1000)
plt.plot(x, x**2)

But how do I go about this if then equation is something like x + y + sin(x) + sin(y) = 0? I would rather not have to solve for y by hand. Is there some function that handles this?

0

2 Answers 2

0

This will do the job:

import matplotlib.pyplot
import numpy as np
X, Y = np.meshgrid(np.arange(-10, 10, 0.05),np.arange(-10, 10, 0.05))
matplotlib.pyplot.contour(X, Y, X + Y + np.sin(X) + np.sin(Y), [0])
matplotlib.pyplot.show()
Sign up to request clarification or add additional context in comments.

1 Comment

Hi Miriam, is there a way to extract the values of y from this plot? I have a function of a rotated cone that I can obtain the plot but I'm not sure how to obtain the values of Z.
0

You can try contour plots:

from matplotlib.pyplot import *

def your_function(x, y):
    return 5 * np.sin(x) - 2 * np.cos(y)

x = np.linspace(-10, 10, 1000)
X, Y = np.meshgrid(x, x)
Z = your_function(X, Y)

CP = contour(X, Y, Z, [0])
grid()
show()

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.