How to plot a line between two points in a scatter3 plot in MATLAB?
I am using the following code for producing a scatter3 plot:
X = [1,2,3,1,2,3,1,2,3,1,2,3,1,2,3]; Y = [0,0,0,20,20,20,40,40,40,60,60,60,80,80,80,]; Z1 = [10,-48.7863,-73.3457, -68.3091, -142.0666,... 12, -35.7863, -23.347, -29.3091,-141.0660,... 13,3.2137,-10.3457,-33.3091,-128.0666] Z2 = [2,8.2137,-2.3457, 46.6909, 12.9334,... 10,11.2137, 19.6543,35.6909, 45.9334,... -1,16.2137,37.6543,50.6909,34.9334] figure;scatter3(X,Y,Z1,'filled'); hold on; scatter3(X,Y,Z2,'filled')
Which results in the following image:
What I would like to have is a vertical line between each blue and red dot.
I tried using the
line function, however I am not sure how to build up the vector.
line(X,Y,Z1) % will only connect the blue dots line(X,Y,Z2) % will only connect the red dots line(X,Y,Z1:Z2) % will give an error that the vectors must be the same length
See also questions close to this topic
When making surface plot 3D from scattered data matlab
I have some scattered 3D data which I want to make a surface plot.
The scattered data looks like the following.
This is something I got when I made a surface plot using the data(I used the function grid data. See the following code below.)
[xq, yq] = meshgrid(-95:2:190, 20:0.5:170); vq = griddata(XYZ(:,1),XYZ(:,2),XYZ(:,3),xq,yq,'natural'); surf(xq, yq, vq); %XYZ is the 3 column array contains the scattered data
I am not satisfied with the result because I wanted the points with same height to be connected with a line. In other words, the result I expected was more like the picture below.
Especially, at the surface plot (2nd picture) I do not want the wriggling valleys between the peaks. I want the peaks to be smoothly connected at the surface plot too (just like 3rd plot)
So my question is, how can I make the surface plot like the 3rd picture? Thanks.
align axes in one figure
I have a figure with two different axes.
I cannot manage to get the axes aligned and to make the second axis invisible... I tried a couple if things (see comments in the code), but they did not work
clearvars close all clc [X1,Y1,Z1] = peaks(25); [X2,Y2,Z2] = peaks(25); idx = find(X2>0); Z2(idx) = NaN; figure set(gcf, 'Position', [0 0 800 800]) %%title title('') %%Create two axes ax1 = axes; pcolor(X1,Y1, Z1); shading flat view(2) ax2 = axes; pcolor(X2,Y2, Z2); shading flat %%link them linkaxes([ax1,ax2]) %<==it didn't work %ax1.XLim=[-3 3]; %<==I also tried this %ax2.XLim=[-3 3]; %ax1.YLim=[-3 3]; %ax2.YLim=[-3 3]; %%Hide top axes ax2.Visible = 'off'; %<== I thought that this would work ax2.XTick = ; ax2.YTick = ; %%Colormaps colormap(ax1, bone) colormap(ax2, jet(26)) %%Add colorbars set([ax1,ax2],'Position',[.17 .11 .685 .815]); cb1 = colorbar(ax1,'position',[.08 .11 .03 .815]); set(get(cb1,'ylabel'),'String','whatever','interpreter','latex', 'fontsize',20); cb2 = colorbar(ax2,'position',[.92 .11 .03 .815]); set(get(cb2,'ylabel'),'String','whatever','interpreter','latex', 'fontsize',20); caxis(ax1,[-7 7]) caxis(ax2,[-5 5]) xlabel(ax1,'stuff') ylabel(ax1,'other stuff')
Note: I am using 2017a
Three variables: conditional formatting to find highest and lowest values
I have a list of genes (from single cell sequencing data) in excel format. Each gene attribute can be defined by three variables (fold change, pct1, pct2). I would like to find the top candidate genes that fulfill the following condition:
- highest possible value in fold change
- highest possible value in pct1
- lowest possible value in pct2
Highest and lowest could be > or < 2 Std.deviations from the mean. I seek an R or Matlab solution because the number of gene entries and number of files are too large for excel to handle.
How can I create a plot of eigenvalues in R?
I need to create a plot in R of the following eigenvalues: 2.2928, 0.401, 0.1322, 0.0594, 0.0406, 0.0288, 0.025 at Principal Components 1-7. I used the following dataset:
Chu_data = as.matrix(read.table(file="http://epiphanet.uth.tmc.edu/preds/f11/Chu_data.csv", sep = ",")) library(matrixStats)
and transformed it with the following command:
Chu_data2 = Chu_data * -1
I have already done the following commands:
colMeans(Chu_data2) ## V1 V2 V3 V4 V5 V6 ## -0.11900458 -0.21401111 -0.09612128 -0.11873978 -0.00745832 -0.03254005 ## V7 ## -0.02472377 colMedians(Chu_data2) ##  -0.12 -0.18 -0.10 -0.17 -0.10 -0.10 -0.13 colVars(Chu_data2) ##  0.02940187 0.36919574 0.26928803 0.42775589 0.73665904 0.55204203 ##  0.59568623 pc = prcomp(Chu_data2) summary(pc) ## Importance of components: ## PC1 PC2 PC3 PC4 PC5 PC6 ## Standard deviation 1.5143 0.6333 0.36356 0.24374 0.20140 0.16983 ## Proportion of Variance 0.7694 0.1346 0.04435 0.01994 0.01361 0.00968 ## Cumulative Proportion 0.7694 0.9040 0.94837 0.96831 0.98192 0.99160 ## PC7 ## Standard deviation 0.1582 ## Proportion of Variance 0.0084 ## Cumulative Proportion 1.0000 eigenvals <- pc$sdev^2 eigenvals ##  2.29299111 0.40101764 0.13217381 0.05940873 0.04056253 0.02884208  0.02503294
And I created the following covariance matrix:
> M3 = t(Chu_data2) %*% Chu_data2 > M3 V1 V2 V3 V4 V5 V6 V7 V1 266.4949 167.9723 66.944 35.6704 -87.9778 -24.5144 4.2718 V2 167.9723 2538.5794 1501.269 1311.2387 1415.1033 1005.0506 954.0424 V3 66.9440 1501.2686 1703.761 1595.5595 1703.0130 1235.2951 1120.9957 V4 35.6704 1311.2387 1595.560 2702.8413 3097.8469 2448.1094 2349.3759 V5 -87.9778 1415.1033 1703.013 3097.8469 4506.4837 3637.6371 3541.8690 V6 -24.5144 1005.0506 1235.295 2448.1094 3637.6371 3383.3192 3236.6570 V7 4.2718 954.0424 1120.996 2349.3759 3541.8690 3236.6570 3647.5524 > M4 = M3 / 6117 > M4 V1 V2 V3 V4 V5 V6 V1 0.0435662743 0.02745991 0.01094393 0.005831355 -0.01438251 -0.004007585 V2 0.0274599150 0.41500399 0.24542563 0.214359768 0.23133943 0.164304496 V3 0.0109439268 0.24542563 0.27852884 0.260840199 0.27840657 0.201944597 V4 0.0058313552 0.21435977 0.26084020 0.441857332 0.50643239 0.400214059 V5 -0.0143825078 0.23133943 0.27840657 0.506432385 0.73671468 0.594676655 V6 -0.0040075854 0.16430450 0.20194460 0.400214059 0.59467666 0.553101063 V7 0.0006983489 0.15596573 0.18325906 0.384073222 0.57902060 0.529124898 V7 V1 0.0006983489 V2 0.1559657348 V3 0.1832590649 V4 0.3840732222 V5 0.5790205983 V6 0.5291248978 V7 0.5962975969
I need to recreate the graph that I have attached by using the following code: Plot of eigenvalues
x = as.vector(M2) y = .72263 / 0.69123 * x plot(M2, type = "p", col = "orange") lines(x,y, type = "l", col = "red", new = "F")
I am very confused and have tried the following codes, but they do not give me the same graph as shown in the image:
x = as.vector(Chu_data2) y = .00072 / .22153 / .24098 / .40163 / .54893 / .46412 / .46350 * x plot(Chu_data2, type = "p", col = "black") lines(x,y,type = "l", col = "black", new = "F") x = as.vector(M4) y = .00072 / .22153 / .24098 / .40163 / .54893 / .46412 / .46350 * x plot(M4, type = "p", col = "black") lines(x,y,type = "l", col = "black", new = "F")
I would appreciate any help; once again this is a plot of the eigenvalues shown in this table principal components
Thank you in advance!
Plot and save Wavelet (Biwavelet) 300 dpi image resolution
I am working with Biwavelet package to Wavelet analysis. After generating the wavelet transform, I should plot a common 2D spectogram, as in help of the package, for example with
plot(w, useRaster = TRUE). The point is that I need a 300dpi image, and I have dificult to do this, since the plot is giving to me a 96dpi image as default. I also need to save it in my computer, what I didn't get.
I put an example of a "signal", its wavelet transform "w" and how I got its plottage, what works, but no with the resolution I need:
signal.len <- 1024 # input param. sin.freq <- 40 # input param. # noise + 40 Hz sine wave signal <- rnorm(signal.len) + sin(sin.freq*2*pi/signal.len * 1:signal.len) library(biwavelet) w <- wt(cbind(index(signal), signal)) # continuous wavelet transform # rendering the results par(mfrow=c(2,1)) plot.default(signal, type = "l", xaxs = "i") # the signal plot(w, useRaster = TRUE) # spectrum of the signal
I was thinking about using something as "plot(w, res = 300)", but it didn't work. I also though about using ggplot that exports with 300dpi resolution using "ggsave", but I did not know how, and if it's possible.
To save the image I was trying with no sucess:
png(filename = "WT.png", width = 600, height = 671, res = 300)
So, does anyone help me?
how to figure out why there are two group in my plot
I have an Integer vector with approx. 18000 observations. At first it was a list, but when trying to use some plot function I got some errors, so I changed it into a integer vector as so:
data <- read.csv("gumdrops.csv") head(data)
X01 X02 X03 X04 X05 X06 0 0 1 0 0 2
Named int [1:18828] 0 0 1 0 0 2 3 0 0 0 ... - attr(*, "names")= chr [1:18828] "X01" "X02" "X03" "X04" ...
summary(data) data_new <- unlist(data) plot(data_new)
output for the last line of code above:
I am new to Data Analysis, and I see there are so two different clusters in the graph. But I do not know what to make of it or why there are two clusters.
Any ideas? Or any advice as to how to understand the graph better?
ORA-06550: line 1, column 7: PLS-00306: wrong number or types of arguments in call to
when call a parameter show this error what is the issue i dont understand.i am new user :-(
CREATE OR REPLACE PROCEDURE cust_order_sample ( order_po_num IN Number, sale_order_num OUT Number ) As BEGIN select CONTROLLING_MANAGER INTO sale_order_num from FND_CONC_REQ_SUMMARY_V WHERE ARGUMENT_TEXT=order_po_num; END cust_order_sample;
and when i run this procudure show this error
execute cust_order_sample(28685); show this error ORA-06550: line 1, column 7: PLS-00306: wrong number or types of arguments in call to 'CUST_ORDER_SAMPLE' ORA-06550: line 1, column 7: PL/SQL: Statement ignored
LIne chart - line color based on line direction
Is there any possibility how to make a line color dependent on it's direction in line chart? I would like to have a line chart with one color for parts where the chart is ascending and a different color for the line when it is descending. I think that I have seen some example somewhere, but now I really cannot find it.
Extracting a line after a specific line in python
I have this problem, am trying to extract two lines A and B. But i will extract those line if B comes after A, other wise, i want to pass. Initially, i thought they were equal amount to i used the code, below. It's actually part of a larger code, but this is where is issue is mainly.
def get_line(file_name, find_word1, find_word2): lines =  for line in file_name.strip().split('\n'): if find_word1 in line: lines.append(line) elif find_word2 in line: lines.append(line) else: pass return lines
B. from my code, i know i can only get two line but not condition . I don't know how to go about this. if you can help, please kindly do Thank you
Ruby AXLSX ScatterChart titles
I can see within the ScatterChart method, there are 2 variables, x_val_axis and y_val_axis. When executed, my graph title is always on the X-axis, whether or not I used x_val_axis or not. Is it not possible to change the y-axis title AND the x-axis title on the same chart?
My code snippet is below:
@dbChart.y_val_axis.title = "RT" @dbChart.x_val_axis.title = "IOPS"
Pandas scatter plot by category and point size
So I had the idea to using a single Pandas plot to show two different datum, one in Y axis and the other as the point size, but I wanted to categorize them, i.e., the X axis is not a numerical value but some categories. I'll start by illustrating my two example dataframes:
earnings: DayOfWeek Hotel Bar Pool 0 Sunday 41 32 15 1 Monday 45 38 24 2 Tuesday 42 32 27 3 Wednesday 45 37 23 4 Thursday 47 34 26 5 Friday 43 30 19 6 Saturday 48 30 28
tips: DayOfWeek Hotel Bar Pool 0 Sunday 7 8 6 1 Monday 9 7 5 2 Tuesday 5 4 1 3 Wednesday 8 6 7 4 Thursday 4 5 10 5 Friday 3 1 1 6 Saturday 10 2 6
Earnings is the total earnings in the hotel, the bar and the pool, and tips is the average tip value in the same locations. I'll post my code as an answer, please fell free to improve/update.
See also: Customizing Plot Legends
How to fill area between a scatter plot
I'm trying to fill the area between a scatter plot with one shaded area. So it would contain all the scatter points in one shaded area. The code below provides a polygon between each x,y coordinate (see image). How do I alter the code to provide one area filled between the outer scatter points?
fig, ax = plt.subplots(figsize = (8,6)) x = [45.10031842, -5.039210065, -3.516560206, 41.79799446, -24.6161481, -22.98303729, -3.640677541, 3.51273869, 28.44337707, 11.06472095, -35.54419066, -4.37055025, 45.73116662, 29.26475119, -40.68655635, 6.110571001, -3.189147979, -45.11483157, 3.001018117, -1.052283362, 38.61536724] y = [65.74835477, -2.22955167, 73.73594438, 61.90991549, 67.06663915, 77.13941436, -2.107068269, 93.94853726, 56.51826591, 70.2095591, 73.07962202, -2.086428541, 69.78626105, 73.34402753, 64.72901307, 70.90387539, -3.165213755, 70.94140139, 42.78164288, 61.77394225, 72.07455255] SCN = ax.scatter(X,Y) SCN = ax.fill_between(X,Y) plt.show()
R: scatter3D plot with errorbars produces error in plotdev()
I produce 3D scatter plots using R's
plot3Dpackage. I draw a scatter plot with defined errorbars. Here's a toy example
library("plot3D") aax=c(1,2,3,4,5) aay<-c(2,3,4,5,6) aaCI<-list(z=matrix(nrow=length(aax),data=c(rep(0,length(aax)),rep(-6000,length(aax)) ))) scatter3D(aax,aay,rep(-5000,length(aax)),phi = 0, bty = "g", pch = 20, ticktype="detailed",colkey=FALSE,add=FALSE,nticks=3,CI=aaCI, zlim=c(-11000,-5000))
Everything is OK, but next I want to use the
plotdev()directive from plot3D package to limit the drawing area and to avoid plotting objects, which are beyond the coordinate data. However, setting any xlim, ylim, zlim limitations produces an error, if scatter3D is invoked with errorbars:
plotdev(xlim=c(0,6) ) Error in if (CIpt$dopoints) points(CI.mid$x[io], CI.mid$y[io], col = CIpt$col[io], : argument is of length zero
For all other plots, including scatterplots without error bars, and combination thereof, such subsetting with
Plotting spheres around given coordinates in 3D in Matlab
I am working on model of an object sliding on some rough surface consisting of spheres with a small random variance in position. In the graphics I want the spheres to be of a given radius, however when using scatter3 this wont work, the sizes of the circles change when I zoom in or out. I could easily solve this in 2D by using "rectangle"-function instead but for 3D this doesn't work.
Is there a better function for plotting spheres around points?
I have read this https://se.mathworks.com/matlabcentral/answers/101738-how-do-i-specify-the-size-of-the-markers-created-by-the-scatter-plot-in-units-proportional-to-the-da. But it either doesn't work for scatter3 or I do it wrong.
Sizes change when zooming in.
fig = figure(1); hold on daspect([1,1,1]); surface.xnum = 16; surface.znum = 16; surface.r = 1; circlenumber = 0; for n = 1:surface.xnum for m = 1:surface.znum circlenumber = circlenumber + 1; surface.circlecentre(circlenumber,:) = [n + 0.1*surface.r*randn , 0, m + 0.1*surface.r*randn ]; plt.surface = scatter3(surface.circlecentre(circlenumber, 1),surface.circlecentre(circlenumber, 2),surface.circlecentre(circlenumber, 3), 850*surface.r,'filled','r','MarkerEdgeColor','k'); end end
Relevant part of the code. Setting coordinates to center of the spheres and plotting spheres around them.
How to edit the legend of a scatter plot?
I made a plot with legend. By this code:
scatter3d(x = red, y = green, z = blue, groups = C1class$V1, surface. col = 1:21, grid = FALSE, surface = FALSE) legend3d("right", legend = levels(C1class$V1), col = rainbow(21), pch = 16, inset = -0.25, xpd = TRUE)
But my graph looks like this:
How can I edit it to look better?
Can you help me with some function to fix it?
Thanks for you help.