Add spoke labels in glyphplot

I am using glyplot to create star plots to visualize several statistical metrics of performance for a model. However, I cannot figure out how to add labels to each individual spoke of the star plot. I have used gca to get all of the axes properties, but have been unable to find any successful way to add spoke labels. I see another user asked this same question a number of years ago, but it was never answered satisfactorily (https://www.mathworks.com/matlabcentral/answers/345558-how-can-i-label-the-individual-spokes-in-a-glyph-plot). Can anyone help?

3 个评论

Adam Danz
Adam Danz 2020-6-22
编辑:Adam Danz 2020-6-22
To be clear, is your goal to label each line segment or each of the vertices?
Also, you mentioned that it's a start plot which is helpful. I just want to confirm that it is indeed a starplot and not a face plot which is also an option with the glyphplot.
Lastly, do you have a vector of labels or do you just want to label them numerically?
My goal is to label each line segment. So, for example, I have 4 statistical metrics that I want to visualize on a star plot with normalized units, i.e. the absolute values of each metric will be scaled between [0,1]. So, the star plot would have 4 'spokes' and I want to label each of them with the name of the metrics (e.g. CV, bias, MAE, % wins) .
Yes, it is indeed a star plot and not a face plot.
And finally, I want to use an array (cell) to supply the spoke labels.
Adam Danz
Adam Danz 2020-6-22
编辑:Adam Danz 2020-6-24
Good. All you need to do is adapt my demo to your data.
Replace the labels in my data with the labels from your cell array.

请先登录,再进行评论。

回答(1 个)

Adam Danz
Adam Danz 2020-6-22
编辑:Adam Danz 2020-6-23
h = glyphplot(X,...) returns the handle to all line and text objects created within the function. For a star plot, h(:,1) and h(:,2) contain handles to the line objects for each star's perimeter and spokes, respectively.
From the line handles, you can get the endpoint coordinates. The endpoint coordinates can be used to compute the midpoint of each line segment.
This demo shows how to label the midpoints of each spoke with numbers 1:n and the midpoint of each perimeter segment with letters 'a' to 'z'. You can adapt the demo to use your own labels.
The demo uses labelpoints() from the file exchange but that function could be replaced with Matlab's text() function if needed.
See the inline comments for important details.
% Load a built-in Matlab dataset
load carsmall
% Produce a glyphplot; save the output handle 'h' !
X = [Acceleration Displacement Horsepower MPG Weight];
h = glyphplot(X,'standardize','column','obslabels',Model,'grid',[2 2],...
'page','scroll');
% Get the handle to axes using the glyphplot output handle
ax = h(1).Parent;
% Hold the axes if needed.
hold(ax, 'on')
% These two lines are not necessary but they will add axis ticks
% which may be helpful when troubleshooting.
ax.XTickMode = 'auto';
ax.YTickMode = 'auto';
% The perimeter labels will be letters a:z (note, this demo only supports
% glyphs that have less than 27 perimeter segments.
perimeterLabels = num2cell(('a':'z')')'; % only supports up to 26 perimeter labels
% Loop through each glyph handle
for i = 1:size(h,1)
% Compute and label the midpoint of each spoke
idx = 1:3:numel(h(i,2).XData);
xCnt = sum([h(i,2).XData(idx);h(i,2).XData(idx+1)],1)/2;
yCnt = sum([h(i,2).YData(idx);h(i,2).YData(idx+1)],1)/2;
labelpoints(xCnt, yCnt, 1:numel(xCnt), 'Center', 'Fontsize', 6, 'axHand', ax); % From file exchange
% Compute and label the midpoint of each perimeter segment
idx = 1:numel(h(i,1).XData)-1;
xCnt = sum([h(i,1).XData(idx);h(i,1).XData(idx+1)],1)/2;
yCnt = sum([h(i,1).YData(idx);h(i,1).YData(idx+1)],1)/2;
labelpoints(xCnt, yCnt, perimeterLabels(1:numel(xCnt)), 'Center', 'Fontsize', 6, 'axHand', ax); % From file exchange
end
To use Matlab's text() function instead of labelpoints,
text(ax, xCnt, yCnt, LABEL_ARRAY, 'Fontsize', 6, ...
'HorizontalAlignment', 'Center', 'VerticalAlignment','Middle');

类别

帮助中心File Exchange 中查找有关 Axis Labels 的更多信息

产品

版本

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by