As I said I have 2D matrix 68 per 68 and I want to make a heat map from it.
Each value in the matrix should be displayed as a separate cell. Every fourth cell should be labelled as "XXX\n715" 0, "XXX\n718" 3 and so on...
This is my plot: https://www.dropbox.com/s/tiipsn5mhmbnb5b/TEST.png?dl=0
Data used to produce this plot can be found here: https://www.dropbox.com/s/izrfbm157q1tedj/matrix.dat?dl=0
At present, I can see two problems with my plot:
1.) Cells are too small. Therefore, the plot is hard to read.
I want to increase size of a cell 2 times.
If I understand correctly, each pixel corresponds to one value?
If so, I would like to increase size of a pixel. That's way I was thinking
about drawing a grid size of 68*2/68*2, so that each value in my matrix will
be displayed in a 2-pixel/2-pixel-square box (cell).
2.) Values are outside cells's borders.
I had the same problem with smaller 2D arrays and I fixed it by trying
different resolutions (terminal size). I have been trying to apply a discussed
solution for the 68x68 matrix, but it did not work for me.
I tested many different scripts and I am stuck on these problems.
Thank you.
Code below:
set terminal png transparent truecolor nocrop enhanced size 800,800 font
"arial bold,8”
set output 'TEST.png'
set size ratio 1
set palette rgbformulae -21,-22,-23
# drawing grid
set x2tics 1 format '' scale 0,0.001
set y2tics 1 format '' scale 0,0.001
set mx2tics 2
set my2tics 2
# labels
set xtics 3 out nomirror
set ytics 3 out nomirror
set grid front mx2tics my2tics lw 0.5 lt 1 lc rgb 'black'
set xrange[-0.5:67.5]
set yrange[-0.5:67.5]
set x2range[-0.5:67.5]
set y2range[-0.5:67.5]
set xtics add ("XXX\n715" 0, "XXX\n718" 3)
set ytics add ("XXX\n715" 0, "XXX\n718" 3)
plot "matrix.dat" matrix w image noti
Related
I have the next plot of a KDE density plot of a dataset in file AAFPStable.dat which has 5 columns.
I only want to use the first for the plot.
set encoding iso_8859_1
set key right top font "Helvetica,17"
set ylabel "Density" font "Helvetica,18"
set xlabel "Minutes" font "Helvetica,18"
set xtics font "Helvetica,16"
set ytics font "Helvetica,16"
set title "Event 1" font "Helvetica, 18"
set size 1, 1.2
set terminal postscript eps enhanced
set grid
set key spacing 1.5
set key box linestyle 1 width 3
lfps = system("cat AAFPStable.dat | wc -l")
set output "event1-gnu.eps"
plot [0:150][] "AAFPStable.dat" using 1:(1) smooth kdensity bandwidth 2.5 lw 2 title "FPS"
The problem is that now the figure shows de KDE density plot but on the y-axis, it shows the number of occurrences. I would like to have the normalized density plot showing probability densities between 0 and 1. The command says that the second column should be 1/(count of points). The value of lfps is the number of rows of the file. I have tasted to change 1:(1) by 1:(1/lfps) but it does not work. I would not like to generate an intermediate file with the first column of AAFPS.dat and add a second with the value of 1/lfps.
How could I indicate gnuplot to plot the normalize KDE density plot?
Thank you for your help
Regards
It works with
plot [0:150][] "AAFPStable.dat" using 1:(1./lfps) smooth kdensity bandwidth 2.5 lw 2 title "FPS"
Thanks
I want to visualize data given at certain timestamps from multiple sources along a timeline. For example, with the follwing to input files with column 1 being the timestamp and column 2 the data:
O1.dat:
100 5
300 10
O2.dat:
200 7
400 3
Along with that the average of all values is sampled at certain intervals:
Avg.dat:
250 6.5
500 6.25
I would like to plot all values in a table-like manner so it looks something like this, with the values aligned to the time on the top:
My real data reaches timestamps of up to 10000, so something dynamic would be nice.
So far I only plotted simple box or line plots, so I'm not sure how to go about this one.
Thanks for your time.
EDIT:
This is what it looks like so far with adjustments made to the accepted answer:
There is still some overlapping, but that is simply because of the data being too close to each other. The script used for this:
#set term pdf
#set term pdf size 8, 5
#set output 'out.pdf'
set term png
set term png size 1200, 700
set output 'out.png'
set termoption font ",20"
set label 'Time (ms)' at graph 0, graph 1 offset -0.75, char 1 right
unset border
unset key
unset xtics
set ytics scale 0
set x2tics () scale 0
set yrange [0:5.5]
set x2range[0:10000]
set lmargin 9
set arrow from graph -0.15, graph 1 to graph 1.1, graph 1 nohead
set arrow from graph -0.01, graph 1.2 to graph -0.01, graph -0.2 nohead
set arrow from graph -0.15, first 0.3 to graph 1.1, first 0.3 nohead
set style data labels
plot for [i=0:9] 'desc'.i.'.txt' using 1:(5-0.5*i):(sprintf('%d', $2)):ytic('Object '.i) axes x2y1, \
'Avg.dat' using 1:(0):(sprintf('%d', $2)):ytic('Avg') axes x2y1
The conventional, simple part is plotting of the actual data. For this you can use the labels plotting style. A very simple example would be:
set xtics (0)
set xrange [0:*]
set offsets graph 0, graph 0.2, graph 0.2, graph 0.2
set style data labels
unset key
plot 'O1.dat' using 1:(5):(gprintf('%g', $2)):ytic('O1'),\
'O2.dat' using 1:(4):(gprintf('%g', $2)):ytic('O2'),\
'Avg.dat' using 1:(3):(gprintf('%g', $2)):ytic('Avg'):xtic(1)
That simply plots the values from your data files as labels at the x-positions given in the first columns. The y-positions are set as fixed numbers:
In order to move the xtick labels to the top and have some table-like lines you need a bit more tweaking:
reset
set termoption font ",20"
set label 'Object' at graph 0, graph 1 offset -1, char 1 right
unset border
unset key
unset xtics
set ytics scale 0
set x2tics () scale 0 format "%g"
set yrange [2:5.5]
set x2range[0:*]
set lmargin 8
set arrow from graph -0.15, graph 1 to graph 1.1, graph 1 nohead
set arrow from graph 0, graph 1.2 to graph 0, graph 0 nohead
set arrow from graph -0.15, first 3.25 to graph 1.1, first 3.25 nohead
set style data labels
plot 'O1.dat' using 1:(5):(sprintf('%d', $2)):ytic('O1') axes x2y1,\
'O2.dat' using 1:(4):(sprintf('%d', $2)):ytic('O2') axes x2y1,\
'Avg.dat' using 1:(2.5):(gprintf('%g', $2)):ytic('Avg'):x2tic(1) axes x2y1
Such a table layout isn't a typical task, so you must adapt several settings to your final result. Main impact comes from canvas size, font and, font size.
If you have more than those two files you could of course also iterate over a file list.
How do I move the vertical grid lines so that they match the horizontal labels/xtics?
In the following image, the vertical grid lines don't line up with the xtics:
I tried setting the xtics offset before setting the grid, but that doesn't seem to work.Here's my current script:
#!/usr/bin/gnuplot -persist
set terminal png nocrop font small size 40000,800
set output 'decode3.png'
set style data linespoints
set title "Raw Audio Chunk"
set xlabel "Count"
set ylabel "Sample Value"
set xtics 16 offset 10
set ytics 10000
set grid
plot "decode3_Samsung_Exhibit.csv"
Thats the wrong way of thinking about this! The offset parameter only shifts the xtics labels (in your case by 10 character widths), but the xtics remain at their original positions. And the grid lines are drawn at the tic positions.
What you probably want is to shift the data a bit to the right. That is done by shifting the actual x-values to the right like
set xtics 16
set grid
plot "decode3_Samsung_Exhibit.csv" using ($1 + 10):2
That assumes, that your data file has two columns. The x-values are shifted by 10 (in units of the x-axis) to the right.
I'd like to take a plot that I have done as a surface in 3D using cartesian coordinates and view it as a heatmap in 2D in POLAR coordinates. The reason for this is I am obtaining data on a system in that coordinate system. I've only found some related examples, but am getting stuck trying to get it to work with my data. I am currently using the matrix format, and I can reformat the data set if this would help get the chart working.
The data is SPL measurements taken on a loudspeaker. The microphone is positioned at a fixed distance away (e.g. fixed radius) and measurements are made at every 10 degrees around the entire loudspeaker horizontally. The SPL measurement is obtained as a function of frequency, 20Hz to 20kHz.
I would like to use gnuplot to create a 2D polar plot. Frequency would be plotted as the radius, the angle around the loudspeaker would be the angle, and the "height" would be the SPL level. This should generate a surface, however, I would like to create a heat map pm3d and then view that from above (e.g. view 0,0) or as a 2D plot. I also need to add contour lines that show intervals of SPL and superimpose that on the heat map.
I found something similar for cartesian coordinates here:
http://gnuplot-tricks.blogspot.com/2009/07/maps-contour-plots-with-labels.html
When I tried this approach using polar coordinates for the final 2D plot, I got an error message that the "with image" option is not supported for polar plots. Can someone try this or confirm this?
I have been able to plot my polar data as a heatmap+contour lines in 3D using splot and view from directly above (set view 0.0). If I first convert my existing polar coordinate data into cartesian coordinates I will probably get something like what is shown in this web page:
how to create a 3d polar graph with gnuplot
I could view this from above, too, but I would like to add in the polar grid and have labels for the angle and radius. Would I have to do this manually or could I use multiplot to overlay a 2D grid and the 3D plot viewed from 0.0?
I am not sure how to approach this. Any advice about what direction to take would be appreciated.
-Charlie
The image plotting works only for equally distributed rectangular grids, just like any bitmap image is arranged. Otherwise you must use splot with pm3d.
The set grid polar works only for 2D, so you must use multiplot to overlay your heatmap with the polar grid. Here a, quite lengthy, example to show you how it might work:
reset
set terminal pngcairo size 800,800
set output '3d-polar.png'
set lmargin at screen 0.05
set rmargin at screen 0.85
set bmargin at screen 0.1
set tmargin at screen 0.9
set pm3d map
unset key
set multiplot
# plot the heatmap
set parametric
set isosamples 500
unset border
unset xtics
unset ytics
set angles degree
r = 6
set urange[0:r] # radius
set vrange[0:360] # angle
set xrange[-r:r]
set yrange[-r:r]
set colorbox user origin 0.9,0.1 size 0.03,0.8
splot u*cos(v), u*sin(v), (cos(v)*besj0(2*u))**2
# now plot the polar grid only
set style line 11 lc rgb 'white' lw 2
set grid polar ls 11
set polar
set rrange[0:r]
unset raxis
set rtics format '' scale 0
unset parametric
set for [i=0:330:30] label at first (r+0.35)*cos(i), first (r+0.35)*sin(i)\
center sprintf('%d', i)
plot NaN w l
unset multiplot
The result is:
And now some details about some tricks:
In order to get a square size, you can't use set size ratio 1, because the margins differ for the 2D and 3D plots, even if you would specify some absolute margins. Therefore, I set a square canvas size (terminal option size 800,800), and set appropriate absolute margins.
You cannot unset rtics because then the grid would disappear.
The grid labels must be set manually.
The colorbox was also set manually because otherwise it would have overlapped with the 0 label.
Plotting NaN does only plot the grid
I took the command file that Christoph posted and played around a bit and managed to get it working for my needs EXCEPT for the labels, which I am still having problems with. The plot is looking like this:
In order to get this result, I had to recalculate the coordinates of my measurement data, changing them from a polar coordinate system (frequency=r, theta=off-axis angle, z=SPL) to a Cartesian one (x,y,z). At the same time I modified the way that the polar grid was presented. Although I wanted a logarithmic polar r-axis, Cartesian coordinates must be used for the pm3d data, so I took the log of the r data before using it to calculate x,y,z coordinates. Also, I knew that the minimum value of the polar log r-axis scale would be 10, and this seems to be set equal to the center of the plot when a logscale polar grid is used. In order for the grid and the surface data to line up properly, I subtracted log10(10) from the r values before using them to calculate the Cartesian coordinates used for the pm3d map. So in total, the equations I used were
r = log10( frequency ) - 1
x = r cos( theta )
y = r sin( theta )
z = SPL
I then used the following command file to plot the data:
reset
set terminal pngcairo size 800,800
set output '3d-polar.png'
set lmargin at screen 0.05
set rmargin at screen 0.85
set bmargin at screen 0.1
set tmargin at screen 0.9
set pm3d map interpolate 20,20
unset key
set multiplot
# plot the heatmap
set cntrparam levels increment 3,-3, -24
set contour surface
set palette rgb 33,13,10 #rainbow (blue-green-yellow-red)
set cbrange [-18:0]
unset border
unset xtics
unset ytics
set angles degree
r = 3.31
set xrange[-r:r]
set yrange[-r:r]
set colorbox user origin 0.9,0.1 size 0.03,0.8
splot 'new_test.dat' using 1:2:3
# now plot the polar grid only
set style line 11 lc rgb 'black' lw 1 lt 0
set grid polar ls 11
set polar
set logscale r 10
set rrange[10:20000]
unset raxis
set rtics format '' scale 0
set rtics (10,20,100,200,1000,2000,10000,20000)
#unset parametric
#set for [i=0:330:30] label at first (r+0.35)*cos(i), first (r+0.35)*sin(i) \
#center sprintf('%d', i)
plot NaN w l
unset multiplot
unset output
The data used to generate the plot only span +/- 30 degrees, so only that sector fills the polar plot. Additional angular data can be used to fill out the plot.
If I can get some help with labels, I can call this "done". I still need to get the labels of angle working. Input on how to label the polar r-axis tics that would be very welcome, too.
I have created a plot made up of four subplots; each subplot is a bar chart. Above the smaller bars I want to print how many units on the y-scale the bar represents. To do this I use 'set label', which works fine if I create individual files for the subplots, but not if I use multiplot. In this case the labels are successively printed on top of each other (i.e. those of the first subfigure also appear in the second, etc.).
Here is a truncated version of my gnuplot script:
set terminal postscript eps size 26cm,16cm font "Helvetica,18"
set out 'all_Figures.eps'
set multiplot
set multiplot layout 2,2
set bars fullwidth
set data style boxes
set boxwidth 0.5
set style fill solid 1.0 border -1
set border 3 front linetype -1 linewidth 1.000
set xtics border in scale 0,0.5 nomirror norotate offset character 0, 0, 0
set ytics border in scale -1,0 nomirror norotate offset character 0, 0, 0
set nogrid
set datafile separator ","
# ** First Plot **
set label "36" at first 2, 130 center
set label "86" at first 3, 160 center
set size .4,.3
plot 'allPDB_perc.csv' using 2:xticlabels(1) notitle
# ** Second Plot **
set size .4,.3
set label "10" at first 3, 236 center
set label "3" at first 4, 236 center
plot 'allPDB_num_dom.csv' using 2:xticlabels(1) notitle
unset multiplot
Is someone able to tell me how to clear the previous subfigure's data labels prior to generation of the current labels? Thanks a lot in advance!
Oh dear >_< I simply had to unset the labels after plotting, like so:
# ** Plot 1 **
set label ...
plot 'datafile.dat'
unset label
# ** Plot 2 **
set label ...