MATLAB: Plotting only ponts with colorbar based on

2019-08-26 20:07发布

I want to plot only data points. Now I can plot the points which only considers 1 type of point. But my data contains different column variables. I want to plot different figures with different x and y variables from the data. Suppose I want to plot variable D against variable A or variable E against variable year but I want to plot data points with different colors or different types of points either *, dot, diamond etc. based on suppose, variable pub or variable E. Now for colormap I want to show colormap beside the figure with where the range of the variable value will be shown. For different type of points the point indexes will be suppose another variable E.

Also the 1st data should have a completely different point so that it can be distinguishable. My code actually shows different point for that data but it also plots with others.

Here is the truncated data.

Can anyone help me with that?

My code:

T = readtable('Data.xlsx');

year = T.Year;
pub = T.Publication;
A = T.A;
B = T.B;
C = T.C;
D = T.D;
E = T.F;

% Plot Data
f = figure;
%hold on; grid on, box on;
plot(A, D,'*')
hold on;
plot(A(1), D(1),'d')

1条回答
混吃等死
2楼-- · 2019-08-26 20:43

It feels like this matlab example should be pretty close to what you want. It is a scatter plot (like your plot(A,D,'*') command), and has a colour scale that varies with a third variable c.

You should then combine this with a hold on command and plotting the first point using a different style suitable to your liking. You could something along the lines of the following (I have not downloaded your data, so I will use the example from the matlab link I provided):

x = linspace(0,3*pi,200);     % Independent variable
y = cos(x) + rand(1,200);     % Dependent variable
c = linspace(1,10,length(x)); % Colour variable

% Plot all points except the first one using colours in c and size 50:
scatter( x(2:end), y(2:end), 50, c(2:end) );
hold on

% Plot first point differently: twice the size, and with a filled marker:
scatter( x(1), y(1), 100, c(1), 'filled');
legend({'Data','First point'});
hold off
查看更多
登录 后发表回答