Why can't I use a 1x19 string to assign y-tick values on a barh plot?
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Nicolaas Pickard
le 28 Avr 2023
Commenté : chicken vector
le 28 Avr 2023
The labels for my bar plot are assigned based on a previous for loop, which could vary in length depending on the data I am processing. This produces a 1xn string. I am trying to use that string to assign the y-tick labels for the chart, but only the first value is being plotted.
Any help with this?
%%Producing the bar labels
for i5=1:Doff
DoffValue(:,i5)=DoffOutput(:,3,i5);
DoffColour(:,i5)=DoffOutput(:,2,i5);
DoffTime(1,i5)=(DoffOutput(Time,1,i5)-(fix(c(1,1))));
Day(1,i5)=fix(DoffTime(1,i5));
Hour(1,i5)=fix((DoffTime(1,i5)-fix(DoffTime(1,i5)))*24);
MinuteCount(1,i5)=fix((((DoffTime(1,i5)-fix(DoffTime(1,i5)))*24)-Hour(1,i5))*60);
DoffTimeText(i5)=sprintf("Day %d %d:%d",Day(1,i5),Hour(1,i5),MinuteCount(1,i5));
end
%% Assigning y-tick labels
yticklabels(DoffTimeText);
0 commentaires
Réponse acceptée
chicken vector
le 28 Avr 2023
Modifié(e) : chicken vector
le 28 Avr 2023
You also have to setup the location of the ticks accordingly.
In the following example I set the range of y axis between 0 and 1 and if I want to display 5 ticks labels I have to specify their location using 'YTick'.
Is similar to use Coordinate-Value pairs.
data = rand(50,2);
tickText = cell(5,1);
for j = 1 : length(tickText)
tickText{j} = ['This is Tick ' num2str(j)];
end
yRange = [0,1];
ticks = yRange(1):diff(yRange)/(length(tickText)-1):yRange(2);
figure;
grid on;
scatter(data(:,1),data(:,2),50,'d','filled')
set(gca,'YTick',ticks,'YTickLabel',tickText)
tickText
ticks
You can invert the order with flip.
figure;
grid on;
scatter(data(:,1),data(:,2),50,'d','filled')
set(gca,'YTick',ticks,'YTickLabel',flip(tickText))
2 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Annotations 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!