HOW TO ADD XTICKLABLE IN BAR HISTOGRAM ?

3 Ansichten (letzte 30 Tage)
Sanchit
Sanchit am 11 Jul. 2023
Bearbeitet: Mayur am 11 Jul. 2023
I am using following lines of matlab to generate bar histogram
bar(rf_classifier.OOBPermutedVarDeltaError)
ax = gca;
xlabel('Feature Number','FontSize', 16)
ylabel('Out-of-Bag Feature Importance','FontSize', 16)
ax.XTickLabel = [Td,T,EV,PEV,SSR,SSRD,TP,VPD,RH];
ax.XTickLabelRotation = 45;
However, this code is not putting the variable names on x-axix of bar diagram. I request you to kindly fix it in order to put the variable names on x-axis. I am attaching the bar figure also.
Thanks.
Sanchit
  1 Kommentar
Sanchit
Sanchit am 11 Jul. 2023
It is putting all the variables nine times. I have attached the output png file. You may please have a look ot it. Thank you very much.
Sanchit

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Mayur
Mayur am 11 Jul. 2023
Bearbeitet: Mayur am 11 Jul. 2023
Hi Sanchit!
I understand that you're not able to get the labels in x-axis. Assuming Td, T, EV, etc as variables and not actual values, you will need to use curly braces instead of square brackets. Here's the updated code:
bar(rf_classifier.OOBPermutedVarDeltaError)
ax = gca;
xlabel('Feature Number','FontSize', 16)
ylabel('Out-of-Bag Feature Importance','FontSize', 16)
ax.XTickLabel = {Td,T,EV,PEV,SSR,SSRD,TP,VPD,RH};
ax.XTickLabelRotation = 45;
Otherwise, if they are actual values (strings), you need to use a string array or cell array.
bar(rf_classifier.OOBPermutedVarDeltaError)
ax = gca;
xlabel('Feature Number','FontSize', 16)
ylabel('Out-of-Bag Feature Importance','FontSize', 16)
ax.XTickLabel = {'Td','T','EV','PEV','SSR','SSRD','TP','VPD','RH'};
ax.XTickLabelRotation = 45;
  2 Kommentare
Steven Lord
Steven Lord am 11 Jul. 2023
This likely doesn't do what the user wants. Let's look at what you're using to set the XTickLabel property:
['Td','T','EV','PEV','SSR','SSRD','TP','VPD','RH']
ans = 'TdTEVPEVSSRSSRDTPVPDRH'
Either use a string array (preferred) or a cell array containing char arrays.
s = ["Td","T","EV","PEV","SSR","SSRD","TP","VPD","RH"]
s = 1×9 string array
"Td" "T" "EV" "PEV" "SSR" "SSRD" "TP" "VPD" "RH"
c = {'Td','T','EV','PEV','SSR','SSRD','TP','VPD','RH'}
c = 1×9 cell array
{'Td'} {'T'} {'EV'} {'PEV'} {'SSR'} {'SSRD'} {'TP'} {'VPD'} {'RH'}
Sanchit
Sanchit am 11 Jul. 2023
Thank you very much. It worked very well.
Sanchit

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Produkte


Version

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by