Plotting data vertically with gnuplot - gnuplot

I have a data file with a single column of data. By default, gnuplot renders this on the x-axis from left to right. However, I want to plot this data vertically from top to bottom. How can I do this?
The relevant excerpt from my plot file:
set size 1.0, 1.0
set terminal postscript eps enhanced color dashed lw 1 "Helvetica" 14
set output "ocean-diffuse.eps"
set autoscale
set xtic auto
set ytic auto
plot '0000086400.dat' using 1 with line, \
'0000172800.dat' using 1 with line

In order to have the single column used as x-value, use:
plot '0000086400.dat' using 1:0
That uses the row number (column 0) as y-values. Of course you can do any scaling and computation with the row number as
f(x) = x
plot '0000086400.dat' using 1:(f($0))
To have the y-axis reversed, use
set yrange [*:*] reverse

Related

kdensity normalised by the total number of points

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

gnuplot - intersection of two plots

I am using gnuplot to plot data from two separate csv files (found in this link: https://drive.google.com/open?id=0B2Iv8dfU4fTUZGV6X1Bvb3c4TWs) with a different number of rows which generates the following graph.
These data seem to have no common timestamp (the first column) in both csv files and yet gnuplot seems to fit the plotting as shown above.
Here is the gnuplot script that I use to generate my plot.
# ###### GNU Plot
set style data lines
set terminal postscript eps enhanced color "Times" 20
set output "output.eps"
set title "Actual vs. Estimated Comparison"
set style line 99 linetype 1 linecolor rgb "#999999" lw 2
#set border 1 back ls 11
set key right top
set key box linestyle 50
set key width -2
set xrange [0:10]
set key spacing 1.2
#set nokey
set grid xtics ytics mytics
#set size 2
#set size ratio 0.4
#show timestamp
set xlabel "Time [Seconds]"
set ylabel "Segments"
set style line 1 lc rgb "#ff0000" lt 1 pi 0 pt 4 lw 4 ps 0
plot "estimated.csv" using ($1):2 with lines title "Estimated", "actual.csv" using ($1):2 with lines title "Actual";
Is there any way where we can print out (write to a file) the values of the intersection of these plots by ignoring the peaks above green plot? I also have tried to do an sql-join query but it doesn't seem to print out anything for the same reason I explained above.
PS: If the blue line doesn't touch the green line (i.e. if it is way below the green line), I want to take the values of the closest green line so that it will be a one-to-one correspondence (or very close) with the actual dataset.
Perhaps one could somehow force Gnuplot to reinterpolate both data sets on a fine grid, save this auxiliary data and then compare it row by row. However, I think that it's indeed much more practical to delegate this task to an external tool.
It's certainly not the most efficient way to do it, nevertheless a "lazy approach" could be to read the data points, interpret each dataset as a LineString (collection of line segments, essentially equivalent to assuming a linear interpolation between data points) and then calculate the intersection points. In Python, the script to do this might look like this:
#!/usr/bin/env python
import sys
import numpy as np
from shapely.geometry import LineString
#-------------------------------------------------------------------------------
def load_data(fname):
return LineString(np.genfromtxt(fname, delimiter = ','))
#-------------------------------------------------------------------------------
lines = list(map(load_data, sys.argv[1:]))
for g in lines[0].intersection(lines[1]):
if g.geom_type != 'Point':
continue
print('%f,%f' % (g.x, g.y))
Then in Gnuplot, one can invoke it directly:
set terminal pngcairo
set output 'fig.png'
set datafile separator comma
set yr [0:700]
set xr [0:10]
set xtics 0,2,10
set ytics 0,100,700
set grid
set xlabel "Time [seconds]"
set ylabel "Segments"
plot \
'estimated.csv' w l lc rgb 'dark-blue' t 'Estimated', \
'actual.csv' w l lc rgb 'green' t 'Actual', \
'<python filter.py estimated.csv actual.csv' w p lc rgb 'red' ps 0.5 pt 7 t ''
which gives:

Mapping between data and line color in gnuplot

I want to create a simple histogram in gnuplot and want to adapt the color of the bars according to the data. Currently, I am struggling with the mapping between color and data.
Let's say I have the following data file:
X, 500.00, 100.00, 1
Y, 600.00, 200.00, 2
I generate the histogram with the following code:
reset
fontsize = 12
set terminal png
set output "file.png"
set style fill solid 1.00 border 0
set style histogram errorbars gap 2 lw 1
set style data histogram
set xtics rotate by -45
set grid ytics
set xlabel "label"
set ylabel "label"
set yrange [0:*]
set datafile separator ","
plot 'data.dat' using 2:3:4:xtic(1) ti "" lc variable
Now I want to create a mapping between the fourth column in the data and the color, e.g. 1 -> yellow, 2 -> blue.
I assumed that I can define something like the following
set style line 1 linecolor rgb "yellow"
set style line 2 linecolor rgb "blue"
but this code is not working since it defines styles and not colors. On the other hand I have read in the documentation that "rgb variable" is only available in 3D plotting mode (splot), so I think in this terms my whole approach might go in a wrong direction.
Does anyone know how to realise the mapping between data and line colors?
Have you tried with the command palette? I had the same problems some times ago. I wanted to make this plot (that is in some ways what you need)
So I used the number of elements in a column of the histogram to set the color of that column. My datafile looked like
#MY_FILE
...
26 0.02302 2302
28 0.02233 2233
30 0.02261 2261
32 0.02383 2383
34 0.02279 2279
36 0.02366 2366
38 0.02226 2226
40 0.02148 2148
...
#EOF
where the first row $1 was the n parameter, the second one $2 was my pdf (simply the histogram normalized) and the third $3 column was the number of occurrence int the bin. Then I used the last column as the parameter to color my graph with the command
set palette model RGB defined (1 "blue", 2 "red")
that create a gradient between the starting point 1 and the end 2. Then to use the palette i plotted with the line
p 'MY_FILE' u 1:2:3 w boxes palette
where the w boxes was the command to generate my histogram, and the palette (also pal) command was the command o set the color, which use the third column as specified in u 1:2:3, where the 1:2 is my histogram and 3 is the color gradient.
if you don't want the lateral strip of color (heatmap) just type in gnuplot
unset colorbox
Here's some documentation about palette command in gnuplot:
http://gnuplot.sourceforge.net/demo_5.0/pm3dcolors.html
type help palette on gnuplot
THIS could be particularly HELPFUL: http://www.gnuplotting.org/defining-a-palette-with-discrete-colors/

Gnuplot histogram x logscale

I'm using gnuplot in a bash script to draw several things.
For this special graphic, I need to print the amount of matrices (y axis) with the matrix size as the x-axis.
As the distribution can be pretty sparsed, I want to use a logscale for x and y. It works great with y, but gnuplot tells me I can't have a logscale for the x-axis when I'm using histogram style.
Any ideas to debug this? or on how to present the results using a similar way?
set style data histogram
set style histogram cluster gap 1
set style fill solid border -1
set logscale xy
plot '$res/histo-$ld-$lr-$e-$r' using 2:xtic(1) title 'Run'
The error is :
line 0: Log scale on X is incompatible with histogram plots
Thanks in advance.
Edit : btw, I was using gnuplot 4.4 patchlevel 4 and just updated to the newest version (i.e. 4.6 patchlevel 5)
Gnuplot histograms work a bit differently from what you might think. The x-axis isn't numeric. In your case the value in the first row, second column is placed at an x-value of 0 with the y-value taken from the second column and a manual label taken from the first column, first row. The values of the second row are placed at x=1 etc.
You can try using the boxes plotting style, which is used with a 'conventional' x-axis and supports a logscale in x:
set logscale xy
set offset 0,0,1,1
set boxwidth 0.9 relative
set style fill solid noborder
plot 'data.dat' with boxes
With the data file data.dat
1 1000
2 300
5 150
20 10
135 3
this gives the result (with 4.6.5):
In order to have a fixed boxwidth and a varying box distance, you can use a third column to specify a box width as percentage of the x-value:
set logscale xy
set offset 0,0,1,1
set style fill solid noborder
plot 'data.dat' using 1:2:($1*0.5) with boxes
Putting the actual values on the x-axis works as follows:
set logscale xy
set offset 0,0,1,1
set style fill solid noborder
plot 'data.dat' using 1:2:($1*0.5):xtic(1) with boxes

Plot received powers with gnuplot

I'd like to plot the received powers over different wireless channels. For each channel, I have three values, and I want to plot them stacked.
Actually, this is my script:
set boxwidth 0.6 relative
set ylabel "dBm"
set xlabel "Channel"
set style fill solid
set key off
plot "RR1" using 1:2 with boxes, "RR2" using 1:2 with boxes, "RR3" using 1:2 with boxes
The problem is that since they are negative values (dBm), it plots from 0 to the value it finds, and thus the highest power is on the top. I'd like to plot a somewhat reverse image, with the blue box starting from the bottom up to the value it reaches, and the same for the other two values.
Any idea?
My data looks like this
21.0 -93.9207
22.0 -92.241
23.0 -93.452
One possibity is to use the boxxyerrorbars plotting style:
reset
set ylabel "dBm"
set xlabel "Channel"
set style fill solid
set key off
set style data boxxyerrorbars
set xtics 1
set autoscale xfix
set offset 0.5,0.5,0,0
ylow = -100
plot for [i=3:1:-1] sprintf("RR%d", i) using 1:(0.5*($2+ylow)):(0.3):(0.5*($2-ylow)) lt i
Here, I used a fixed lower y-value, but you could also extract it from the data file with stats and do some other tweaking.
In the using statement, the second column gives the box center, which is the mean of actual y-value and the lower boundary, the third column is x-delta (half of the actual box width), and the fourth column is y-delta.
With some more data values, this gives:

Resources