How can I change the color and border of my bars on a hbar graph?

5 ビュー (過去 30 日間)
Brady Wayne Robinson
Brady Wayne Robinson 2018 年 10 月 17 日
編集済み: Luna 2018 年 10 月 17 日
I have a bar simple bar graph made with the following code. I want to have the three bars be different colors. Thank You!
yearsforcoal=fossilfulesyearsleft(1,4);
yearsforoil=fossilfulesyearsleft(3,4);
yearsforng=fossilfulesyearsleft(2,4);
c=categorical({'Coal','Natural Gas','Oil'})
Yearsl=[yearsforcoal yearsforng yearsforoil]
barh(c,Yearsl)
title('Projected Fossil Fuel Reserves','FontSize',18)
xlabel('Years Left','FontSize',15)
ylabel('Fossil Fuel Type','FontSize',15)

回答 (2 件)

Matt J
Matt J 2018 年 10 月 17 日
編集済み: Matt J 2018 年 10 月 17 日
If Years1 is an Mx3 matrix, then you should automatically be getting 3 different colors already. Regardless, you can take control of the bar color by returning a handle from barh like in this example.

Luna
Luna 2018 年 10 月 17 日
編集済み: Luna 2018 年 10 月 17 日
Hi Brady,
if you create your data like below then plot the barh, you will get 3 different colors. (3x3 unit Matrix with your data)
Yearsl=[yearsforcoal 0 0; 0 yearsforng 0; 0 0 yearsforoil]

カテゴリ

Help Center および File ExchangeDirected Graphs についてさらに検索

製品


リリース

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by