Adding XYZ axis in RGB colors in the corner of a plot
22 views (last 30 days)
Show older comments
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
0 Comments
Accepted Answer
Chunru
on 3 Oct 2022
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')
0 Comments
More Answers (1)
George Abrahams
on 14 Dec 2023
Edited: George Abrahams
on 20 Mar 2024
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] )
0 Comments
See Also
Categories
Find more on Line Plots 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!