# Floating bar graphs with characters and numerical data

4 views (last 30 days)
Onkar Khadke on 5 Sep 2021
Commented: Onkar Khadke on 6 Sep 2021
Hello experts,
I am looking to get a plot of floating bar graphs in horizontal orientation. The Y-axis has got different chemicall elements and the X-axis has got the range of these chemical elements. I am attaching a sample figure, I am looking for. Kindly someone help me in how can I plot such a figure with one axis (Y-axis) being character names of the chemical elements and on X-axis their range with the horizontally oriented bars showing their range.
I had also written the ranges of all the chemical elements for which I need the plot.
Thank you
Data:
Al: min = 0.01, max = 0.58
Ti: min = 0.76, max = 1.95
Nb: min = 5.0, max = 5.61
Co: min = 0, max = 1.0
Mo: min = 2.63, max = 3.11
Rik on 5 Sep 2021
This should be relatively easy to achieve with calls to patch. I don't think there is a native function to do exactly this. What have you tried? Have you searched the file exchange?

Ive J on 5 Sep 2021
Edited: Ive J on 5 Sep 2021
tags = ["Al", "Ti", "Nb", "Co", "Mo"];
ranges = [0.01 0.58; 0.76 1.95; 5 5.61; 0 1; 2.63 3.11];
h = gca;
h.YLim = [0, numel(tags) + 1];
ranges(:, 3) = ranges(:, 2) - ranges(:, 1); % width of bars
hght = ones(size(ranges, 1), 1).*0.5; % height of each bar: 0.5
y = (1:size(ranges, 1)).' - 0.25; % Y position of each bar
for i = 1:numel(y) % loop over each element and plot
rectangle(h, 'Position', [ranges(i, 1), y(i), ranges(i, 3), hght(i)], 'FaceColor', '#153944');
end
h.YTick = 1:numel(tags);
h.YTickLabel = tags;
h.Box = 'on';
h.LineWidth = 1.2;
h.FontSize = 12;
h.XLabel.String = "Range";
axis square Onkar Khadke on 6 Sep 2021
Dear Ive J sir,
Your code works perfectly and has helped me, exactly for what I was looking for.
A big big Thank you to you sir.
Your help is highly appreciated sir
Thank you once again
Regards