translate matlab plot to gnuplot 3d - matlab

I have a matrix of fft data over time, 8192 rows of data x 600 columns of time. The first column is a frequency label, the first row is shown below but doesn't actually exist in the data file, neither do the spaces, they are shown just for ease of reading.
Frequency, Sec1, Sec2, Sec3...Sec600
1e8, -95, -90, -92
1.1e8, -100, -101, -103
...
It is plotted in matlab with the following code (Apologies to other posters, I grabbed the wrong matlab code)
x is a matrix of 8192 rows by 600 columns, f is an array of frequency labels, FrameLength = 1, figN = 3
function [] = TimeFreq(x,f,FrameLength,figN)
[t,fftSize] = size(x);
t = (1:1:t) * FrameLength;
figure(figN);
mesh(f,t,x)
xlabel('Frequency, Hz')
ylabel('time, sec')
zlabel('Power, dBm')
title('Time-Freq Representation')
I cant quite figure out how to make it work in gnuplot. Here is a sample image of what it looks like in Matlab: http://imagebin.org/253633

To make this work in gnuplot, you'll want to take a look at the splot (for "surface plot") command. You can probably figure out quite a lot about it just by running the following commands in your terminal:
$ gnuplot
gnuplot> help splot
Specifically, you want to read the help page shown by running (after the above, when the prompt asks for a subtopic): datafile. That should tell you enough to get you started.
Also, the answers to this question might be helpful.

so here is the gnuplot command script that I ended up using. It has some additional elements in it that weren't in the original matlab plot but all the essentials are there.
set term png size 1900,1080
set datafile separator ","
set pm3d
# reverse our records so that time moves away from our perspective of the chart
set xrange[*:*] reverse
# hide parts of the chart that would make the 3d view look funny
set hidden3d
# slightly roate our perspective and compress the z axis
set view 45,75,,0.85
set palette defined (-120 "yellow", -70 "red", -30 "blue")
set grid x y z
set xlabel "time (secs)"
set ylabel "frequency"
set zlabel "dBm"
# plot all the data
set output waterfall.png
splot 'waterfall.csv' nonuniform matrix using 1:2:3 with pm3d lc palette

Related

Line increment in gnuplot

I have large files (~5 Gbs) whit constant increment on x-axis, let's say each dt.
I would like to know if I could set the every command of Gnuplot as logarithmic increment not linear.
plot "fileA.txt" u 1:2 every dt #linear increment of dt
This is because, if x-axis is in log-scale, then I want to have more points for low values of x in (10^-4,10^-2) but also not an oversampling in (10^4,10^2) range. Somehow a differential increment.
Does I have to use external programs like sed to re-write my file first?
A test plot is included as well as the data. In blue the full data, in red the ones with the every command. As you can see one loose the information for short x also oversample the plot for large x. the data file
Many thanks.
You could plot smoothed data with points:
set key left
set logscale x
set yrange [3.9:4.8]
set samples 30
set terminal png
set output "log.png"
plot "fort.11" title "raw" with points lc 3 pointtype 5 pointsize 2,\
"" title "smooth" smooth csplines with points lc 1 pointtype 5 pointsize 1
set samples 30 tells gnuplot to use 30 points equidistant in x
smooth csplines interpolates the datapoints
with points plots with points instead of lines, which would be the default
Note that this does not plot the original data, and that smooth csplines introduces new points if the original datapoints are too far apart. This might or might not be what you want.

Scatter plot with different size for each point

I have several thousands of points to plot (about 10k) and I would like to plot them with Matlab but deciding a diferent size for each of the points (and a different color if possible). I tried to make a scatter plot for each point, but it is extremely slow compared to a single scatter call for all the points. Is there a way to plot several points in Matlab with different properties for each point, that works in a reasonable amount of time?
In case it is not possible to do it with Matlab, is there a way to do it with gnuplot?
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
So in your case, perhaps
scatter(xData, yData, [], 1:10000)
will result in your data having a different colour determined by its position in the data array.
For gnuplot it's easy, suppose you write your datafile with 3 columns, all you have to do is
plot 'data.dat' u 1:2:3:3 with circles lc palette
HERE you can find some examples (for help type help circles).
If you want just what is called variable pointsize (pointsize is not related to the real axis) you can use:
plot 'data.dat' with points ps variable pt 7
HERE you can find some examples (for help type help pointsize).
For gnuplot you can combine pointsize variable and linecolor variable or linecolor palette:
set xrange [0:10]
set samples 21
plot '+' using 1:1:(0.2*$1):1 with point pointsize variable linecolor palette pt 7 notitle

