如何使图像足够大以避免刻度标签重叠?

5
假设数据X的大小为1000*1000。可以使用以下命令显示X:
imagesc(X);

所有行都使用标签进行标注:

set(gca, 'YTickLabel', somelabels);

尽管数据X已经被正确地绘制出来,并且Y轴刻度标签也被显示出来了,但由于行数过多,标签高度重叠。有没有什么方法可以解决这个问题?非常感谢您的帮助。
编辑1:
我意识到我的问题表述不太清楚,无法准确反映我的问题。根据答案,我将总结自己的理解并重新提问:
  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.

我的问题是:
如何将图像保存为PDF文件或PNG文件,使其在Adobe Reader中打开时具有与上面第3点类似的行为,而不是第4点的行为?

2个回答

4
另一种选择是旋转刻度标签,该方法在这个技术解决方案中有讨论。您可以在MATLAB文件交换中找到许多易于使用的实现。

alt text


这并不能真正帮助他处理y轴的问题。 - gnovice
它不会产生影响,但我在寻找实现X的方法时,最终来到了这个页面。 - Superbest

4

您还可以通过调整轴标签字体来使其更小。

set(gca,'FontSize',6)

请参见其他坐标轴属性,例如FontName、FontWidth、FontUnits等,以更改字体。

另一种解决方案:如果您的标签很短,您可以轮流调整它们与坐标轴的距离,这样标签就不会重叠。请查看此示例:

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)

生成的图片的一部分:

示例图片

更新

回答您的更新问题。

  1. PDF文档只能包含静态图像。一旦您将图形保存为PDF(或任何其他图形文件),您就无法像MATLAB图形工具一样进行缩放。
  2. 您可以先在MATLAB图形上进行缩放,然后保存PDF文件。在这种情况下,该图形将按原样保存。但是,这种方法假定用户与该图形进行交互。
  3. 如果您事先了解您感兴趣的区域,可以使用XLim / YLim属性设置轴限制,然后保存该图形。

例如:

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

顺便提一下,你还可以使用PRINT函数将图形保存到文件中。更加灵活。SAVEAS只是对其进行了包装。

print('-dpdf','fig.pdf')

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接