views:

146

answers:

2

Assume that the data X has size 1000 *1000. X is displayed using the command:

imagesc(X);

and all the rows are labeld using:

set(gca, 'YTickLabel', somelabels);

Although the data X are properly polotted and the Ytick labels are also shown, the labels are highly overlapped because of the large number of rows. Is there any way to solve the problem? Any help will be highly appreciated.

Edit 1

I realize my question was not stated well to represent my problem. I am going to wrap up my understanding based on the answers and re-ask a question:

  1. To show as many rows/labels in a Figure Window, the following helps:

    set(gca,'FontSize',6), 
    or, alternate the distance (suggested by yuk),
    or, set(gca,'YTick',1:10:1000,'YTickLabel',somelabels(1:10:1000));
    
  2. The code

    set(gca,'Units','pixels','Position',[20 20 10000 10000]);
    

    will display a zoomed-in image by default. But if the zoomed-in image is too large to fit in the Figure Window, only part of the image will be displayed. However, neither zoom out nor the pan tool can reach to the rest part of that image.

  3. The default behavior of the code

    imagesc(X);
    set(gca, 'ytick', 1:1000, 'yticklabe', ylabel);
    

    displays the whole image fitting to the Figure Window with overlapping labels. Nevertheless, it does allow one to zoom into part of the image and to see the un-overlapped labels.

  4. If I save the image into a pdf file:

    imagesc(X);
    set(gca, 'ytick', 1:1000, 'yticklabe', ylabel);
    saveas(gcf, 'fig.pdf');
    

    Then the saved pdf is only the image fit to the Figure Window with overlapping labels. However, unlike zoom in within Matlab figure window, zoom in within a pdf reader won't change the relative position/distance of labels. As a result, the zoomed-in image in pdf is still label-overlaped.

So my question is:
How to save the image into a pdf file or png such that it has a similar behavior as of point 3 above when opened in Adobe reader, rather than that of point 4?

+4  A: 

You can also play with axes label font to make it smaller.

set(gca,'FontSize',6)

See also other axes properties to change font - FontName, FontWidth, FontUnits, etc.

Another solution: If your labels are short, you can alternate there distance from the axes, so the labels will not overlap. Check this example:

lbl = cellstr(reshape(sprintf('%3d',1:100),3,100)');
lbl(1:2:100) = strcat(lbl(1:2:100),{'     '});
imagesc(rand(100))
set(gca,'ytick',1:100)
set(gca,'yticklabel',lbl)

Part of the resulted image:

example image

UPDATE

To answer your updated question.

  1. PDF document can contain only static images. Once you saved the figure to PDF (or any other graphic file), you cannot zoom in/out as with MATLAB figure tools.
  2. You can zoom first on the MATLAB figure, then save PDF file. In this case the figure will be saved as is. But this way assumes user interactivity with the figure.
  3. If you know your region of interest in advance, you can set axes limits with XLim/YLim properties, then save the figure.

Example:

imagesc(X);
set(gca, 'ytick', 1:1000, 'yticklabe', ylabel);
set(gca, 'XLim',[1 20], 'YLim', [20 40])
saveas(gcf, 'fig.pdf');

By the way, you can also save figure to file with PRINT function. More flexible. SAVEAS is just wrapper around it.

print('-dpdf','fig.pdf')
yuk
+2  A: 

Another option is to rotate the tick labels which is discussed in this technical solution. You can find a number of easy-to-use implementations on the MATLAB File Exchange.

alt text

Amro
That won't really help him when dealing with the y axis.
gnovice

related questions