【问题标题】:How to make the bar have the same color in the same group when plot in Matlab在Matlab中绘图时如何使同一组中的条具有相同的颜色
【发布时间】:2020-03-03 13:54:24
【问题描述】:

在这个图中,我们有两组条,A 和 B。如何使 A 组中的条具有相同的颜色 a,而 B 组中的条具有相同的颜色 b。以及如何为这两组产生图例。

谢谢。

代码:

latency = [62.36 80 793.17 215.15 199.39 ; 
           43.21 50 221 206.90 10 ]; 
h = bar(latency, 1);
set(h, 'FaceColor',[64 224 208]./255,'LineWidth', 0.7)
set(gca,'linewidth',0.8,'Fontname', 'Arial', 'FontWeight', 'bold');
set(gca,'XLim',[0.5, size(latency,1)+0.5], ...
   'XTick',[0.69:0.155:1.4 1.70:0.155:2.3], ...
   'XTickLabel',{'A', 'B', 'C', 'D', 'E', 'A', 'B', 'C', 'D', 'E'});
box on;

【问题讨论】:

  • 从阅读How to Ask开始。您将在那里学习展示您的努力。向我们展示如何制作条形图是一个开始,但是您是否例如?阅读the documentation on bar()?这很清楚地告诉你该怎么做。

标签: matlab matlab-figure figure


【解决方案1】:

您可以在一个轴上使用两个条形图:

figure;
h1 = bar(1:5, latency(1,:));
hold on;
h2 = bar(7:11, latency(2,:));
ax = gca;
ax.XTick = [1:5, 7:11]
ax.XTickLabel={'A','B','C','D','E','A','B','C','D','E'}

您可以使用h1h2 访问和修改Bar 对象。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-03-14
    • 2018-06-07
    • 1970-01-01
    • 2019-05-31
    • 1970-01-01
    • 2021-09-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多