web-dev-qa-db-ja.com

MATLABプロットの右軸と左軸が異なりますか?

plot()を使用してMATLABで単一のトレースをプロットします。目盛りのセットが異なる(線形にスケーリングされた)右y軸を追加したいと思います。これは可能ですか?

13
AndyL

この密接に関連する質問 には多くの良い提案がありますが、それらはあなたよりも複雑な状況を扱っています。超シンプルなDIYソリューションが必要な場合は、次の方法を試すことができます。

plot(Rand(1, 10));       % Plot some random data
ylabel(gca, 'scale 1');  % Add a label to the left y axis
set(gca, 'Box', 'off');  % Turn off the box surrounding the whole axes
axesPosition = get(gca, 'Position');           % Get the current axes position
hNewAxes = axes('Position', axesPosition, ...  % Place a new axes on top...
                'Color', 'none', ...           %   ... with no background color
                'YLim', [0 10], ...            %   ... and a different scale
                'YAxisLocation', 'right', ...  %   ... located on the right
                'XTick', [], ...               %   ... with no x tick marks
                'Box', 'off');                 %   ... and no surrounding box
ylabel(hNewAxes, 'scale 2');  % Add a label to the right y axis

そして、これがあなたが得るべきものです:

enter image description here

16
gnovice

このMATLABFile Exchangeへの送信を試すことができます- PLOT2AXES

PLOT2AXESの例http://www.mathworks.com/matlabcentral/fx_files/7426/2/plot2axes.png

8
yuk

Jiroのソリューションは優れています(ファイル交換関数)が、Matlabの組み込みプロット関数(bar、scatterなど)を使用することはできず、代わりにplot2axesを使用する必要があります。 Matlabの独自のヘルプは、任意のタイプのプロットに2つの軸を持つソリューションを提供します:ax2 = axis( 'Position'、get(ax1、 'Position')、... 'XAxisLocation'、 'top'、... 'YAxisLocation' 、 'right'、... 'Color'、 'none'、... 'XColor'、 'k'、 'YColor'、 'k');

見てください: http://www.mathworks.com/help/techdoc/creating_plots/f1-11215.html

2
Mam

F1でMATLABヘルプを開き、以下の関数を見てください。関数 plot で、そこに plotyy が表示されます。これはおそらくあなたが必要とするものです。

UPDATE:実際には plotyy は、gnoviceが指摘した質問への回答ではありません。

1
Mikhail

Matlab 2016以降では、どの軸にプロットするかを定義するオプションがあります。

yyaxis left
plots...
yyaxis right
plots...

ソース: https://se.mathworks.com/help/matlab/ref/yyaxis.html

1
IceQueeny