複数の x 軸と y 軸があるチャートのマーカー表示

複数の x 軸と y 軸があるチャートを作成した際に、描画コマンドとしてlineを使用しているのですが、線でしか表示されず、マーカーを表示させたいですが、エラーが出てしまい出来ない状態です。複数の x 軸と y 軸があるチャートを作成するためにはplotは使えないようなので困っています。

4 Kommentare

madhan ravi
madhan ravi am 18 Jul. 2019
Could you upload your code?
riku
riku am 18 Jul. 2019
figure
line(frequency,height,'Color','b','LineWidth',2);
grid(gca,'minor');
ax1 = gca;
ax1.XColor = 'b';
ax1.YColor = 'b';
set(gca,'FontSize',20);
xlabel('周波数[Hz]','FontSize',20);
ylabel('高度[km]','FontSize',20);
xlim([0 3000]);
ylim([95 130])
ax1_pos = ax1.Position;
ax2 = axes('Position',ax1_pos,...
'XAxisLocation','top',...
'YAxisLocation','right',...
'Color','none');
line(ondo,height,'Parent',ax2,'Color','r','LineWidth',2);
ax2.XColor = 'r';
ax2.YColor = 'r';
set(gca,'FontSize',20);
xlabel('温度[K]','FontSize',20);
ylabel('高度[km]','FontSize',20);
ylim([95 130])
madhan ravi
madhan ravi am 18 Jul. 2019
Can you provide the missing variable datas too?
riku
riku am 18 Jul. 2019
Sorry, It's secert.

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

Kazuya
Kazuya am 20 Jul. 2019

1 Stimme

うまくいかない状況を共有できれば解決も速いと思います。使用するデータに依存する現象だと難易度かなりあがります。
以下、乱数で適当プロットしてみましたが、マーカーの表示も問題ありませんでした。
R2019a で試しましたが、バージョンによるんでしょうか・・。
エラーがでるとのことですが、どんなエラーメッセージですか?
figure
frequency = rand(10,1);
height = rand(10,1);
line(frequency,height,'Color','b','LineWidth',2,'Marker','x');
grid(gca,'minor');
ax1 = gca;
ax1.XColor = 'b';
ax1.YColor = 'b';
set(gca,'FontSize',20);
xlabel('周波数[Hz]','FontSize',20);
ylabel('高度[km]','FontSize',20);
% xlim([0 3000]);
ylim([0,1])
ax1_pos = ax1.Position;
ax2 = axes('Position',ax1_pos,...
'XAxisLocation','top',...
'YAxisLocation','right',...
'Color','none');
ondo = rand(10,1);
line(ondo,height+1,'Parent',ax2,'Color','r','LineWidth',2,'Marker','o');
ax2.XColor = 'r';
ax2.YColor = 'r';
set(gca,'FontSize',20);
xlabel('温度[K]','FontSize',20);
ylabel('高度[km]','FontSize',20);
ylim([1,2])

Weitere Antworten (1)

Etsuo Maeda
Etsuo Maeda am 25 Jul. 2019

0 Stimmen

Kazuyaさんに便乗しまして、plot関数を使った複数軸プロットの方法をご紹介しておきます。
プロット系の関数は実行時にaxesのプロパティをリセットしてしまいます。
予めNextPlotプロパティをreplacechildrenにしておくか、plotしてからaxesのプロパティを調整するようにしておけば、plot関数を使った複数軸プロットが実現できます。
ドキュメンテーション「グラフの Figure および座標軸の準備」
untitled.png
xL = 1:10;
yL = sin(xL);
xR = -xL;
yR = sin(xR);
f = figure;
axL = axes('Parent', f);
axL.NextPlot = 'replacechildren';
axL.XColor = 'b';
axL.YColor = 'b';
axL.Box = 'off';
axL.Color = 'g';
myPos = axL.Position;
axR = axes('Parent', f, 'Position', myPos);
axR.NextPlot = 'replacechildren';
axR.XColor = 'r';
axR.YColor = 'r';
axR.Box = 'off';
axR.XAxisLocation = 'top';
axR.YAxisLocation = 'right';
axR.Color = 'none';
hL = plot(axL, xL, yL, 'bo-', 'MarkerFaceColor', 'b', 'MarkerSize', 8);
hR = plot(axR, xR, yR, 'ro-', 'MarkerFaceColor', 'r', 'MarkerSize', 18);
legend([hL, hR], 'Left', 'Right')
HTH

Gefragt:

am 18 Jul. 2019

Beantwortet:

am 25 Jul. 2019

Community Treasure Hunt

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

Start Hunting!