How to change the YTickLabel Position in barh graph
9 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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
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?
Antworten (0)
Siehe auch
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!