如何使图像足够大以避免刻度标签重叠?
假设数据X的大小为1000 * 1000。使用以下命令显示 X:
imagesc(X);
并且使用以下命令标记所有行:
set(gca, 'YTickLabel', somelabels);
虽然数据 X 已正确绘制并且还显示了 Ytick 标签,但由于行数较多,标签高度重叠。有什么办法可以解决这个问题吗?任何帮助将不胜感激。
编辑 1
我意识到我的问题没有很好地表达我的问题。我将根据答案总结我的理解并重新提出一个问题:
要在图形窗口中显示尽可能多的行/标签,以下内容会有所帮助:
set(gca,'FontSize',6), 或者,改变距离(yuk建议), 或者,设置(gca,'YTick',1:10:1000,'YTickLabel',somelabels(1:10:1000));
代码
set(gca,'单位','像素','位置',[20 20 10000 10000]);
默认显示放大的图像。但如果放大的图像太大而无法容纳图形窗口,则仅显示图像的一部分。但是,缩小和平移工具都无法到达该图像的其余部分。
代码的默认行为
imagesc(X); 设置(gca,'ytick',1:1000,'yticklabe',ylabel);
显示适合图形窗口的整个图像,并带有重叠标签。尽管如此,它确实允许用户放大图像的一部分并查看未重叠的标签。
如果我将图像保存为 pdf 文件:
imagesc(X); 设置(gca,'ytick',1:1000,'yticklabe',ylabel); saveas(gcf, '图.pdf');
然后保存的 pdf 只是适合图形窗口且标签重叠的图像。但是,与 Matlab 图形窗口中的放大不同,pdf 阅读器中的放大不会改变标签的相对位置/距离。结果,pdf中放大的图像仍然是标签重叠的。
所以我的问题是:
如何将图像保存为 pdf 文件或 png,使其在 Adobe reader 中打开时具有与上述第 3 点类似的行为,而不是与第 4 点类似的行为?
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:
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));
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.
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.
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您还可以使用轴标签字体以使其更小。
另请参阅其他坐标区属性来更改字体 - FontName、FontWidth、FontUnits等。
另一种解决方案:如果标签很短,您可以交替距轴的距离,这样标签就不会重叠。检查此示例:
结果图像的一部分:
更新
回答您更新的问题。
示例:
顺便说一句,您还可以使用 PRINT 功能。更灵活。 SAVEAS 只是它的包装。
You can also play with axes label font to make it smaller.
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:
Part of the resulted image:
UPDATE
To answer your updated question.
Example:
By the way, you can also save figure to file with PRINT function. More flexible. SAVEAS is just wrapper around it.
另一种选择是旋转刻度标签,这在 该技术方案。您可以在 MATLAB File Exchange 上找到许多易于使用的实现。
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.