[Errorbar plot] How to set letters/word on x axis properly?

Hello folks,
I'm using this code to create an error bar plot
errorbar(1:1:34,[cell{2,:}],[cell{3,:}],'o');
which results in
When I try add specific names to the x axis with
set(gca,'XtickLabel', cell(1,:));
This happens:
Where i expect the x axis to fill with all supplied names.
cell(1,:)
has the same format as well as the same size as the other ones. Can someone help me?

 Akzeptierte Antwort

Star Strider
Star Strider am 31 Aug. 2017
You didn’t post ‘all the supplied names’ or other details, so writing specific code for your problem is not possible.
Adapt this idea:
Cell{1} = {'k','d','X','b','f'};
figure(1)
plot(1:5, rand(1,5), 'o')
set(gca, 'XTick',1:5, 'XTickLabel',Cell{1})
set(gca, 'XLim',[0 6])

4 Kommentare

You're right, sorry.
kdXbf is one variable name. here is a part of the cell I'm using:
My code
names = names';
VMT = num2cell(ValFinMean);
VMHT = num2cell(ValFinMeanHalf);
cell = [names; VMT; VMHT];
figure;
errorbar(1:1:34,[cell{2,:}],[cell{3,:}],'o');
set(gca,'XtickLabel', cell(1,:));
is working if I plot using bar. But it is not working for errorbar.
Maybe it has something to do with how MATLAB assigns the values in the plot to the axis?
Again, without your data, writing specific code is impossible. The errorbar function does not seem to be the problem.
This works for me:
Cell{1} = {'kdXbf','f0_fl','qwerty','uiop','asdf'};
figure(1)
errorbar(1:5, rand(1,5), 0.1*randn(1,5), 'o')
set(gca, 'XTick',1:5, 'XTickLabel',Cell{1}, 'TickLabelInterpreter','none')
set(gca, 'XLim',[0 6])
Note Setting 'TickLabelInterpreter','none' is necessary so that 'f0_fl' prints as it exists in your cell array. Otherwise the underscore is interpreted as printing the following character as a subscript.
Moritz Pohl
Moritz Pohl am 31 Aug. 2017
Bearbeitet: Moritz Pohl am 31 Aug. 2017
Thanks Star Strider,
I've set my default interpreter to latex.
'TickLabelInterpreter','none'
did the trick. Also,
'XTick',1:34
was necessary to show all labels. Is there a way to change the font of the labels to latex back again?
As always, my pleasure.
The default interpreter is 'latex' since you set it that way. Setting it using gca (‘get current axes’) affects only that axes object, so there is no need to reset it for others. The 'latex' interpreter remains the default.
It’s good practice to always specify 'XTick' locations first when you’re specifying 'XTickLabel' to be certain the labels are plotted where you want them. (I also did that in my example code.)

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Community Treasure Hunt

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

Start Hunting!

Translated by