Smooth Surface Plotting of a discrete data file using gnuplot - random

I have a file with three columns. All three have different values. To plot it in a
smooth surface with a color gradient for third column what should I do? First two columns are pseudo randomly distributed. And so do the final column.
The data file looks like this:
8.4295190 0.3860565 0.3706621
-2.9886350 -0.1156874 -0.1314160
8.4375611 0.2617630 0.3710158
8.4092863 0.3195774 0.3697725
8.4237288 0.3930579 0.3704075
-1.1439280 -0.7286996 -0.0919299
-1.0866221 -0.9426172 -0.0873246
-0.9633012 -0.8667140 -0.0774141
-0.8225506 -0.6229306 -0.0661029
-0.9931836 -0.6562048 -0.0798155
-1.3138121 -0.8559578 -0.1055823
-0.8687813 -0.7689202 -0.0698182
7.3637155 1.8145656 0.1891778
7.4434600 1.9952866 0.1912265
7.5885025 1.8936264 0.1949527
7.3067197 1.8313323 0.1877136
7.5324886 2.0066328 0.1935137

You could use dgrid3d to turn your points into grid data:
set dgrid3d 32,32
set xyplane at 0
splot 'data' with pm3d
This creates a grid with 32 rows and 32 columns from your data.
You can increase the number of grid points to get a smoother surface and you may also want to use set pm3d interpolate 0,0, which means that the optimal smoothing is applied to the surface.

Related

How to set the elevations of sea to a common negative value in GMT6.1?

I want to draw a relief of some region (sea and land involved), but I DO NOT want to show the variation of marine bathymetry, so I must set them to a common negative value to make sure that all the bathymetry map to the same color, like lightblue. I don't know how to do it?
That's easy using grdclip. When using command line GMT you can try:
gmt grdclip grid -Ggrid_clipped -Sb0/-1000 -V
which sets all values of your input grid grid< 0 to -1000 (adjust the values for your needs) and writes the clipped grid to outfile grid_clipped.
If you're using PyGMT you can try:
import pygmt
grid = pygmt.grdclip(grid, below = [0, -1000])
where you can directly hand the clipped grid to another PyGMT function for plotting like
fig.grdimage(grid = grid).

matlab: texture classification

I have a histology image like this:
From the image, we can observe there are two kinds of different cells.
and
Is there any way that I can separate these two types of cells into two groups?
How about using your raw image and previous code to achieve this?
% % % your old code
I=imread(file);
t1=graythresh(I);
k1=im2bw(I,t1);
k1=~k1;
se = strel('disk',1);
k0=imfill(~k1,'holes');
cc = conncomp(k0);
k0(cc.PixelIdxList{1})=0;
k1=imfill(k1,'holes');
mask=k0 | k1;
%%%%%%%%%%%%%%%%%%
This will give you:
I=rgb2hsv(I);
I=double(I);
I1=I(:,:,1); % again, the channel that can maximizing the margin between donut and full circle
Imask=(I1-0.2).*(I1-0.9)<0;
k2=mask-Imask;
k2=bwareaopen(k2,100);
This will give you:
k2=mask-Imask;
I2=zeros(size(I1,1),size(I1,2),3);
I2(:,:,1)=(k2==1)*255;
I2(:,:,3)=((I1-0.2).*(I1-0.9)<0)*255;
imshow(I2)
will finally give you (the two types are stored in two channels in the rgb image):
I would use regionprops
props=regionprops(YourBinaryImage, 'Solidity');
The objects with a high solidity will be the disks, those with a lower solidity will be the circles.
(Edit) More formally:
I=imread('yourimage.jpg');
Bw=~im2bw(I, 0.5);
BWnobord = imclearborder(Bw, 4); % clears the partial objects
Props=regionprops(BWnobord, 'All');
solidity=cell2mat({Props.Solidity});
Images={Props.Image};
Access the elements of Images where the value in solidity is higher than 0.9 and you get your disks. The circles are the other ones.
Hope it helps

Cubism.js / d3.js Scale and Extent

Can someone provide some insight on how scales and extents work together in cubism.js
.call(context.horizon()
.extent([-100, 100])
.scale(d3.scale.linear().domain([-10,10]).range([-100,100])
)
);
For example what does the code above do? If the values are generated using a random number generator (numbers between -10 and 10)
I know extent is used to set the maximum and minimum.
I know how to define a scale, example:
var scale = d3.scale.threshold().domain([100]).range([0,100])
console.log(scale(1)) // returns 0
console.log(scale(99.9)) // returns 0
console.log(scale(88.9)) // returns 0
console.log(scale(100)) // returns 100
I read about d3.scales here http://alignedleft.com/tutorials/d3/scales/
My main issue is that I want to define thresholds for my data, very simple
0-98 Red
98-100 Pink
100 Blue
Or maybe just
0-99.99 Red
100 Blue
But I'm not being able to use all what I've read to construct something that works.
I'm guessing that you just want to use a different color to represent anomalies in your data. If that is true, you don't need to create a domain and range.
You can just create a custom color palette like this:
var custom_colors = ['#ef3b2c', '#084594', '#2171b5', '#4292c6', '#6baed6', '#9ecae1', '#c6dbef', '#deebf7', '#f7fbff', '#f7fcf5', '#e5f5e0', '#c7e9c0', '#a1d99b', '#74c476', '#41ab5d', '#238b45', '#006d2c', '#00441b'];
This color palette was constructed using the palette on this page with an extra red color tacked on to the end.
Then just call the custom colors like this:
d3.select("#testdiv")
.selectAll(".horizon")
...
.call(context.horizon()
.colors(custom_colors)
));
Play around with the colors until you find a combination that you like. In this above example, only the outlier will be in red while the rest will follow the blue and green pattern.
Hope this helps!

