user2898538
user2898538

Reputation: 11

How do I plot a 3D graph in 2D with color in octave?

I have a function z=f(x,y) and want to plot it using octave, but don't want the plot to be in 3d, as in

octave:1> x=(1:300);
octave:2> y=(1:300);
octave:3> [xx,yy]=meshgrid(x,y);
octave:4> A=sin(xx/100).*yy;
octave:5> mesh(x,y,A)

but rather in 2d using colors for the values of z, like what you get using the gnuplot instruction

gnuplot> plot 'a.txt' matrix w image

if I save the matrix A in the file a.txt. The closest I have found is the command contourf, but the as you can see if you try it,

octave:7> contourf(xx,yy,A)

the result is far from optimal... Any suggestion?

Thanks

Upvotes: 1

Views: 4803

Answers (1)

Dan Getz
Dan Getz

Reputation: 9134

imagesc will plot a matrix of your "z" values using colors:

> imagesc(x, y, A)

This will be inverted vertically compared to contourf, but that's easily fixed:

> imagesc(x, flipud(y), flipud(A))

And in your example you don't even need to provide the variables x and y:

> imagesc(A)
> imagesc(flipud(A))

Upvotes: 2

Related Questions