3

I have a surf plot, in which I would like to have two y-axes. I cannot seem to find any other discussion quite like this.

The closest I got so far is:

surf(peaks);
view(0,0)
ax(1) = gca;
axPos = ax(1).Position;
ax(2) = axes('Position',axPos, 'Color', 'none','XTick',[],'ZTick',[],'YAxisLocation','right');
linkprop(ax, 'CameraPosition');
rotate3d on
jkazan
  • 1,149
  • 12
  • 29
  • According to [the documentation](http://www.mathworks.com/help/matlab/ref/axes-properties.html#property_yaxislocation) `YAxisLocation` is ignored when switching to a 3D view. – Suever Mar 16 '16 at 14:02
  • 1
    I think You have to 'hack' the system by manually create second axis with ticks and ticklabels yourself. The inspiration may be there: http://www.mathworks.com/matlabcentral/fileexchange/3245-plot3axisatorigin – Crowley Mar 16 '16 at 14:24
  • Thank you both. I will take a look at your link, Crowley, thanks. @Suever: I tried plotting an invisible surf with an offset, in order to bypass the issue you speak of, but without success. – jkazan Mar 16 '16 at 14:37
  • In case it's of interest to you @Crowley and Suever. I figured out a solution, I posted an answer below. Thanks for commenting! – jkazan Mar 17 '16 at 12:17
  • I couldn't tag you both in lats comment so I'll tag you here @Suever. Perhaps this is of interest to you too. Thanks for commenting! – jkazan Mar 17 '16 at 12:34

1 Answers1

1
% Desired plot
surf(peaks);

% Save axis
ax(1) = gca;

% Use the position of the first axis to define the new axis
pos = ax(1).Position;
pos2 = pos - [0.08 0 0 0];
ax(2) = axes('Position',pos2,'Color', 'none');

% Plot random line in 3D, just make sure your desired axis is correct
plot3(ones(length(peaks),1), 10:10:length(peaks)*10,...
    ones(length(peaks),1), 'Color','none')

% Make plot, and non-desired axes, invisible
set(gca,'zcolor','none','xcolor','none','Color','none')

% Link axes
linkprop(ax, 'View');
jkazan
  • 1,149
  • 12
  • 29
  • 1
    You can set all `gca` colours in one command. And mark the question answered. – Crowley Mar 17 '16 at 12:22
  • Of course, not sure why I had three lines for colors. Thank you @Crowley! I cannot accept the answer until tomorrow though. I'll do it asap. – jkazan Mar 17 '16 at 12:24