Dear Community
I would like to create a plot for my bachelor thesis that looks like the one in the picture.
However, I haven't seen anything similar and would like some advice on how to do it. Of course it would be better to just get a solution.
Thanks a lot if you take care of the question.

 采纳的回答

One approach —
barvals = sort(rand(2,5),'descend') % Matrix Defining Limits Of Bars
barvals = 2×5
0.5639 0.6979 0.6853 0.4293 0.6496 0.1724 0.3140 0.0080 0.1476 0.4906
figure
plot([1;1]*(1:size(barvals,2)), barvals, 'LineWidth',25, 'Color',[1 1 1]*0.8)
hold on
plot([1;1]*(1:size(barvals,2)), [-0.01;0.01]*(ones(size(barvals(1,:))))+barvals(1,:), 'r', 'LineWidth',25)
plot([1;1]*(1:size(barvals,2)), [-0.01;0.01]*(ones(size(barvals(2,:))))+barvals(2,:), 'b', 'LineWidth',25)
hold off
xlim([0 size(barvals,2)+1])
text(1:size(barvals,2), mean(barvals), compose('$%d$',randi(200,1,size(barvals,2))), 'Horiz','center', 'Vert','middle', 'Rotation',90, 'Interpreter','latex', 'FontSize',14)
Adding the tick labels is straightforward. I can help with that if you like.
.

2 个评论

Hello Star Rider
Thanks for your help, it is exactly what I was looking for.
I have uploaded the final result as an image and will add my code below in case anyone has the same question.
Data = readmatrix('Data.xlsx');
barvals = sort(Data(1:2,:),'descend'); % Matrix Defining Limits Of Bars
%figure
plot([1;1]*(1:size(barvals,2)), barvals, 'LineWidth',25, 'Color',[1 1 1]*0.8)
hold on
plot([1;1]*(1:size(barvals,2)), [-0.01;1]*(ones(size(barvals(1,:))))+barvals(1,:), 'r', 'LineWidth',25)
plot([1;1]*(1:size(barvals,2)), [-0.01;1]*(ones(size(barvals(2,:))))+barvals(2,:), 'b', 'LineWidth',25)
hold off
xlim([0 size(barvals,2)+1])
text(1:size(barvals,2), mean(barvals), compose('$%d$',Data(3,:)), 'Horiz','center', 'Vert','middle', 'Rotation',90, 'Interpreter','latex', 'FontSize',14)
xt = get(gca, 'XTick');
%Name of the x-axis
set(gca, 'XTick', xt, 'XTickLabel', {'','Toluen' 'Lit Toluen' 'Ethanol' 'Lit Ethanol',...
'Acetonitril','Lit Acetonitril','DMSO','Lit DMSO'})
%define y-label
ylabel('$\lambda$ / nm','interpreter','latex');
set(gcf,'color','w');
As always, my pleasure!
It would be straightforward to add the legend as well. It would likely be necessary to use ylim to increase the upper limit of the axes in order to accommodate it.

请先登录,再进行评论。

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Annotations 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by