PLOT2AXES

버전 1.1.0.1 (5.56 KB) 작성자: Jiro Doke
Plot a set of data with two different axes.
다운로드 수: 8.5K
업데이트 날짜: 2016/9/1

라이선스 보기

PLOT2AXES(X, Y, 'Param1', 'Value1', ...) plots X versus Y with secondary axes. The following parameters are accepted [default values]:
xloc ['top']: location of secondary X-axis
yloc ['right']: location of secondary Y-axis
xscale [1]: scaling factor for secondary X-axis (scalar)
yscale [1]: scaling factor for secondary Y-axis (scalar)

xscale and yscale can also be an anonymous function that describes the relationship between the 2 axes, such as the equation relating Celsius and Fahrenheit: @(x) 5/9*(x-32)

xlim [NaN NaN]
ylim [NaN NaN]:
xlim/ylim in the primary axes (secondary is adjusted accordingly). The default is naturally selected by the plotting function.

PLOT2AXES(@FUN, ...) uses the plotting function @FUN instead of PLOT to produce the plot. @FUN should be a function handle to a plotting function, e.g. @plot, @semilogx, @semilogy, @loglog ,@stem, etc. that accepts the syntax H = FUN(...). Optional arguments accepted by these plotting functions are also allowed (e.g. PLOT2AXES(X, Y, 'r*', ...))

[AX, H] = PLOT2AXES(...) returns the handles of the primary and secondary axes (in that order) in AX, and the handles of the graphic objects in H.

Right-click on the axes to bring up a context menu for adding grids to the axes.

The actual data is plotted in the primary axes. The primary axes lie on top of the secondary axes. After the execution of this function, the primary axes become the current axes. If the next plot replaces the axes, the secondary axes are automatically deleted.

When you zoom and pan, the secondary axes will automatically adjust itself (only available on R2006b or later). For older releases of MATLAB®, there will be a "Fix Axes" menu, which let's you adjust the limits.

PLOT2AXES('FixAxes') fixes the secondary limits of all figures created using plot2axes.

Example 1:
x = 0:.1:1;
y = x.^2 + 0.1*randn(size(x));
[ax, h] = plot2axes(x, y, 'ro', 'yscale', 25.4);
title('Length vs Time');
ylabel(ax(1), 'inch');
ylabel(ax(2), 'millimeter');
xlabel('time (sec)');

Example 2:
x = 1:10;
y = 50*rand(size(x));
[ax, h] = plot2axes(x, y, 'ro', 'yscale', @(x) 5/9*(x-32), ...
'xscale', 2.20);
xlabel(ax(1), 'kg'); ylabel(ax(1), 'Fahrenheit');
xlabel(ax(2), 'lb'); ylabel(ax(2), 'Celcius');

인용 양식

Jiro Doke (2024). PLOT2AXES (https://www.mathworks.com/matlabcentral/fileexchange/7426-plot2axes), MATLAB Central File Exchange. 검색됨 .

MATLAB 릴리스 호환 정보
개발 환경: R2009b
모든 릴리스와 호환
플랫폼 호환성
Windows macOS Linux
카테고리
Help CenterMATLAB Answers에서 Combine Multiple Plots에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
버전 게시됨 릴리스 정보
1.1.0.1

Updated license

1.1.0.0

Added auto adjust of axes limits (works R2006b and later). Now works with nonlinear scaling. Added ability to add grids interactively. Use of function handles instead of strings.

1.0.0.0

Fixed problem plotting on uipanel, where the parent of the axes is not a figure.