How to change the YTickLabel Position in barh graph

9 views (last 30 days)
Hello everybody,
I am trying to change the position of the y-tick labels in a horizontal bar graph. My values are names and percantage changes.
After running the code I want to change the y-tick label position that it is close to the horizontal axis at the value of zero.
% setting up the names
Names={'Person A' 'Person B' 'Person C' 'Person D' 'Person E'};
% setting up the Units
Units=1:5;
% setting up the values
values=[0.05 -0.02 0.03 -0.01 -0.04];
% initialazing figure
f = figure(1);
barplot=barh( Units,values);
% set x-limits
set(gca, 'XLim', [-0.06 0.06])
% change x values to percentage values
a=[cellstr(num2str(get(gca,'xtick')'*100))]; % Create a vector of '%' signs
pct = char(ones(size(a,1),1)*'%'); % Append the '%' signs after the percentage values
new_xticks = [char(a),pct];% 'Reflect the changes on the plot
set(gca,'xticklabel',new_xticks)
%set y-limits
set(gca, 'YLim', [0.5 5+0.5])
%set y-ticks and labels to names
set(gca, 'YTick', 1:1:6,'yTickLabel', Names)
Is there a possibility to do this?
Thank you very much.
  3 Comments
Michael
Michael on 25 Nov 2016
Thank you. I edited my original post. Should be running now.
dpb
dpb on 25 Nov 2016
"I want to change the y-tick label position that it is close to the horizontal axis at the value of zero."
I'm looking at the resulting figure and don't know what the above is referring to. What particular item is it you want moved and where to?

Sign in to comment.

Answers (0)

Categories

Find more on Line Plots in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!