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

 采纳的回答

Etsuo Maeda
Etsuo Maeda 2019-8-28

1 个投票

5 个评论

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.
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;
That is great! Thank you so much for your help!
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

请先登录,再进行评论。

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Scatter Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by