python - How would I plot a function f(x,y) (technically a field) as a colour gradient in Pylab? -


i current trying plot function f(x,y), technically vector a(r) , field if being nit picky.

the plot:

i want plot done on xy graph, f(x,y) represented colour gradient.

for example near point of origin field, f(x,y) larger , therefore darker in colour!

any appreciated, , understand there tutorials have looked at. problem these struggling understand why use syntax like:

from import * or import something else

why that, have been taught do:

import numpy import pylab 

i struggle understand rest of program because syntax unclear , can't find tutorial black , white in answer!

the user has 2 questions: why alias imports, , how "plot" variable of 2 parameters. reason alias imports make code more compact, , therefore easier read. packages have nice long names unlikely collide each other. users' responsibility keep aliases unique within package. from import * convenient not maintainability, since obscures being imported. sake of relating physics, it's writing g=w*e^2, , expecting figure out "i use g energy, w mass , e speed of light."

to plot function of 2 variables:

import numpy np import matplotlib.pyplot plt def f(x,y):    "arbitrary function of 2 variables demonstration"    return np.sinc(x**2 + y**2)  x, y = np.meshgrid(np.arange(-5, 5, 0.01), np.arange(-5, 5, 0.01)) plt.imshow(f(x, y)) plt.show() 

if want gray-scale, use plt.imshow(f(x, y), cmap=plt.cm.gray) , if bothers large values of f(x, y) light rather dark, replace f -f.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

c# - How do I get the Nth largest element from a list with duplicates, using LINQ? -

jsp - "Sending a redirect is forbidden after the response has been committed" in sendRedirect -