How to change a single xtick (x label)?
12 次查看(过去 30 天)
显示 更早的评论
Dear Community
Here is the code on how i generated my figure:
x = 1:100;
y = rand (100);
plot(x,y)
I would like to change the zero label on the x-axis with 'no stim', at the same time ALL other values need to remain unchanged. Furthermore they need to stay flexible (Without magic numbers). Do you know how to do that?
0 个评论
采纳的回答
Star Strider
2023-1-30
Perhaps something like this —
x = 1:100;
y = rand (100);
figure
plot(x,y)
xt = xticks;
xticklabels([{'No Stim'} compose('%3d',xt(2:end))])
This simply concatenates {'No Stim'} with the cell array created by compose to create the rest of the cell array defining the rest of the xticklabels.
.
4 个评论
Star Strider
2023-2-1
I get the impression that you are plotting the black line (and what appears to be a 'pchip' interpolant) first, and then the green value and errorbar separately. (I can’t follow the code snippet.)
It would really help to have your data. Lacking it, I did my best to emulate it, so that porting it to your data would be relatively straightforward —
x = 9000:250:12500;
y = (rand(size(x))+0.25)*100;
err = rand(size(x))*25;
figure
errorbar(x+500, y, err, '-k')
xt = xticks; % Get Original 'xticks' Vector
xlim([min(xt)-1000 max(xt)+500]) % Set X-Limits
xticks([9000 xt]) % Re-Define 'xticks' Vector
xticklabels([{'No Stim'} compose('%d',xt(1:end)-500)]) % Set 'xticklabels'
hold on
errorbar(9000, rand*100, rand*25, '-g', 'LineWidth',1.5) % Plot Green Errorbar
hold off
You may still have to tweak this to get it the way you want. This should get you started.
.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Errorbars 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!