0

Suppose that we have this array and pcolor function in MATLAB:

jj = [0,1,0;1,0,1;1,1,0];
pcolor(jj);

Plot:

Enter image description here

I want show all elements of jj matrix in this pcolor plot so we should have a 3*3 plot. How can I do this in MATLAB?

Anyway, to show only row and column numbers in a plot not above vertical and horizontal scaling? Is there any other recommended suitable type of plots to show this type of data (2D binary data)?

6
  • 3
    Why not use imshow or imagesc? Commented Sep 18, 2016 at 17:17
  • Thank you for comment. Please add your answer for questions. I checked imagesc. It worked. What's your idea about two other questions? Commented Sep 18, 2016 at 17:20
  • 1
    I don't understand the question about row/column numbers. Can you show a diagram of what you mean? Commented Sep 18, 2016 at 17:21
  • I don't want this scaling in horizontal and vertical axes. I only want number of rows and columns. for instance I want only number 1 instead of 1 to 2 scaling (in middle). Commented Sep 18, 2016 at 17:23
  • 1
    Have a look here for another option to use imagesc to visualize your data. Commented Sep 18, 2016 at 21:02

1 Answer 1

3

If you want all of the image data to be displayed with pcolor, you need to pad the input with an extra row and column prior to printing since underneath, pcolor is a surf object and the colors are assigned to the vertices not the faces.

jj = [0,1,0;1,0,1;1,1,0];

% Add an extra column
jj(:,end+1) = 0;

% Add an extra row
jj(end+1,:) = 0;

p = pcolor(jj);

Now if you want only the integer labels on the axes, you can tweak them using the XTick/Ytick and XTickLabel/YTickLabel properties of the axes to draw the proper values for each element

xlims = get(gca, 'XLim');
ylims = get(gca, 'YLim');

% Must offset ticks by 0.5 to center them
xticks = (xlims(1) + 0.5):(xlims(2) - 0.5);
yticks = (ylims(1) + 0.5):(ylims(2) - 0.5);

xticklabels = arrayfun(@num2str, 1:numel(xticks), 'UniformOutput', 0);
yticklabels = arrayfun(@num2str, 1:numel(yticks), 'UniformOutput', 0);

set(gca, 'xtick', xticks, 'ytick', yticks, ...
         'xticklabel', xticklabels, 'yticklabel', yticklabels)

If you don't need the black edges, you can accomplish the same 2D plot by just using imagesc

imagesc(jj);

xlims = get(gca, 'xlim');
ylims = get(gca, 'ylim');

set(gca, 'xtick', xlims(1):xlims(2), 'ytick', ylims(1):ylims(2))
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.