MATLAB: Plotting only ponts with colorbar based on another variable

廉价感情. 提交于 2019-12-11 15:16:02

问题


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:


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


来源:https://stackoverflow.com/questions/52395163/matlab-plotting-only-ponts-with-colorbar-based-on-another-variable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!