Hello, below you can see the structure of my plot. At the moment Im using the same y axis for every plot but I want to use two different y axis. One for the bar plot (patch...) and a second one for the other plots. How can i do this?
f(8) = figure('Units','pixels',...
'position',[fLeft fBottom fWidth fHeight],...
'PaperType','A4',...
'PaperOrient','portrait',...
'PaperPositionMode', 'manual');
set(gcf, 'color', GrayLight);
set(gcf, 'InvertHardCopy', 'off');
AxH = axes('NextPlot','add');
for k1 = 1:size(...)
hLine=patch(...);
end
plot(...,...)
hold on
grid on
datacursormode on
title(...)
xlabel(...)
ylabel(...)
xlim(...)
ylim(...);
plot(...,...)
hold on
plot(...,...)
legend({'...'},...
'Position',[....
'FontSize',LegendFontSize,...
'Color',Gray);
xTick=...
set(gca,'Color',GrayLight, 'XTick', xTick);

 採用された回答

Stephen23
Stephen23 2018 年 7 月 27 日
編集済み: Stephen23 2018 年 7 月 27 日

0 投票

Create two axes. For the top axes set the YAxisLocation to right, the Color to none, and NextPlot to replacechildren.
For example:
>> ax1 = axes();
>> ax2 = axes('YAxisLocation','right','Color','none','NextPlot','replacechildren');
>> plot(ax1,0:3,0:3)
>> plot(ax2,0:3,sqrt(0:3))
giving:
Do not use gcf and gca: always obtain and use the explicit handles for all graphics objects that you need to refer to.

5 件のコメント

leonidas86
leonidas86 2018 年 7 月 27 日
How can I create two axis?
Stephen23
Stephen23 2018 年 7 月 27 日
"How can I create two axis?"
Exactly like I showed you in my answer: my answer has just four lines of code. Did you look at them? The first two lines create two axes, by calling axes twice. The next two lines plot data on those two axes.
leonidas86
leonidas86 2018 年 7 月 27 日
Thanks, your example is running. But how can I do this with the patch function above? When I write patch(ax1,...) I get an error that vectors must be the same length..
leonidas86
leonidas86 2018 年 7 月 27 日
It works with 'Parent', ax1
Stephen23
Stephen23 2018 年 7 月 27 日
Not all versions of MATLAB allow the first input argument of patch to be an axes handle. To know what your installed version does always refer to the installed help, not the online help. Note that you can provide the axes handle as a Name-Value input argument:
patch(...,'Parent',ax1)
For example:
>> axh = axes();
>> patch([0,0.5,1],[0,1,0],1,'Parent',axh)
generates this:

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeTwo y-axis についてさらに検索

質問済み:

2018 年 7 月 27 日

コメント済み:

2018 年 7 月 27 日

Community Treasure Hunt

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

Start Hunting!

Translated by