-1

ズームインまたはズームアウトするときにこの自動スケーリングを行うには、プロットにテキストを追加する方法を教えてください。

と の両方FontUnitsのオプションは、ズームインまたはズームアウト時に再スケーリングnormalizedpixelsません。

figure(1);
text(0.5,0.5,'test',...
    'FontUnits','Normalized',...
    'FontSize',0.25,...
    'HorizontalAlignment','center',...
    'Color',color...
    );
figure(2);
set(gcf,'Position',[935   428   672   504])
text(50,50,'test',...
    'FontUnits','pixels',...
    'FontSize',100,...
    'HorizontalAlignment','center',...
    'Color',color...
    );
axis([0 100 0 100])

この関数には、zoomCallBack 関数のさらなる変更が含まれます。

function drawtext(p,s,f,color)
    % get axes size
    ax = axis;
    % add some text
    ax0=ax(4)-ax(3);
    txt = text(p(1),p(2),s,...
        'FontSize',f,...
        'HorizontalAlignment','center',...
        'Color',color);
    h = zoom; % get handle to zoom utility
    set(h,'ActionPostCallback',@zoomCallBack);
    set(h,'Enable','on');
    % everytime you zoom in, this function is executed
    function zoomCallBack(obj, evd)      
        % Since i expect to zoom in ax(4)-ax(3) gets smaller, so fontsize
        % gets bigger.
        ax = axis(evd.Axes); % get axis size
        % get all texts in figure
        htxt = findobj(gcf,'Type','text');
        axi=ax(4)-ax(3);
        for i=1:length(htxt)
            % change font size accordingly
            set(htxt(i),'FontSize',str2num(get(htxt(i),'Tag'))*ax0/axi);
        end
    end
end

これは有効な解決策ですが、非常に扱いにくく、失敗することもあります。より良い解決策は大歓迎です。

4

1 に答える 1