我想在Matlab 2015b中的数字间距上有垂直/水平网格线。
我知道你可以通过background
获得一个可以成为网格线网络的背景图片,How do I add a background image to my GUI or figure window?部分关于它的部分内容
但是,我认为没有图片的网格线将是更好的选择
示例代码
data=randi(513,513);
D=mat2gray(pdist(data, 'correlation'));
ax2 = axes('OuterPosition', [0.51 0.5 0.5 0.5]);
plot(D, 'Parent', ax2);
set(ax2, 'XLim', [0, size(D,1)])
axis(ax2, 'square');
title('Corr pdist');
cbar2 = colorbar();
set(ax2, 'XLim', [0 size(D,2)]);
set(cbar2, 'Visible', 'off')
grid minor;
% Force a draw event to have the axes determine where the
labelconverter = @(x)sprintf('%.2g', x); % https://stackoverflow.com/a/35780915/54964
callback = @(varargin)set(ax2, 'xticklabels', arrayfun(labelconverter, get(ax2, 'xtick'), 'uniform', 0));
set(hFig, 'SizeChangedFcn', callback);
callback(); % necessary for the original small window and its scientific numbering
D_square=squareform(D, 'tomatrix');
ax4 = axes('OuterPosition', [0.51 0 0.5 0.5]);
imshow( D_square );
colormap('parula'); colorbar;
axis(ax4, 'square');
title('Square Corr pdist');
系统基于相对位置,而不是here中所描述的关于在Matlab中带有颜色条和子图第3个参数的紧密子图的<{1}}
假设方法
subplot
background
如何在背景中有网格线,即数字之间的间距?
答案 0 :(得分:2)
我可能只是设置一个横跨整个图形的轴,然后打开网格线,然后将轴的颜色设置为“没有”#。完整示例如下所示。
fig = figure();
backax = axes('Parent', fig);
% Ensure that this is below other objects
uistack(backax, 'bottom');
% Span the whole figure
set(backax, 'Position', [0 0 1 1]);
grid(backax, 'on')
% Make it invisible except for the grid and
% ensure it isn't able to be interacted with
set(backax, 'HitTest', 'off', ...
'HandleVisibility', 'off', ...
'GridLineStyle', '-', ...
'Color', 'none', ...
'XColor', 'none', ...
'YColor', 'none')
% Determine grid spacing with x/y ticks
% Increase nLines for a finer grid
nLines = 20;
set(backax, 'XTick', linspace(0, 1, nLines), ...
'YTick', linspace(0, 1, nLines));
然后你可以添加任何图表,uicontrols等等,它应该工作得很好。它还将处理您决定需要不同图形颜色的情况。