x2 and y2 not plotting as expected

2 ビュー (過去 30 日間)
Kathy
Kathy 2017 年 5 月 26 日
コメント済み: Jan 2017 年 5 月 26 日
Code is following
clear all; close all; clc;
% Arbitrary x's and y's
x1 = [10 20 30 40];
y1 = [1 2 3 4];
x2 = [100 200 300 400];
y2 = [105 95 85 75];
figure
plot(x1,y1,'o', 'MarkerEdgeColor', 'r', 'MarkerFaceColor', 'r')
ax2 = axes('Color','none'); % Create secondary axis
plot(ax2, x2,y2,'o', 'MarkerEdgeColor', 'b', 'MarkerFaceColor', 'b')
% Now set the secondary axis attributes
ax2.Color = 'none'; % Make the chart area transparent
ax2.XAxisLocation = 'top'; % Move the secondary x axis to the top
ax2.YAxisLocation = 'right'; % Move
i get the output
but i am looking for this output
x2 and y2 are not plotting properly.where am i going wrong?
  2 件のコメント
Guillaume
Guillaume 2017 年 5 月 26 日
Which version of matlab?
Your code works fine for me.
Jan
Jan 2017 年 5 月 26 日
Works fin in R2015b.

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

採用された回答

Steven Lord
Steven Lord 2017 年 5 月 26 日
You don't need to manually plot two axes. Use yyaxis (or for older releases that don't have yyaxis, use plotyy) instead.

その他の回答 (1 件)

Kathy
Kathy 2017 年 5 月 26 日
MATLAB Version: 8.3.0.532 (R2014a)

カテゴリ

Help Center および File Exchange2-D and 3-D Plots についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by