Adding XYZ axis in RGB colors in the corner of a plot

22 次查看(过去 30 天)
Hello,
Is there any way I can add XYZ coordinate frame in a corner of a plot in Matlab? I have seen many times, reference coordinate frame is shown in the corner. I would like to use RGB colors to represent X Y and Z axis. The attached picture shown what I would like to have in the corner. Thanks

采纳的回答

Chunru
Chunru 2022-10-3
plot(rand(10,1))
annotation('arrow', [0.8, 0.7], [0.8, 0.75], 'Color', 'r')
annotation('textbox', [0.68, 0.70 0.05 0.05], 'String', 'x', 'Color', 'r', 'EdgeColor', 'none')
annotation('arrow', [0.8, 0.9], [0.8, 0.75], 'Color', 'g')
annotation('textbox', [0.9, 0.75 0.05 0.05], 'String', 'y', 'Color', 'g', 'EdgeColor', 'none')
annotation('arrow', [0.8, 0.8], [0.8, 0.9], 'Color', 'b')
annotation('textbox', [0.8, 0.9 0.05 0.05], 'String', 'z', 'Color', 'b', 'EdgeColor', 'none')

更多回答(1 个)

George Abrahams
George Abrahams 2023-12-14
编辑:George Abrahams 2024-3-20
Heres what I think is a pretty nice solution. The coordinate system bases (arrows) are plotted with my plotframe function on File Exchange.
% The main axes containing the object or data of interest.
axObj = axes;
[ X, Y, Z ] = peaks( 25 );
mesh( axObj, X, Y, Z ./ 3 )
% The small, corner axes containing the coordinate system plot.
axIcon = axes( Position=[0.75 0.75 0.2 0.2] );
plotframe( Parent=axIcon, LabelBasis=true )
% Synchronise the axes cameras.
linkprop( [axObj axIcon], [ "View", "CameraUpVector" ] );
% Some beautification.
set( gcf, Color=axObj.Color )
set( axIcon, CameraViewAngleMode="manual", ...
Color="none", XColor="none", YColor="none", ZColor="none" )
set( [axObj axIcon], DataAspectRatio=[1 1 1], PlotBoxAspectRatio=[1 1 1], View=[50 30] )

类别

Help CenterFile Exchange 中查找有关 Line Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by