I want to obtain a Matlab figure using the bar
function but when the actual figure is plotted instead of displaying the numbers underneath each bar I want to display which represents that actual value plotted.
For example I am having the vector x = [1 2 3]
and instead of showing 1, 2 and 3 beneath each plotted bar, I want to display a string corresponding to one of these values y = {'sam'; 'alan'; 'ellie'}
Could you please explain how could I obtain this?
To add text to one point, specify x and y as scalars. To add text to multiple points, specify x and y as vectors with equal length. text( x , y , z , txt ) positions the text in 3-D coordinates. text(___, Name,Value ) specifies Text object properties using one or more name-value pairs.
barh( y ) creates a horizontal bar graph with one bar for each element in y . If y is an m-by-n matrix, then barh creates m groups of n bars. barh( x , y ) draws the bars along the vertical axis at the locations specified by x .
The width of the bars can be controlled by width argument of the bar() function.
The bar function distributes bars along the x-axis. Elements in the same row of a matrix are grouped together. For example, if a matrix has five rows and three columns, then bar displays five groups of three bars along the x-axis. The first cluster of bars represents the elements in the first row of Y.
x = [1 2 3];
str = {'sam'; 'alan'; 'ellie'};
bar(x)
set(gca, 'XTickLabel',str, 'XTick',1:numel(str))
http://www.mathworks.com/matlabcentral/newsreader/view_thread/21178
Labels = {'a', 'b', 'c', 'd'};
set(gca, 'XTick', 1:4, 'XTickLabel', Labels);
if you need to change the Y-labels then substitute YTickLabel for XTickLabel
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With