Hi everybody,
So ... somehow my plot won't show me all of my xticklabels ...
What I did: I plotted 18 bins, and wanted to give each of those a specific name, which I realized with the help of defining my individual xticklabel. But when I've run my code, only the first half of them them will appear ... Even if I increase the size of my figure ... After all the bins show up in the correct amount.
x %vector with my xticklabels
set(gca,'xticklabel',x);
What could be the reason for this? And how can I change it? Might be a reason that the length of one xticklabel is too long? I am so confused ...
Best regards!

댓글 수: 1

Jan
Jan 2018년 7월 26일
Please post a running code, which reproduces the problem. Which "bins" show up a wanted? How did you "plot 18 bins". Which "first half"? A screenshot might help.

댓글을 달려면 로그인하십시오.

 채택된 답변

Adam Danz
Adam Danz 2018년 7월 26일
편집: Adam Danz 2018년 8월 1일

1 개 추천

You're probably not setting the 'XTick' property.
Here's an example that replicates the problem you're describing.
figure
plot(rand(1,20), rand(1,20))
xlab = {'a' 'b' 'c' 'd' 'e' 'f' 'g' 'h' 'i' 'j' 'k' 'l' 'm' 'n' 'o' 'p' 'q' 'r' 's' 't' 'u' 'v' 'w' 'x' 'y' 'z'};
set(gca, 'XTickLabels', xlab)
In that figure (left) you'll only see letters a:k because the original ticks were 0 : 0.1 : 1.
Now set the ticks correctly by using 'XTick'. Here I use space them equally along the x axis but you'll use the x values where your labels should go.
set(gca, 'XTick', linspace(0,1,length(xlab)), 'XTickLabels', xlab)
Now you see all of the labels (right).

추가 답변 (1개)

Jan
Jan 2018년 7월 26일

2 개 추천

Maybe the number of 'XTick' does not equal the number of 'XTickLabel'? This would be clear, if you post the code.
Label = {'1', '2', '3', '4', '5', '6', '7', '8', '9', '10'};
Axes1H = subplot(1,2,1);
plot(1:10);
set(Axes1H, 'XTick', 1:5, 'XTickLabel', Label);
Axes2H = subplot(1,2,2);
plot(1:10);
set(AxesH, 'XTick', 1:10, 'XTickLabel', Label);

댓글 수: 8

Hi! Sorry I am just answering now ... the problem I had in the first place I was able to solve. (it was really just about the xtick property I forgot to set) But by now I am having another though very similar issue ...
I'd like to: show up all of my xticklabels again, but they just won't ...
My code is the following:
subplot(2,1,2);
scatter(t1.s(:,1), t1.diff(:,1),'.');
new_xtick=[t_b.s(:,1)];
set(gca,'xtick',new_xtick);
set(gca,'xticklabel',num2str(new_xtick));
grid on;
num2str() creates 1 string of all your numbers (eg: '2 4 6 8 10'). You need to split them using
strsplit(num2str());
So your code will be
set(gca, 'XTick', new_xtick, 'XTickLabel', strsplit(num2str(new_xtick)))
jrbbrt
jrbbrt 2018년 8월 1일
편집: jrbbrt 2018년 8월 1일
Thank you for your answer Adam! When I try so, I am getting an Error message:
"Error using regexp The 'STRING' input must be either a char row vector, a cell array of char row vectors, or a string array.
Error in strsplit (line 125) [c, matches] = regexp(str, aDelim, 'split', 'match');"
Do you have an Idea why?
Adam Danz
Adam Danz 2018년 8월 1일
What are the values of new_xtick?
jrbbrt
jrbbrt 2018년 8월 1일
The values of new_xtick are numbers (mostly/maximum 8 digits) which I am getting out of a table. And when I convert them with the help of num2str I get a 80x8 char array.
jrbbrt
jrbbrt 2018년 8월 1일
편집: jrbbrt 2018년 8월 1일
The values of the char array look like this:
val= '10004000' '20004000' '30004000' etc.
I see.
new_xtick must be a row vector. If it's a column vector, transpose it.
strsplit(num2str(new_xtick'))
jrbbrt
jrbbrt 2018년 8월 2일
Adam, my hero! Thank you, that actually worked for me :)

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Data Distribution Plots에 대해 자세히 알아보기

질문:

2018년 7월 26일

댓글:

2018년 8월 2일

Community Treasure Hunt

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

Start Hunting!

Translated by