How to change a single xtick (x label)?
12 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Paul Hinze
le 30 Jan 2023
Commenté : Star Strider
le 1 Fév 2023
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 commentaires
Réponse acceptée
Star Strider
le 30 Jan 2023
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 commentaires
Star Strider
le 1 Fév 2023
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.
.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Errorbars dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!