0

my function f takes a vector of the form (1, x, y) and the output is a real number.

I want to plot a line such that f(1,x,y)==0 in x-y plane.

My attempt :

delta = 0.025
xrange = arange(0, 12, delta)
yrange = arange(0, 12, delta)
p, q = meshgrid(xrange, yrange)

mesh_point = []
for i in range(len(p[0])):
    for j in range (len(q[0])):
        mesh_point.append([p[0][i], q[0][j]])

for i in range (0, len(p[0])):
plt.contour(p, q, (y1([1, p[0][i], q[0][i]])-y2([1, p[0][i], q[0][i]])) , [0])
plt.show()   

here f = y1(...)-y2(...)

Anyone can help?

user88914
  • 123
  • 6

1 Answers1

0

You can draw a contour line at f(1,x,y) = 0 by supplying the left hand side to contour and choosing a single level (0).

import matplotlib.pyplot as plt
import numpy as np

delta = 0.025
x = np.arange(0, 12, delta)
y = np.arange(0, 12, delta)
p, q = np.meshgrid(x, y)
# define some function f(n,x,y)
f = lambda n, x, y: np.sin(np.sqrt(np.abs(x-3-0.5*y)**1.5))+np.exp(-(y-6)**2)-1
z=f(1, p,q)

# plot contour line of f(1,x,y)==0
plt.contour(p, q, z , [0], colors=["k"])

#make legend
proxy, = plt.plot([], color="k")
plt.legend(handles=[proxy], labels=["f(1,x,y) = 0"])
plt.show()  

enter image description here

ImportanceOfBeingErnest
  • 321,279
  • 53
  • 665
  • 712