The simulation below represents a generic scalar field in two dimensions. A number of preset fields are available in the simulation or a custom equation can be used. Use the simulation to investigate how a scalar field can be pictorially represented. There are several different representations in the simulation.
Now make use of the simulation below which shows an arbitrary field and its gradient (only the field is shown in the surface plot). Move the mouse in the field of view to see field and gradient values. Try the following
% Calculate a grid of points from -2-2 with 100 points in each direction [x,y] = meshgrid(linspace(-2,2,100),linspace(-2,2,100)); % Calculate the scalar field f = x.*x + y.*y; % Bowl (.* means multiply element by element) % False colour plot figure(1) pcolor(x,y,f); colormap('Hot'); % Set colourmap axis image; % Makes the x and y axes have equal step size shading interp; % Interpolates % Contour plot figure(2) limits = linspace(0, max(max(f)), 10); contour(x,y,f,limits); axis image % Surface plot figure(3) surf(x,y,f);
# The function to plot # Gnuplot can also plot a (scalar) datafile using `splot 'datafile' u 1:2:3` f(x, y) = x*x + y*y set multiplot layout 1,3 title "2-D Scalar Field Plotting" font ",14" set zrange [0:9]; set xrange [-3:3]; set yrange [-3:3]; set samples 40; set isosamples 21 # Colour plot set title "False Colour" set pm3d map splot f(x, y) notitle unset pm3d; unset view # Contour plot set title "Contour" set contour; set view map; unset surface set cntrparam levels incr 0,1,9 splot f(x, y) notitle unset contour; unset view; set surface # Surface plot set title "Surface" splot f(x, y) notitle unset multiplot
import numpy as np from mpl_toolkits.mplot3d import Axes3D # For surface plot import matplotlib.pyplot as plt # Calculate a grid of points from -2-2 with 100 points in each direction x,y = np.meshgrid(np.linspace(-2,2,100),np.linspace(-2,2,100)); # Calculate the scalar field f = x**2 + y**2; # False colour plot plt.figure(); plt.pcolor(x,y,f); plt.colorbar(); # Contour plot plt.figure(); limits = np.linspace(0, np.amax(f), 10); plt.contour(x,y,f,limits); # Surface plot fig = plt.figure(); ax = fig.gca(projection='3d') ax.plot_surface(x,y,f); plt.show();