How to change the YTickLabel Position in barh graph

9 Ansichten (letzte 30 Tage)
Michael
Michael am 24 Nov. 2016
Kommentiert: dpb am 25 Nov. 2016
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 Kommentare
Michael
Michael am 25 Nov. 2016
Thank you. I edited my original post. Should be running now.
dpb
dpb am 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?

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu Line Plots finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by