필터 지우기
필터 지우기

Label 3D axes on multiple sides

조회 수: 15 (최근 30일)
Eugenio Grabovic
Eugenio Grabovic 2021년 1월 28일
댓글: Eugenio Grabovic 2021년 1월 29일
Hi,
i need a way to label different sides of axes which contain a surface. Basically i need to label each edge of my meshgrid boundaries.
What i would like to achieve is something like this

채택된 답변

Adam Danz
Adam Danz 2021년 1월 28일
편집: Adam Danz 2021년 1월 28일
Unfortunately you can only label one side of each axis using the xlabel, ylabel, zlabel functions.
A common workaround in Matlab is to add a second invisible axis that hosts the second set of axis labeles on the other side of the axes but XAxisLocation and YAxisLocation which determine the side of the axis and label are only supported in 2D axes and there is no ZAxisLocation. Double bummer.
If this is for publication or will be inserted into a document, I recommend labeling the axes outside of Matlab (powerpoint, for example).
A workaround in Matlab for 3D axes is to use annotation or text to add what appears to be an axis label but behaves slightly differently. Text objects are anchored to data units and annotation objects are anchored to normalized figure units. So if you use text() you must do so after setting the final axis limits, rotation, and view and if you pan the data, the pseudo-axis-labels will move along with it. If you use annotation() and the axis size adjust or rotates, the label will not follow. Of course you could set up a listener to fix that.
Here's a simple example using text().
This pseudo axis labels are highly customized to the current viewing angle and it will not look as nice if the axis is rotated!
fig = figure();
ax = axes(fig);
[X,Y,Z] = peaks(25);
surf(ax, X,Y,Z)
box on
xlabel(ax, 'Real x label')
ylabel(ax, 'Real y label')
zlabel(ax, 'Real z label')
xlim(ax, [-3 3])
ylim(ax, [-3 3])
zlim(ax, [-8 8])
xlmax = max(xlim(ax))+range(xlim(ax))*.05;
ylmax = max(ylim(ax))+range(ylim(ax))*.05;
ylmin = min(ylim(ax))-range(ylim(ax))*.05;
zlmax = max(zlim(ax))+range(zlim(ax))*.05;
x2lab = text(mean(xlim(ax)), ylmax, zlmax, 'Pseudo-x-label','Rotation',15,'HorizontalAlignment','center');
y2lab = text(xlmax, mean(ylim(ax)), zlmax, 'Pseudo-y-label','Rotation',-25,'HorizontalAlignment','center');
z2lab = text(xlmax, ylmin, mean(zlim(ax)), 'Pseudo-z-label','Rotation',-90,'HorizontalAlignment','center');
set([x2lab, y2lab, z2lab],'FontName', ax.FontName, 'FontSize', ax.FontSize);
  댓글 수: 1
Eugenio Grabovic
Eugenio Grabovic 2021년 1월 29일
Thank you, that will do just fine.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Graphics Object Properties에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by