Categorical bar plot in AppDesigner (change colors and add refline)

65 次查看(过去 30 天)
Hello everybody,
I'm currently facing some issues with my categorical bar plot in Appdesigner. In the following a short example of what I'd like to achieve:
categorie=categorical({'Asia','USA','Europe'});
categorie = reordercats(categorie,{'Europe' 'Asia' 'USA'});
Data=[Population_Europe Population_Aisa Population_USA];
bar(app.UIAxes,categorie,Data)
I'm able to plot this, but I want to add two things, which I'm currently not able to:
1) Change the colours of the bars -> e.g. Europe = blue, Asia = green and USA =red
2) Add a horizontal line at a certain value across the whole bar plot. Here's a quick example, which does not work in appdesigner:
hold(app.UIAxes,'on')
bar(app.UIAxes,xlim,[100 100], 'r','LineWidth',2)
Thank you in advance for your help and have a great day!
Cheers, Christian

采纳的回答

Kojiro Saito
Kojiro Saito 2019-5-21
编辑:Kojiro Saito 2019-5-21
1) You can set colors on each bar by CData property.
b = bar(app.UIAxes, categorie, Data, 'FaceColor', 'flat');
b.CData = [0 0 1; 0 1 0; 1 0 0];
UPDATED
2) In order to add red horizontal line, yline is the easiest way.
yline(app.UIAxes, 150, 'r', 'LineWidth', 2)
yline(app.UIAxes, 200, 'b', 'LineWidth', 2)
untitled2.png
Or alternatively, you can utilize grid, but line color and width is only one for this approach.
% Add holizontal red line using grid
grid(app.UIAxes)
app.UIAxes.XGrid = 'off';
app.UIAxes.Layer = 'top';
app.UIAxes.YTick = 100;
app.UIAxes.GridAlpha = 1;
app.UIAxes.GridColor = 'red';
This will work as the following.
  7 个评论

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Labels and Annotations 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by