Effacer les filtres
Effacer les filtres

HOW TO ADD XTICKLABLE IN BAR HISTOGRAM ?

1 vue (au cours des 30 derniers jours)
Sanchit
Sanchit le 11 Juil 2023
Modifié(e) : Mayur le 11 Juil 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 commentaire
Sanchit
Sanchit le 11 Juil 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

Connectez-vous pour commenter.

Réponse acceptée

Mayur
Mayur le 11 Juil 2023
Modifié(e) : Mayur le 11 Juil 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 commentaires
Steven Lord
Steven Lord le 11 Juil 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 le 11 Juil 2023
Thank you very much. It worked very well.
Sanchit

Connectez-vous pour commenter.

Plus de réponses (0)

Produits


Version

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by