So, I have two arrays:
X'
ans =
2.5770 2.5974 2.1031 2.7813 2.6083 2.9498 3.0053 3.3860
>> Y'
ans =
0.7132 0.5908 1.9988 1.0332 1.3301 1.1064 1.3522 1.3024
I would like to combine n-th members of two arrays together, and than plot those coordinates on graph.
So it should be:
{(2.5770,0.7132), (2.5974,0.5908)...}
Is this possible to do? If so, how?
Schorsch showed that it is simple to plot, but just to answer the question as asked in the title, you can combine the arrays into coordinates by just arranging the vectors like rectangles.
Your x and y are vertical, so you can put them side-by-side in a 2-column matrix:
combined = [x y]
or transform and have 2 rows: combined = [x' ; y']
(Because they're vertical, what you don't want is these, which would concatenate them out into one long column or row: [x ; y] or [x' y'])
Just to be clear, though, this is not needed for plotting.
Edit: A suggested edit asked what happens if you plot(combined). That depends if it's the horizontal or vertical version. In any case, plotting a 2x? matrix won't plot x vs. y. It plots all of the columns versus the simple indices 1,2,3,... So the first way I defined combined will make two lines, plotting x and y on the y-axis against their indices on the x-axis, and the second version of combined will make a strange plot with the all of the values of x plotted in a vertical column where x=1 and all of the points of y beside those at x=2.
Related
I am trying to extract the coordinates located in the variable x within a .mat structure. I would like to print them as a three column matrix. Let's say:
-5543837.67700032 -2054567.16633347 2387852.25825667
4641938.565315761 393003.28157792 4133325.70392322
-3957408.7414133 3310229.46968631 3737494.72491701
1492206.38965564 -4458130.51073730 4296015.51539152
4075539.69798060 931735.497964395 4801629.46009471
3451207.69353006 3060375.44622100 4391915.05780934
I know that I can get them with
file=load('./filee_scan.mat')
stat = [file.scan.stat]';
x = [stat.x]';
But I get something like:
-5543837.67700032
-2054567.16633347
2387852.25825667
4641938.565315761
393003.28157792
4133325.70392322
% :: and so on
I would like to print them as I showed at the beginning (x as a vector of 3 coordinates and one line per station) but I don't know how to treat them. I have tried with loops but I really don't know how to express them.
How can I display my coordinates as an n -by- 3 matrix?
This is the scan file:
This is x:
[stat.x].' gives you a flattened vector, as you've seen. You can reshape() that vector to the desired format:
x = reshape(x,3,[]).';
This reshapes first to 3 rows and n columns (your number of stations), then transposed to have n rows of 3 columns.
For a short introduction on how reshape works, see this answer of mine.
I am trying to do up a 3D array plot in R.
I already have an array built up and defined with the corresponding z-values
e.g. CVHSP500 = array(0,c((nHSP500-N),N))
So now I am trying to do a 3D array plot with it. I decided to go with persp3d(CVHSP500,col = "lightblue",) and have obtained a rather decent plot.
3D Image
So there are obviously some issues with this plot.
1) The coordinates are not defined correctly.
Reading up online on the usage of persp3D, and other R programming functions/packages like slice3D, they all require x, y and z to be separate list.
I don't understand how to match the values of x and y to the respective z, and since persp3D works perfectly without me having to do that, I decided to use persp3D.
But I will need to insert coordinates for it, but I have no idea how to.
2) Any advice how do I color the plots for different ranges of z?
The ones online all seem to have to refer to individual x, y and z lists and some form of advanced modification which I can't really understand. This light blue color looks okay but it would be good for different ranges of z as well though.
Thanks for the help. Much appreciated.
To transform a 2D array representing z for each (x,y) into 3 vectors x, y and z, you can do this:
CVHSP500 = array(0,c((nHSP500-N),N))
x <- rep(1:(nHSP500-N),N)
y <- rep(1:N,(nHSP500-N))
z <- CVHSP500
dim(z) <- (nHSP500-N)*N
I have an Nx3 array which stores the values in N coordinates. The first and second column correspond to x and y coordinate respectively, and the third column represents the value at that coordinates. I want to plot a 2D intensity plot, what's the best way to do it?
If the coordinates are evenly spaced, then I can use meshgrid and then use imshow, but in my data the coordinates are not evenly spaced. Besides, the array is very large N~100000, and the values (third column) span several orders of magnitude (so I should be using a logplot?). What's the best way to plot such a graph?
You can use griddata to interpolate your data at all 100000 points to a uniform grid (say 100 x 100) and then plot everything with a Log scaling of the colours,
x = data[:,0]
y = data[:,1]
z = data[:,2]
# define grid.
xi = np.linspace(np.min(x),np.max(x),100)
yi = np.linspace(np.min(y),np.max(y),100)
# grid the data.
zi = griddata(x,y,z,xi,yi,interp='linear')
#pcolormesh of interpolated uniform grid with log colormap
plt.pcolormesh(xi,yi,zi,norm=matplotlib.colors.LogNorm())
plt.colormap()
plt.show()
I've not tested this but basic idea should be correct. This has the advantage that you don't need to know your original (large) dataset and can work simply with the grid data xi, yi and zi.
The alternative is to colour a scatterplot,
plt.scatter(x, y, c=z,edgecolors='none', norm=matplotlib.colors.LogNorm())
and turn off the outer edges of the points so they make up a continuous picture.
I got a 2d array ,that each row represents a signal (for wiener filtering)
Arr(10,45).
I want to plot,all signals (all column) in same figure, with X axis the K coefficient of wiener fieltering that is
K=(-11:0.5:11);
Which is of size=45.I also want it to be with logarithmic in both axis , x and y.
But when i plot with
loglog(Arr.');
set(gca,'xtick',(-11:0.5:11);
The result is not what i need.
What's going on?thanks in advance.
When plotting it, you should specify the k values as the first input to plot and Arr.' as the second. If you do not do this, MATLAB will simply use 1:size(Arr, 2) as the x coordinates of your plot.
hplot = plot(k, Arr.');
I have 3 Nx1 arrays, say X,Y,Z. I'd like to create a 3D plot such that each of the arrays I can assign different colours to improve the visibility of points. My main objective now is to change only the colour of array Z, such that elements of array X and Y have different colours as that of elements of Z .
I tried scatter3 function and gscatter MATLAB functions, but not able to achieve what I desire.
If we see the Vertical axis in image (Z axis), the colour of points is varying from Blue to Orange/Yellow. I want to set the colour of all these Z points as Red. Rest, all the colours of X and Y points remain same
scatter(x, y, a, c) takes arguments x and y, and then a for size, and c for colour. a can either be a single scalar, or a vector with a size for each (x,y) point. c can be an RGB triplet, or a vector, the same size as x and y. For example:
x = 1:4;
scatter(x, x, 10*x, x);
results in
scatter3(x,y,z,s,c) is similar, so in your case, perhaps
scatter3(X,Y,Z,[],Z)
will result in your data having a different colour determined by its z value.
One little example which I think is what you're looking for:
X = rand(100,1);
Y = rand(100,1);
Z = rand(100,1);
scatter3(X,Y,Z,[],Z)
Produces:
I got the answer by trying different MATLAB functions.
I used the gscatter function. As I had to colour all the Z points(consider 'Z' array as the 3rd data set) as Red and rest X and Y data set (the other 2 data set) as green or other colour, I used the following code:
group = Z(:,1);
gscatter(X(:,1),Y(:,1),group, 'gr', 'xo');
It creates a 2D plot but serves my purpose.
The Image is made of 3 data sets, but the first 2 data sets are intentionally combined (in Green Cross) and 3rd data set is kept Red, to visualize the relation of 3rd data set with 1st and 2nd data sets combined.
Click here for Image.