adjusting row height in R image() function

I'm drawing several heatmaps using the image() function in R.
The sizes of the heatmaps are quite variable, so every heatmap has a different height, however I want the row heights be uniform across heatmaps.
So I create heatmaps from these two matrices, and the heights of each cell are different between two heatmaps:
m1<-replicate(40, rnorm(20))
image(1:ncol(m1), 1:nrow(m1), t(m1), axes = FALSE,xlab="",ylab="")
m2<-replicate(40, rnorm(10))
image(1:ncol(m2), 1:nrow(m2), t(m2), axes = FALSE,xlab="",ylab="")
For the life of me, I can't figure out how can I specify the row height. It must be a very easy fix, but I can't figure it out.
You give very limited information. E.g., do you want to create PDFs? Or place several plots on one page?
Here is one solution:
par(fin=c(5,5),mar=c(0,0,0,0))
image(1:ncol(m1), 1:nrow(m1), t(m1), axes = FALSE,xlab="",ylab="")
par(fin=c(5,2.5),mar=c(0,0,0,0))
image(1:ncol(m2), 1:nrow(m2), t(m2), axes = FALSE,xlab="",ylab="")
I am sure there are more elegant solutions depending on what you actually want to do with the graphs.
Just set a common maximum number of rows for all the heatmaps using the ylim parameter:
m1<-replicate(40, rnorm(20))
m2<-replicate(40, rnorm(10))
image(1:ncol(m1), 1:nrow(m1), t(m1), axes=FALSE, ann=FALSE, ylim=c(0, max(sapply(list(m1,m2),nrow)) ))
image(1:ncol(m2), 1:nrow(m2), t(m2), axes=FALSE, ann=FALSE, ylim=c(0, max(sapply(list(m1,m2),nrow)) ))
You may want to manually specify the ylim argument and have that be the same between the 2 plots:
par(mfrow=c(1,2))
image( 0:ncol(m1), 0:nrow(m1), t(m1), axes=FALSE, xlab='', ylab='',
ylim=c(0,nrow(m1)) )
image( 0:ncol(m2), 0:nrow(m2), t(m2), axes=FALSE, xlab='', ylab='',
ylim=c(0,nrow(m1)) )

Viewing Part of a figure

I made a simulation of 10000 times and want to view part of simulation between 5000-5200. I am able to view it with the code below, but the x-axis says 0-250. I want the x-axis to display the exact figure of 5000-5200. Also there seems to be a small gap at the end of the figure as the axis runs up to 250 for some reason. I just want to view the figure in for this set time with the x-axis showing the exact labels and without the gap at the end.
Thanks
N=10000;%Number of simulation
P=0.02;
Q = zeros(N,1); %current value of queue
X=zeros(N,1);%simulation data
Ci=0;
L=0.9;
Bu=zeros(N,1);
Bs=30;
Bd1=50;
Bd2=270;
Ti=0;
for Ti=2:N
U=rand(1);
a=log10(U);
b=log10(1-P);
c=(a/b);
d=1+c;
X(Ti)=round(d);
Ci=Ci+1;
if X(Ti)< (L)*(Bs)
Bu(Ti)=Bs;
else if X(Ti) < (L)*(Bs+Bd1)
Bu(Ti)=Bs+Bd1;
else
Bu(Ti)=Bs+Bd1+Bd2;
end
end
Ti=Ti+1;
end
plot(X(5000:5200,1),'r');
set (gca,'ylim',[0 400]);
hold on;
plot(Bu(5000:5200,1),'b');
set (gca,'ylim',[0 400]);
hold off
Plot expects two inputs, the first depicting the horizontal axis and the second depicting the vertical axis. When you do not supply two inputs, then it computes the length of the single input (in this case that length is 5200-5000 = 200), and it just uses 1 through that length (1:200 in this case) as if it is the values for the horizontal axis variable.
I think you want to issue the command:
plot(5000:5200, X(5000:5200,1), 'r')
Often Matlab will adjust plot axes for better default views, so it's probably showing the axis out to the index 250 just by virtue of some default plotting convention. You can similarly use set(gca, 'xlim', [5000 5200]) if you wish.

Resources