Im trying to plot a linear combination in a 3d plane, subset of two vectors, with julia and plots and I’m failing with this tasks. Julia plots works a bit different than matplotlib.
What is the correct way to do that?
let
gr()
# x-axis range
xlim = [-4,4];
a = [3, 5, 1];
b = [0, 2, 2];
xscalars = rand(xlim[1]:xlim[2], 100);
@info xscalars;
yscalars = rand(xlim[1]:xlim[2], 100);
@info yscalars;
c = [(a * xs) + (b .* ys) for (xs, ys) in zip(xscalars, yscalars)];
@info c;
scatter(a, b, c)
end
Note that you could avoid the vector of vectors and generate x, y, z components from the start. See the simple method below using a generator expression:
using Plots; gr()
xlim = -4:4
a, b = [3, 5, 1], [0, 2, 2]
xs, ys = rand(xlim, 100), rand(xlim, 100)
x, y, z = (a*xs + b*ys for (a,b) in zip(a,b))
scatter(x, y, z)