plotting a text file with 4 columns in matlab

I want to plot a text file with 4 columns that first column in longitude,second in latitude, third is depth and forth is amount of displacement in each point.(it's related to a fualt)
-114.903874 41.207504 1.446784 2.323745
I want a plot to show the amount of displacement in each point (like images that we plot with imagesc),unfortunately "imagesc" command doesn't work for it.
how can I plot it?
Thanks for your attention
A simple way would be to use scatter3 and assign your displacements to be the colours. Note that you have to supply a size for this to work - I'm using [] (empty matrix) which will set it to default. If your four sets of values are four vectors of the same size, then it's just something like:
scatter3(lat,lon,depth,[],displacement, 'filled')
Values in displacement will be linearly mapped to the current colormap. 'filled' gives you filled markers rather than open ones (default marker is a circle but can be changed).
You can plot each point using plot3(longitude,latitude,depth). You can color each point according to the displacement in a for loop. The easiest way to do this is create a colormap, e.g. using jet and chosing the color according to the displacement.
figure;
hold on;
cmap = jet(256);
dispRange = [min(displacement),max(displacement)];
for k=1:size(longitude,2)
c = cmap(1+round(size(cmap,1)*(displacement(k)-dispRange(1))/dispRange(2)),:);
plot3(longitude(k),latitude(k),depth(k),'o', ...
'MarkerEdgeColor',c,'MarkerFaceColor',c);
end

change yTicklabel in matlab plot

I want to draw a plot that displays y tick labels are similar to the below image. How can I do that?
thanks for your attentions
The y axis is setup as logarithmic.
you can create plots similar to this using
semilogy(xData,yData)
If you wanted the plot to look the same, you would of course need to use the semilogy to plot the data and then also add x and y axis labels using something like the following
xlabel('Fitness Evaluations');
ylabel('Error');
If you truly want to only show the powers of 10 on the y axis, meaning the power number, you can do something like as follows
labels = sort(str2num(get(gca,'YTickLabel')));
set(gca,'YTickLabel',labels);
labels = [' 1 ';'10 '; '100'];
set(gca,'YTickLabel',lbls);
This will set the YtickLabels to 1, 10 and 100. If you want LaTeX to interpret your ticklabels such that you will see (10⁰,10¹,10²), you can download this file from matlab exchange.
http://www.mathworks.com/matlabcentral/fileexchange/15986

Plotting horizontal lines across histogram bars

I have an experiment where I measured the performance of some algorithms relative to three baselines. I'd therefore like to plot histograms for the algorithms, with horizontal lines of various styles drawn through the histogram bars to show the baselines.
Below is an example which I produced by manually drawing horizontal lines on a graph produced by Gnuplot. The histograms "sentence" and "document" represent the algorithms I tested, and "mono", "random", and "MFS" are the baselines.
Is there some way I can do this within Gnuplot itself? If not, can anyone recommend another tool which can do this? Or perhaps there's a better visualization technique I should be using instead?
This is definitely possible. Here's a little example that I cooked up:
First, the datafile "data.dat":
#histograms
1 3 stack1
2 2 stack2
3 1 stack3
#mono
.6
.6
1.5
1.5
3.1
3.1
Now the gnuplot script to plot it:
set yrange [0:*]
set style data histograms
set style histogram cluster gap 1
IDX=-1
xpos(x)=(IDX=IDX+1, IDX%2==0)?(IDX/2-.5):(IDX/2+.5)
set style fill solid
plot 'data.dat' index "histograms" u 1:xtic(3) title "column1", \
'' index "histograms" u 2 title "column2", \
'' index "mono" u (xpos($1)):1 w lines ls -1 title "mono"
This is a little more tricky than my last version. When plotting a cluster of histograms, each cluster is centered on an integer starting at 0 and incrementing by 1 for each cluster (regardless of your setting for xtics and labels). What I've done is used that information to simplify the datafile. Now this plot command plots 2 different data sets as histograms (taken from each column in the "histogram" portion of the datafile), the first one adds the xtic labels. Then the tricky part: I write a function which has side-effects (gnuplot inline-functions are new in gnuplot 4.4 I think). Each time it is called, the value for the variable IDX is incremented -- So, the current position on the xrange is always IDX/2. This function alternates between returning IDX/2-.5 and IDX/2+.5. Note that to create another dataset random, you'll need another function xpos2 which is the same as xpos1 except it uses a separate iterator.