how to plot some data that is in two scales in gnulpot - linux

I want to plot some data that is in two scales.
for 1 < X < 20 , Y is between 0 and 1 and
for 20 < X < 100 Y is between 1 and 20
normal plot has this result:
and as you see the carve between 0 and 20 is hidden!
how can i solve it?

Use a logarithmic scale
set logscale y

Related

Contour plots of noisy data - gridding and averaging

I am trying to make a contour plot from a dataframe in which the x and y coordinates are unevenly spaced and sometimes overlap and the z coordinate is noisy:
x y z
1 15.4707 174.6779 1592.811638
2 15.4707 171.3179 1304.953183
3 61.6107 108.2379 1687.233377
4 46.3707 151.6929 1688.368690
5 30.7107 124.5429 1339.451757
6 31.1307 202.8704 1616.756963
7 0.2307 141.5029 1620.288736
8 15.4707 141.9054 1167.798302
9 46.3707 72.0729 1687.546227
10 15.4707 212.6929 638.059709
What I'd like to do is to define a grid in x and y whose gridelines pass coordinates, say
x=[7.5, 22.5, 37.5, 52.5]
y=[60, 120, 180, 240]
In every grid section, I then take the average of the z values and make a new dataframe where the x and y columns are the centres of the grid sections and the z column is the aforementioned average. The dataframe should look something like
x y z
1 15 90 1621.1
2 30 150 1444.2
3 45 210 1651.7
From this stage it easy to get a contour plot using matplotlib.contourf or similar, but how can do this type of gridding and averaging? Is there an elegant way to do it in Pandas or other python packages?

How do you sum every nth column of data in gnuplot?

I would like to take an average over several columns of a data set in Gnuplot. The problem is that I want to average every other column (starting from the second column of my dataset). I was thinking of using every somehow but I still don't really understand when and where to use every. To help visualise my question: my data looks something like this:
x y1 z1 y2 z2
2 0.6 0 0.6 0
1 0.7 0 0.7 1
1 0.8 2 0.8 1
1 0.9 0 0.9 0
and I would like to average y1 and y2 and plot the result by doing something like:
stats filename nooutput
plot filename u 1:sum[col = every :2::2::STATS_columns] / ((STATS_columns-1)/2)
Not sure if this is anywhere close to doable though. Also, it would be nice to have a way of finding the number of columns used without any apriori knowledge of what the data looks like. In the example I have used my knowledge of the data to know that the average is over ((STATS_columns-1)/2) number of points.
Thank you for your response
From your code I assume you want to average y1 and y2 for each row and then plot it versus x (column 1). Since you have several identical x values, there would be another average, namely an average over the columns and over all identical x values.
I modified your data to better illustrate the difference.
I guess you were asking fot the red circles. The blue triangles are basically the average of the average, i.e. the average of the red points.
Check help summation and help smooth. sum has no step size with the index.
From gnuplot help:
sum [<var> = <start> : <end>] <expression>
Code:
### average over columns and smooth
reset session
$Data <<EOD
#x y1 z1 y2 z2
1 2.0 0 4.0 0
1 2.2 0 4.2 1
1 2.9 2 4.9 1
2 2.1 0 4.1 0
2 2.3 0 4.3 0
2 2.8 0 4.8 0
3 2.2 0 4.2 0
3 2.3 0 4.3 0
3 2.7 0 4.7 0
EOD
stats $Data nooutput
set offsets 0.5,0.5,0.5,0.5
Count = (STATS_columns-1)/2
plot $Data u 1:((sum[i=1:Count] column(i*2))/Count) w p pt 7 lc rgb "red" ti "average over y1,y2 columns for each row",\
$Data u 1:((sum[i=1:Count] column(i*2))/Count) smooth unique w p pt 9 lc rgb "blue" ti "average over y1,y2 for each x"
### end of code
Result:

heatmap color not relating with data in gnuplot

I am trying to create one heatmap using Gnuplot and my data file structure is looked like below:
6 5 4 3 1 0
3 2 2 0 0 1
0 0 0 0 1 0
0 0 0 0 2 3
0 0 1 2 4 3
the cell values are z values and columns represent y-axis and row are x-axes. that means the first value 6 is the z value where the y-axis is 5th position at x label zero. However, while plotting the heat map I am getting a different color which does not correlate with the z value. Also, I am getting five bins for the x-axis (which is supposed to be 6)and 4 bins (which is supposed to be 5) for the y-axis. My simple code is written below:
set pm3d map
splot 'm.txt' matrix
Please help me out of this confused situation.
Thanks.

gnuplot | 3D layers

I have the below data file which has:
1st column is the layer number.
2nd column is the X axis.
3rd column is the Y axis.
1 1999-01-19 21 0 1
1 2009-07-01 0 1 1
1 2008-08-20 2 1 1
1 2008-12-18 1 1 1
2 2004-05-12 4 1 1
2 2009-07-29 2 1 1
3 2008-08-07 0 1 1
4 2006-03-08 1 1 1
4 2004-08-31 9 1 1
4 2001-03-27 12 1 1
My questions:
1. How can I plot the above data file in 3D knowing that each layer must have different Z offset and different color?
the below must be plotted with Z=1
1 1999-01-19 21 0 1
1 2009-07-01 0 1 1
1 2008-08-20 2 1 1
1 2008-12-18 1 1 1
and the below with Z=2
2 2004-05-12 4 1 1
2 2009-07-29 2 1 1
and so on.
2.If I want to select the layer number 2, other layers must be shaded with gray and this layer must be colored with red for example, is that possible? so it's like highlighting the selected layer.
thx.
To plot the points just use
set xdata time
set timefmt '%Y-%m-%d'
set format x '%Y'
splot 'data.dat' using 2:3:1
That uses the layer number as z-value. To get something else, just specify a function for the z-value depending on the layer number:
zpos(z) = 1 + 0.5*z
splot 'data.dat' using 2:3:(zpos($1))
For the coloring use linecolor rgb variable. That allows you to specify the color in the last column. This color must be the integer representation of an rgb-tuple which is 65536*red + 256*green + blue, with red, green and blue being in the range [0:255].
The following script plots the points in layer 2 in dark red:
set xdata time
set timefmt '%Y-%m-%d'
set format x '%Y'
rgb(r,g,b) = 65536*r + 256*g + b
gray = rgb(200,200,200)
red = rgb(200,0,0)
layer = 2
set view 66,20
splot 'data.dat' using 2:3:1:($1 == layer ? red : gray) with points pt 7 linecolor rgb variable notitle
The result with 4.6.4 is:

GNUPlot matrix plot with changing distance between lines

In GNUPlot you can make 3d plots based on a .dat file with a matrix notation:
#Y 0.1 0.2 0.3 0.4
0 1 4 9 #X = 1
1 2 5 10 #X = 2
4 5 8 13 #X = 3
9 10 13 18 #X = 5
16 17 20 25 #X = 7
25 26 29 34 #X = 10
However the file I want to plot has some changes in X-distance between the lines. As shown in comment. One can use set xtics but that only changes the numbers on the plot, while the points should be plotted on a linear axis.
Is there a way to do this?
No, not with this type of matrix notation. You would have to use a format as described here: http://t16web.lanl.gov/Kawano/gnuplot/datafile-e.html#3dim
The matrix format assumes an even spacing between x and y points, but the 3D data format allows arbitrary positioning of all the points.

Resources