Dear friends,
I would like to draw scatter diagram with 3-y axis. Please help me.
Thank you so much!

 Réponse acceptée

Etsuo Maeda
Etsuo Maeda le 28 Août 2019

1 vote

5 commentaires

Tien Nguyen
Tien Nguyen le 28 Août 2019
Hi,
I found this link before, and it is for plot not for scatter.
I also tried did for scatter, but I could not get the diagram because the codes in that link for 'plot' only.
Etsuo Maeda
Etsuo Maeda le 29 Août 2019
OK, just try to rewrite the logic with Axes properties. It works fine in R2019a.
clear; close all;
% create dummy data
x = 1:10;
y1 = rand(1, 10);
y2 = rand(1, 10)*10;
y3 = rand(1, 10)*100;
% create Figure f
f = figure;
% create Axes ax1
ax1 = axes('Parent', f);
ax1.NextPlot = 'replacechildren';
% create invisible Axes ax2
ax2 = axes('Parent', f);
ax2.NextPlot = 'replacechildren';
ax2.Color = 'none';
ax2.XAxis.Visible = 'off';
ax2.YAxis.Visible = 'off';
% create invisible Axes ax3
ax3 = axes('Parent', f);
ax3.NextPlot = 'replacechildren';
ax3.Color = 'none';
ax3.XAxis.Visible = 'off';
ax3.YAxis.Visible = 'off';
% plot scatter data x, y1, y2, y3
scatter(ax1, x, y1, 'ro')
scatter(ax2, x, y2, 'gx')
scatter(ax3, x, y3, 'b*')
% create dummy Axes, dAx1
dAx1 = ax1;
dAx1.YColor = 'r';
% create dummy Axes, dAx2 with right YAxis
dAx2 = axes('Parent', f);
dAx2.YColor = 'g';
dAx2.Color = 'none';
dAx2.XAxis.Visible = 'off';
dAx2.YAxisLocation = 'right';
dAx2.YLim = ax2.YLim;
% create dummy Axes, dAx3 with offset YAxis
dAx3 = axes('Parent', f);
dAx3.YColor = 'b';
dAx3.Color = 'none';
dAx3.XAxis.Visible = 'off';
Pos = ax1.Position;
dAx3.Position = Pos + [-0.06 0 0 0];
dAx3.YLim = ax3.YLim;
Tien Nguyen
Tien Nguyen le 2 Sep 2019
That is great! Thank you so much for your help!
Etsuo Maeda
Etsuo Maeda le 2 Sep 2019
:-)
Ahmad Bayhaqi
Ahmad Bayhaqi le 9 Avr 2022
Hi, thank you very much for this code. This also works for me. Then, is there a way to put legend and ylabel in this code? @Etsuo Maeda

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by