Warm tip: This article is reproduced from stackoverflow.com, please click
gnuplot graphics matlab octave plot

Shading command produces different results in MATLAB and Octave

发布于 2020-04-23 18:47:05

The commands shading faceted and shading interp produce different figures in MATLAB and Octave.

Consider this code:

[X, Y] = meshgrid(0:2, 0:2);
Z = magic(3);

figure;
colormap('jet');

subplot(1, 3 ,1);
imagesc(Z);
axis xy
yticklabels({'0', '1', '2'})
yticks(1:3)
xticklabels({'0', '1', '2'})
xticks(1:3)
title('imagesc(Z)');

subplot(1,3,2);
surf(X, Y, Z);
shading faceted;
view([0,0,1]);
yticks(0:3)
xticks(0:3)
title('surf(X, Y, Z); shading faceted;');

subplot(1,3,3);
surf(X, Y, Z);
shading interp;
view([0,0,1]);
yticks(0:3)
xticks(0:3)
title('surf(X, Y, Z); shading interp;');

This is the result in MATLAB: enter image description here

And the result generated by Octave:

enter image description here

MATLAB generates a correct figure.What is wrong with this Octave figure?

What is the reason we get two different outputs? Is it an issue with to the view command?

EDIT (After Bug Report)

It's been fixed for Ocatve 6.1: https://hg.savannah.gnu.org/hgweb/octave/raw-file/11072ea6a16c/scripts/plot/appearance/view.m

Questioner
sci9
Viewed
58
Andrew Janke 2020-02-12 23:13

Your code looks right. I can reproduce in Octave 4.4 and 5.2 on macOS.

Throw in an xlabel('X Axis'); call to clarify what's going on.

This sure looks like a bug in Octave's implementation of view. It appears the X and Y axes are getting swapped. Could you report this as a bug on the Octave issue tracker at https://savannah.gnu.org/bugs/?group=octave?