Why can't I use a 1x19 string to assign y-tick values on a barh plot?

1 次查看(过去 30 天)
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);

采纳的回答

chicken vector
chicken vector 2023-4-28
编辑:chicken vector 2023-4-28
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
tickText = 5×1 cell array
{'This is Tick 1'} {'This is Tick 2'} {'This is Tick 3'} {'This is Tick 4'} {'This is Tick 5'}
ticks
ticks = 1×5
0 0.2500 0.5000 0.7500 1.0000
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))

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Grid Lines, Tick Values, and Labels 的更多信息

产品


版本

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by