Plotting in two side

5 ビュー (過去 30 日間)
George
George 2023 年 7 月 21 日
編集済み: Samya 2023 年 7 月 21 日
Matlab includes plotyy for plotting two graphs with distinct yaxes, however it does not synchronize the tics. Matlab also does not allow you to disable the tics on the opposite side. so far as I am aware.
Now I'd like to plot two lines with entirely unconnected y-data. The tics on the left and right axes are currently out of sync, making the plot look skewed.
So I need a way to synchronize the tics on both sides of the y-axis.
This is my plot function:-
[axiss,height1,height2] = plotyy(x_0, y_1, x_0, y_2);
I wrote this much till now. Please help what to do further:-
a_0 = axes;
set(a_0,'Box','on','Color','white','XTick',[],'YTick',[]);
a_1 = axes('Position',get (a_0, 'Position'));
set(a_1,'Box','off','Color','none','YAxisLocation','left');
a_2 = axes('Position',get (a_0,'Position'));
set(a_2,'Box','off','Color','none','XTick',[],'YAxisLocation','right');

採用された回答

Samya
Samya 2023 年 7 月 21 日
編集済み: Samya 2023 年 7 月 21 日
Hi, To synchronize the ticks on the y-axis of two plots created using the `plotyy` function in MATLAB, you can use the `addaxis` function from the MATLAB File Exchange. Here's how you can integrate it with your plot:
1. Download and install the `addaxis` function from the MATLAB File Exchange. You can find it at this link: addaxis.
2. After installing `addaxis`, you can modify your code as follows:
% Create the initial plot using plotyy
[axiss,height1,height2] = plotyy(x_0, y_1, x_0, y_2);
% Set the ticks and tick labels for the right axis
set(axiss(2), 'YTick', <your array>);
set(axiss(2), 'YTickLabel', <your cell array>);
% Add the second y-axis using addaxis
addaxis(x_0, y_2, 'r');
% Set the ticks and tick labels for the added axis
addaxislabel(2, <your array>);
This will synchronize the ticks on both y-axes and display the second y-axis with the specified tick values and labels.
Hope it helps!

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeTwo y-axis についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by