scatter plot with color gradient on y-values

86 ビュー (過去 30 日間)
Alejandro Fernández
Alejandro Fernández 2020 年 6 月 8 日
Hello, I have a question: when making a scatterplot with a color gradient, what I want is that this gradient is applied to the values on the Y axis, not to those on the X axis (which is what I manage to do with the code at the bottom)
close all; clear all; clc
load data.mat
data = flipud(data.').';
% Create colormap
len = 50;
c1 = [5, 25, 150]/255;
c2 = [245, 225, 235]/255;
c = [linspace(c1(1),c2(1),len)', linspace(c1(2),c2(2),len)', linspace(c1(3),c2(3),len)'];
% Scatter data
scatter(data(1, :), data(2, :), 10, 1:size(data,2), 'filled');
colormap(c);
colorbar
What I mean is that, being the data of the Y axis number that goes from 0 to 1, and I take into account that the color scale goes from dark blue for low values to pink for high values, if you have the points (x,y) (5,0.75), (6,0.80) and (7,0.40) what I want to achieve is that the point (7,0.40) is the most blue, the (6,0.80) the most pink and therefore the point (5,0.75) has an intermediate color.

採用された回答

Bjorn Gustavsson
Bjorn Gustavsson 2020 年 6 月 8 日
That should be as easy as:
scatter(data(1, :), data(2, :), 10, data(2,:), 'filled');
You can modify the scaling of the colour-argument of you want a different look, sqrt, log or whatever, and then make the corresponding change to colorbar etc.
HTH
  1 件のコメント
Alejandro Fernández
Alejandro Fernández 2020 年 6 月 8 日
Thank you so much, it works!!!

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

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by