variable Xtick on bar graph

2 次查看(过去 30 天)
nadav potasman
nadav potasman 2016-4-10
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.

回答(1 个)

Walter Roberson
Walter Roberson 2016-4-10
I suggest you use linspace(1, NumOfDates, 8), possibly rounding the results.
  3 个评论
Walter Roberson
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.
nadav potasman
nadav potasman 2016-4-15
Thank you again Walter. Im not sure that i understood your idea but meanwhile i succssed to solve my problem Thanks anyway

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 2-D and 3-D Plots 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by