For 2 curves, how to have xticks on both the above and below of x-axis?

1 回表示 (過去 30 日間)
Xiaohan Du
Xiaohan Du 2018 年 5 月 14 日
コメント済み: Xiaohan Du 2018 年 5 月 15 日
Hi all, I plot the attached figure using this code
clear; clc;
x1 = [1 3 5 7];
x2 = [1 2 4 7];
data1 = [1 2 3 4];
data2 = [4 3 2 1];
hAx1 = semilogy(x1, data1, 'b-^');
hold on
hAx2 = semilogy(x2, data2, 'k-v');
I'd like to have x1 on top and x2 on below of the x-axis using xticks, so the figure would show (1 3 5 7) on the below of x-axis with blue numbers and show (1 2 4 7) on the top of the x-axis with black numbers. Such that the 2 curves are differentiated.
Many thanks!

回答 (2 件)

Akira Agata
Akira Agata 2018 年 5 月 15 日
The following is one way to do that. Please see the following link for more details.
hAx1 = semilogy(x1, data1, 'b-^');
hold on
hAx2 = semilogy(x2, data2, 'k-v');
ax1 = gca;
ax1.XColor = 'b';
ax1.XTick = [1 3 5 7];
ax2 = axes(...
'Position', ax1.Position,...
'XAxisLocation', 'top',...
'Color', 'none',...
'YTick', [],...
'XLim', [1 7],...
'XTick', [1 2 4 7]);
  1 件のコメント
Xiaohan Du
Xiaohan Du 2018 年 5 月 15 日
How to get rid of the extra scale on the top x axis and right y axis?

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


the cyclist
the cyclist 2018 年 5 月 14 日
The easiest way to get something close to what you want is to use the yyaxis command. Take a look at the examples there.

カテゴリ

Help Center および File ExchangeAnnotations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by