HOW TO ADD XTICKLABLE IN BAR HISTOGRAM ?

3 次查看(过去 30 天)
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 个评论
Sanchit
Sanchit 2023-7-11
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

请先登录,再进行评论。

采纳的回答

Mayur
Mayur 2023-7-11
编辑:Mayur 2023-7-11
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 个评论
Steven Lord
Steven Lord 2023-7-11
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 2023-7-11
Thank you very much. It worked very well.
Sanchit

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Histograms 的更多信息

产品


版本

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by