jkazan
jkazan

Reputation: 1199

Multiple axes for a single surf plot

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

Upvotes: 3

Views: 188

Answers (1)

jkazan
jkazan

Reputation: 1199

% 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');

Upvotes: 1

Related Questions