variable Xtick on bar graph
1 回表示 (過去 30 日間)
古いコメントを表示
hello everyone,
i have this problem: i want to plot on bar figure infomation and wirth below this data the date of any column on the bar. the problem is that the user can choose differnt length of time to see one the graph and its causing to problam (many dates on the Xtick wirte one on the other and think like that). i tried to set that if the user choose more than 8 days so the Xtick will write only 8 days but with proportion between them (for exemple if he choose 16 day so it shoe the dates with jump of 2 days between a couple) but i having trouble to get the right string fo the Xtick. anyone can help? you can see what i done so far to maybe understand better my problem. thanks!
Labels = cellstr(Dates);
NumOfDates = length(Labels);
if NumOfDates < 7
set(gca,'XTick', 1 : NumOfDates, 'XTickLabel', Labels);
else
Labels(1) = Dates(1);
Labels(8) = Dates(end);
j = 2;
for i = 1 + round(NumOfDates/8) : round(NumOfDates/8) : NumOfDates
Labels(j) = Dates(i);
j = j + 1;
end
if strcmp(Labels(end), Labels(end - 1))
Labels(end - 1) = Dates(round(length(Dates) - (NumOfDates/8)));
end
set(gca,'XTick', 1 : (NumOfDates/8): NumOfDates, 'XTickLabel', Labels);
end
labels is the dates string to Xtick. * "Dates" its all the dates of the dtat and from this variable i need to peek max 8 dates.
0 件のコメント
回答 (1 件)
Walter Roberson
2016 年 4 月 10 日
I suggest you use linspace(1, NumOfDates, 8), possibly rounding the results.
3 件のコメント
Walter Roberson
2016 年 4 月 10 日
Index the Dates at the rounded index.
Or, if the dates are equally spaced and there are no holes, then you can linspace() the numeric equivalents of the dates.
参考
カテゴリ
Help Center および File Exchange で Time Series Objects についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!