Label 3D axes on multiple sides
21 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Eugenio Grabovic
am 28 Jan. 2021
Kommentiert: Eugenio Grabovic
am 29 Jan. 2021
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
0 Kommentare
Akzeptierte Antwort
Adam Danz
am 28 Jan. 2021
Bearbeitet: Adam Danz
am 28 Jan. 2021
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);
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Annotations finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!