There is currently no built-in MATLAB function that can achieve this behavior for 3-D plots, as PLOTYY can for 2-D plots. However, there are two possible workarounds that can be used to achieve a similar behavior:
1) Scale your data such that all z-values are in a comparable range, then plot all data on a single set of axes using the HOLD ON command. For example,
[x,y,z] = sphere(16);
bigz = z*100;
scatter3(x(:),y(:),z(:),'bo')
hold on
scatter3(x(:),y(:),bigz(:)/100,'r*')
2) Plot your data on separate axes placed at the same position, with all but one of the axes rendered invisible. This workaround involves manipulating axes properties with the SET and GET functions. For example,
[x,y,z] = sphere(16);
bigz = z*100;
scatter3(x(:),y(:),z(:),'bo')
posAx1 = get(gca,'Position');
hAx2 = axes('Position',posAx1);
scatter3(hAx2,x(:),y(:),bigz(:),'r*')
set(hAx2,'Visible','off');
Though both these workarounds should enable you to view data sets of disparate magnitude together in a single plot area, neither unfortunately enables multiple z-axis labels and numberings. Axis locations in 3-D plots in MATLAB currently cannot be changed. Hence, only one z-axis can be displayed legibly at a time in 3-D plots, whereas two y-axes can be displayed simultaneously in 2-D plots (i.e. by placing one on either side of the plot area as PLOTYY does).
2 Comments
Richard Yu (view profile)
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/95949-is-there-a-function-to-include-two-3-d-plots-with-different-z-axes-on-the-same-plot-area-similar-to#comment_776327
Walter Roberson (view profile)
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/95949-is-there-a-function-to-include-two-3-d-plots-with-different-z-axes-on-the-same-plot-area-similar-to#comment_776340
Sign in to comment.