Clear Filters
Clear Filters

How can I add a title using slice plots?

2 views (last 30 days)
Hey folks,
this is my first question in a forum ever XD (confetti)
I have a volume of measured data and found "slice" beeing perfect to plot those, but I dont know how to add a title and axes labels afterwards.
[Y,X,Z] = meshgrid(Ycm, Xcm, Zcm);
xslice = [Xcm(1),Xcm(2),Xcm(3),Xcm(4),Xcm(5),Xcm(6),Xcm(7)]; yslice = []; zslice = []; %no slices in y or z planes
sliceplot = slice(Y,X,Z, umat, yslice,xslice,zslice);
title='test'; -> gives me nothing
sliceplot.Title='test'; -> gives me "Expected one output from a curly brace or dot indexing expression, but there were 7 results."
sliceplot(1,1).Title='test'; -> gives me "Unrecognized property 'Title' for class 'matlab.graphics.primitive.Surface'."
(I know that I can add a title manually, but there is a lot of data to be plot, so an automatic command seems useful to me)
How can I access the plot features?
~~~~~~~~~~~~~~~
found it, title('test'); works, but still, is there a way to access the plot afterwards?
  3 Comments
Adam
Adam on 25 Apr 2019
The title is a property of the axes, not the slice graphics object so you wouldn't expect:
sliceplot.Title='test';
or
sliceplot(1,1).Title='test';
to work. And
title='test';
just assigns the chars 'test' to a variable named title.
Code has to follow rules, we can't just type things that look intuitive and assume it will magically work as code!
doc title
will give information on adding titles.
Adam
Adam on 26 Apr 2019
Properties of the slice graphics object itself are available on
slicePlot
If you want axes properties then you can get these from the axes handle, which is usually best to acquire right at the start of the process. I don't like using gca, but in the following case I find it acceptable if I am just writing a script:
figure; hAxes = gca;
Then I can use hAxes as my fixed graphics handle from there onwards.

Sign in to comment.

Accepted Answer

Adam Danz
Adam Danz on 26 Apr 2019
Edited: Adam Danz on 26 Apr 2019
Here's a functional demo of Adam's and Kalyan's suggestions. I added a different method of getting the axis handle.
% Create slice plot
[X,Y,Z] = meshgrid(-2:.2:2);
V = X.*exp(-X.^2-Y.^2-Z.^2);
xslice = [-1.2,0.8,2];
yslice = [];
zslice = 0;
h = slice(X,Y,Z,V,xslice,yslice,zslice); %grab output handle(s)
% Get axis handle
axh = h(1).Parent; %alternative: axh = gca;
title(axh, 'title')
xlabel(axh, 'x')
ylabel(axh, 'y')
zlabel(axh, 'z')

More Answers (0)

Community Treasure Hunt

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

Start Hunting!