필터 지우기
필터 지우기

HOW TO ADD XTICKLABLE IN BAR HISTOGRAM ?

조회 수: 1 (최근 30일)
Sanchit
Sanchit 2023년 7월 11일
편집: Mayur 2023년 7월 11일
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