Consider X, Y and Z as n-columnar vector where, Z only has values 1-6.
Then, I would like to plot
for i=1:n
if Z(i) == 1
plot(X(i), Y(i), #1)
hold on
elseif
plot(X(i), Y(i), #2)
...
What I would like to do is accomplish this in single line as
plot(X, y, 'color', Z).
Is there a way to do so?
(In short, can my settings (color in this instance) be dictated by third vector? )
Thanks in advance.
If I understood your question correctly, you want to plot each pair of coordinates x(i), y(i) using color z(i). Use the scatter() function:
scatter(x,y,[],z)
z can be either a vector or a matrix where each row is a RGB color specification.
Related
I have the following data:
d units m : (2481.7, 2483.5, 2486.1, 2488.5)
p units psi: (3759.7, 3759.6, 3760.7, 3761.7)
and I have to find psi/m
I am using =slope(p,d) and it's giving me 0.3147 psi/m. But when I scatter plot d on the y-axis and p on the x axis and draw a linear trendline, the slope is 2.9233 m/psi. I found 1/2.9233 = 0.34207 psi/m, however the values in bold should be the same.
I also tried following, and it's giving absurd answers again
d: (2481.7, 2483.5, 2486.1, 2488.5)
p: (3759.7, 3759.6, 3760.7, 3761.7)
When I use linest(d,p), the slope is 2.9297 m/psi, which translates to 0.341 psi/m, but when I use linest(p,d), the slope is 0.314 psi/m. But the figures in bold should be the same?
This is due to changing axis variable which in turn changes the variance
I want to do a multi-branch fit with gnuplot. I have a set of data containing values for xyerror the following data.
x y1 dx dy1
x y2 dx dy2
I was able to do a fit without x and y errors.
fit f(x,y) 'files.dat' using 1:-1:2 via a,b,c
I want to know how to do a multi-branch fit with x and y errors?
Thank you in advance
As far as I can tell your case is already mentioned in the gnuplot manual about fit:
As an example, if one has 2 independent variables, and errors for the first independent variable and the
dependent variable, one uses the errors x,z qualifier, and a using qualifier with 5 columns, which are
interpreted as x:y:z:sx:sz (where x and y are the independent variables, z the dependent variable, and sx and
sz the standard deviations of x and z).
x ("x" in your data file) and y (line number) are your two independent variables, z ("y" in your data file) is the dependent variable. For your case the fit command should look like
fit f(x,y) 'files.dat' using 1:-1:2:3:4 errors x,z via a,b,c
I need help with Matlab.
I have an Excel sheet with three columns: X, Y and Z. I have used plot3 function to make one 3D curve.
But I need to vary it in colors.
What function/functions do I need to make X, Y and Z in different 3 colors(each column one color)?
Could you please send me link, where I can find out the way, or just write the function/functions needed for it?
Here is the code:
VCG=xlsread('VCGsheet.xls');
figure(1)
plot3(VCG(:,1),VCG(:,2),VCG(:,3));
grid on
I know that plot3 isn't suitable for it.
I'm not aware of a native command that draws line with varying color.
I will also assume that VCG vector is a vector of RGB values, so one color per row.
RGB = VCG(:,1:3);
If you want, you can replace it (VCG(:,1:3)) with any other vector of color derived from your data. Here is an example if you have a single value that can be calculated for each of your points, in the vector T for example, and that you want to show as a color.
map = jet(256);
RGB = map(round((T(:)-min(T(:)))/(max(T(:)) - min(T(:)))*255)+1,:);
For the plot, I propose two different ways:
you can make use of the scatter3 function
It will print points, but no lines connecting the points. The color vector is set with VCG(:,1:3)
colormap('jet')
scatter3(VCG(:,1), VCG(:,2), VCG(:,3), 70, RGB, 'filled');
You can make a direct use of line in a for loop.
It is a bit slower, but it is generally ok for graphs.
for i=2:size(VCG,1)
line(VCG(i-1:i,1), VCG(i-1:i,2), VCG(i-1:i,3), 'color', RGB(i-1,:));
end
If you want both, just use the hold function
I hope I understood what you needed !
I have a contour map in spatstat generated from the intensity function of a point pattern X (like "location of the trees"). Each x,y coordinates in this point pattern is marked with a corresponding third vector (like "diameter of the tree").
-->cf image (of course the vertical lines representing the tree can be omitted)
I would like to display the average of the mark (diameter) in each level of the contour with different colors. Suggestions?
Thanks!
You are effectively asking for a kind of nonparametric regression.
Here is a quick-and-dirty calculation using the function rhohat and demonstrated on the longleaf dataset.
First calculate the intensity estimate: Z <- density(longleaf) yielding an image Z. Next treat Z as a covariate in calls to the rhohat command:
f <- rhohat(unmark(longleaf), Z)
and
g <- rhohat(unmark(longleaf), Z, weights=marks(longleaf)).
Now take the ratio, h <- eval.fv(g/f) and plot it, plot(h). This shows the estimated average tree diameter as a function of the forest density. To apply this function h to the original contours of Z you would first convert h to a true function by H <- as.function(h) then evaluate hZ <- eval.im(H(Z)) and finally plot(hZ).
Hi this may seem to be a simple question but I am having a hard time understanding how to use the colors in a plot3d.
That is what I have:
// x, y and z are matrix 4 by 100
myColors = ones(1,size(z,2));
plot3d(x,y,list(z,myColors),alpha=0,theta=270);
I would like to have myColors related to the altitude of z.
Code
If I understand correct x, y and z are something like:
x = [ 1:100 ];
y = [ 1:4 ];
z = rand( length(x), length(y) ); //Some function resulting in (100 x 4) matrix
Then you can plot it using the following code.
plot3d( x, y, z, alpha=0, theta=270);
e = gce(); // Get current entity handle.
e.color_flag = 1; // Color according to z
f = gcf(); // Get current figure handle.
f.color_map = hotcolormap(512); // Make it a heat color map
Docs
According to the plot3d docs and surface_properties docs the color_flag can be used to:
color_flag: This field is used to specify the algorithm used to set facets' colors.
Note that the rules on color_mode, foreground and hiddencolor are
still applied to this case.
...
color_flag == 1
All facets are painted using one color index per facet proportional to
z. The minimum z value is painted using the index 1 color while the
maximum z value is painted using highest color index. The edges of the
facets can be additionaly drawn depending on the value of color_mode
(see above).
Resulting image