Home > Software engineering >  Labeling points on the x axis in matlab
Labeling points on the x axis in matlab

Time:04-19

I have a table, named "Log_mean" a quick example of this:

numberID Score Model
1 0.3 a
2 0.2 b

I have Plotted the ID against score using the following code:

plot(Log_mean.numberID, Log_mean.Score, '--o');
title('Mean of Log scores.')
ylabel('Score')
xlabel('Models')

Which produces the following graph: Log mean graph

My question is, as each circle represents the score for a particular model, is it possible for me to name each of those points on the x-axis using the column model in my table?

Thank you.

CodePudding user response:

Yes, you just need a categorical axis

xlabs = categorical( Log_mean.Model, Log_mean.Model ); % using the 2nd input preserves ordering

Then you can plot it

plot( xlabs, Log_mean.Score, '--o' );

If you want to combine the model and the ID, you can do that a number of ways. Something like this would work:

xlabs = arrayfun( @(x) sprintf('%d - %s', Log_mean.numberID(x), Log_mean.Model{x}), 1:height(Log_mean), 'uni', 0 );
xlabs = categorical( xlabs, xlabs );

plot( xlabs, Log_mean.Score, '--o' );
  • Related