XTicklabels don‘t match

8 次查看(过去 30 天)
Florian
Florian 2018-10-18
I am plotting a matrix using below code.
The XTicklabels are supposed to be labeled per tick, but they only label every second tick.
Does anybody have a solution?
a = [12 16 5 5 5 11 4 4 3 3]; % rock data
b = [1 1 1 1 2 2 2 2 2 4]; % image data
u = union(a,b);
[~,ia] = ismember(a(:),u);
[bb,ib] = ismember(b(:),u);
n = length(u);
c = accumarray([ia(bb),ib(bb)],1,[n n]);
csum=sum(c,2);
d=c./csum;
% plot the results
figure, clf
x=u';
ytmp=flipud(u); % flip y-direction
y=cellfun(@(x) num2str(x),num2cell(ytmp),'UniformOutput',0);
pcolor(d)
colormap jet
colorbar
set(gca,'XTickLabel',num2str(x))
set(gca,'YTickLabel',y)
xlabel('Image code')
ylabel('Facies code')
  8 个评论
Bruno Luong
Bruno Luong 2018-10-22
Login then go to Bug report page
But attention: this is not bug see Rik's answer about set Xtick
Rik
Rik 2018-10-23
Did my suggestion solve your problem? If so, please consider marking it as accepted answer. It will make it easier for other people with the same question to find an answer. If this didn't solve your question, please comment with what problems you are still having.

请先登录,再进行评论。

采纳的回答

Rik
Rik 2018-10-21
If you want full control over the ticks, you must set both the ticks and their labels explicitly. If you don't, it may depend on your resolution if you get your desired result. You can easily check this by resizing your figure window. This has been the case since before HG2 as far as I know.
set(gca,'XTickLabel',num2str(x)),set(gca,'XTick',1:numel(x))
set(gca,'YTickLabel',y),set(gca,'YTick',1:numel(y))
  3 个评论
Rik
Rik 2018-10-21
The trickiest bugs to find are those where you write something on autopilot yourself and don't realize someone else didn't.
Sumiran Lohani
Sumiran Lohani 2021-9-1
This is a great answer. It has saved me hours of debugging thanks to your solution Rik. Thank you!

请先登录,再进行评论。

更多回答(0 个)

类别

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

产品

Community Treasure Hunt

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

Start Hunting!

Translated by