【问题标题】:Zoom region within a plot in MatlabMatlab中绘图内的缩放区域
【发布时间】:2014-04-26 12:39:30
【问题描述】:

我正在使用 Matlab 生成图形,我想知道是否有办法在整体数据的图形中绘制一个缩放区域?

我在一周内绘制了散点数据,x 轴以小时为单位,我想放大前 3 小时,并将它们显示在主图中,x 轴标签为分钟。

我目前的绘图代码如下:

allvalsx = marabint(:,2)
allvalsy = marabint(:,5)
subvalsx = marabint(1:7,2);
subvalsy = marabint(1:7,2);
%% Plots the scatter chart.
sizemarker = 135
handle = scatter(allvalsx, allvalsy, sizemarker, '.')
figure(1)
axes('Position',[.2 .2 .2 .2])
handle2 = scatter(subvalsx, subvalsy, '.r')
title(plotTitle)
xlabel('Time since treatment (hours)')
ylabel('Contact angle (deg)')

% Axis scales x1, x2, y1, y2
axis([0, marabint(length(marabint),2) + 10, 0, 120]);

% This adds a red horizontal line indicating the untreated angle of the
% sample.
untreatedLine = line('XData', [0 marabint(length(marabint),2) + 10], 'YData', [untreatedAngle untreatedAngle], 'LineStyle', '-', ...
    'LineWidth', 1, 'Color','r');

% Adding a legend to the graph
legendInfo = horzcat('Untreated angle of ', untreatedString)
hleg1 = legend(untreatedLine, legendInfo);

% This encases the plot in a box
    a = gca;
    % set box property to off and remove background color
    set(a,'box','off','color','none')
    % create new, empty axes with box but without ticks
    b = axes('Position',get(a,'Position'),'box','on','xtick',[],'ytick',[]);
    % set original axes as active
    axes(a)
    % link axes in case of zooming
    linkaxes([a b])

set(gcf,'PaperUnits','inches');
set(gcf,'PaperSize', [8.267 5.25]);
set(gcf,'PaperPosition',[0 0.2625 8.267 4.75]);
set(gcf,'PaperPositionMode','Manual');
set(handle,'Marker','.');
print(gcf, '-dpdf', '-r150', horzcat('markertest4.pdf'));

这会产生以下

谁能帮我解决这个问题?

【问题讨论】:

    标签: matlab plot


    【解决方案1】:

    是的,我想我知道你需要什么。试试这个:

    zoomStart = 0;
    zoomStop = 3;
    set(gca, 'XLim', [zoomStart zoomStop])
    

    如果这不能满足您的需要,请告诉我,我会给您另一种方法。

    【讨论】:

    • 它比我拥有的更好,但它仍然不完全存在。缩放窗口中没有绘制任何点。它们闪烁然后消失。
    • 嗯,这很奇怪。当您说它们消失时,轴是否会重新缩放?还是保持不变,没有积分?
    猜你喜欢
    • 1970-01-01
    • 2019-05-04
    • 2020-09-18
    • 1970-01-01
    • 2011-12-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多