HOW TO ADD XTICKLABLE IN BAR HISTOGRAM ?

3 visualizzazioni (ultimi 30 giorni)
Sanchit
Sanchit il 11 Lug 2023
Modificato: Mayur il 11 Lug 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 Commento
Sanchit
Sanchit il 11 Lug 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

Accedi per commentare.

Risposta accettata

Mayur
Mayur il 11 Lug 2023
Modificato: Mayur il 11 Lug 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 Commenti
Steven Lord
Steven Lord il 11 Lug 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 il 11 Lug 2023
Thank you very much. It worked very well.
Sanchit

Accedi per commentare.

Più risposte (0)

Prodotti


Release

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by