MATLAB:仅基于基于另一个变量的颜色条来绘制点图 [英] MATLAB: Plotting only ponts with colorbar based on another variable
问题描述
我只想绘制数据点.现在,我可以绘制仅考虑一种点类型的点.但是我的数据包含不同的列变量.我想从数据中绘制具有不同x和y变量的不同图形.假设我想针对变量A
绘制变量D
或针对变量year
绘制变量E
,但是我想基于假设绘制具有不同颜色或不同类型点的数据点*,点,菱形等,变量pub
或变量E
.现在,对于颜色图,我想在图形旁边显示颜色图,并在其中显示变量值的范围.对于不同类型的点,点索引将假定为另一个变量E
.
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.
这是被截断的数据.
有人可以帮我吗?
我的代码:
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')
推荐答案
感觉像这个Matlab示例应该与您想要的非常接近.这是一个scatter
绘图(类似于您的plot(A,D,'*')
命令),并且色标随第三个变量c
的不同而变化.
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
.
然后应将此命令与hold on
命令结合使用,并使用适合自己喜好的其他样式绘制第一个点.您可以按照以下方式进行操作(我尚未下载您的数据,因此我将使用我提供的matlab链接中的示例):
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
这篇关于MATLAB:仅基于基于另一个变量的颜色条来绘制点图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!