In earlier posts we have seen how we plot functions of one independent variable. Such a diagram is built by two axes and a line; for a given value on an axis we can read out a corresponding value on the other depending the function. But what if we have two independent variables?
There are 3D graphs, but in some situations they may be hard to read. The alternatives I’m going to present here is a representation of the values in a bitmap with different colors as well as level curves.
This is great! We’ve got a graphical representaion of our array. Each color maps a correponding value in the array and the scale of each axis represents the position of a value in the array.
As you might expect, we can make much larger arrays and visualize the values by colors.
Of course, the usual way to fill an array it’s not by typing it on the keyboard. Let’s create an array with values resulted from a calculation of two independent variables. We soon will see how we can achive the array just below quite simple from two 1d arrays.
Array of values combined by an arbitrary function.
or may not be equal.
Say we want $x$ as well as $y$ values in the domain $-5\leq x,y\leq 5$ and we want to plot the sum of the sine values for a large number of combinations of $x$ and $y$.
# the sines for each value of x and y.
# z will be a 125x125 array in this case.
# need to move it to the lower left.
Yes! We have colorized the range of the equation $z=\sin x + \cos x$. We see the “hot spots” (yellow spots, close to 2) and the “cold spots” (violette spots, close to -2) building a periodic pattern over the $xy$-plane.
Here, we may get an idea of which pairs of $x$ and $y$ satisfying a given equation, e.g. $\sin x + \sin y = 1.4$.
We don’t need to go so advanced as trigonometric sums like above. For me, as a maths teacher, I think I even can make use of a similar plot with stright lines. The equation of a straight line is $Ax + By + C = 0$, for some constants $A$, $B$ and $C$. Or why not a circle, $r^2=(x+a)^2+(y+b)^2$, for some constants $a$ and $b$.
ax.set_aspect(10) # scale of x axis 10 times the scale of y.
