Is there a function to include two 3-D plots with different z-axes on the same plot area, similar to the PLOTYY function for 2-D plots in MATLAB 8.1 (R2013a)?
9 views (last 30 days)
Show older comments
MathWorks Support Team
on 17 Apr 2013
Commented: Walter Roberson
on 9 Dec 2019
I want to include two 3-D plots with different z-axes on the same plot area, similar to what PLOTYY does for 2-D plots. This would be helpful for visual comparisons of two data sets featuring z-values of disparate magnitudes.
Accepted Answer
MathWorks Support Team
on 30 Aug 2016
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); % generate sample data
bigz = z*100; % generate scaled z data
scatter3(x(:),y(:),z(:),'bo') % plot sample data
hold on % disable erasing
scatter3(x(:),y(:),bigz(:)/100,'r*') % plot scaled data
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); % generate sample data
bigz = z*100; % generate scaled z data
scatter3(x(:),y(:),z(:),'bo') % plot sample data
posAx1 = get(gca,'Position'); % get position of current axes
hAx2 = axes('Position',posAx1); % create duplicate axes at same position
scatter3(hAx2,x(:),y(:),bigz(:),'r*') % plot scaled data on duplicate axes
set(hAx2,'Visible','off'); % make duplicate axes invisible
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).
1 Comment
More Answers (0)
See Also
Categories
Find more on Two y-axis in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!