image style plot issue with latest gnuplot 5.0.3 - gnuplot

Recently I upgrade gnuplot to 5.0.3 and find that image style plot generate strange output with none square data. This does not happen in previous version (5.0.2). here is the minimal example
set term png
set output "a.png"
plot "-" using 1:2:3 with image title ""
#data
1 1 2
1 2 3
1 3 1
2 1 1
2 2 2
2 3 3
3 1 8
3 2 6
3 3 4
4 1 8
4 2 6
4 3 4
the output image is a.png
When dealing with square data like this
set term png
set output "b.png"
plot "-" using 1:2:3 with image title ""
#data
1 1 2
1 2 3
1 3 1
2 1 1
2 2 2
2 3 3
3 1 8
3 2 6
3 3 4
everything is fine b.png
is this a bug?

This may be a problem of sorting.
Try to sort by 2nd column like this:
1 1 2
2 1 1
3 1 8
4 1 8
1 2 3
2 2 2
3 2 6
4 2 6
1 3 1
2 3 3
3 3 4
4 3 4

I am facing the same problem. At the moment, I switch the x and y axes. I use "u 2:1:3 w image" instead of using "u 1:2:3 w image"

Related

Create Multiple rows for each value in given column in pandas df

I have a dataframe with points given in two columns x and y.
Thing x y length_x length_y
0 A 1 3 1 2
1 B 2 3 2 1
These (x,y) points are situated in the middle of one of the sides of a rectangle with vertex lengths length_x and length_y. What I wish to do is for each of these points give the coordinates of the rectangles they are on. That is: the following coordinated for Thing A would be:
(1+1*0.5, 3), (1-1*0.5,3), (1+1*0.5,3-2*0.5), (1-1*0.5, 3-2*0.5)
The half comes from the fact that the given lengths are the middle-points of an object so half the length is the distance from that point to the corner of the rectangle.
Hence my desired output is:
Thing x y Corner_x Corner_y length_x length_y
0 A 1 3 1.5 2.0 1 2
1 A 1 3 1.5 1.0 1 2
2 A 1 3 0.5 2.0 1 2
3 A 1 3 0.5 1.0 1 2
4 A 1 3 1.5 2.0 1 2
5 B 2 3 3.0 3.0 2 1
6 B 2 3 3.0 2.5 2 1
7 B 2 3 1.0 3.0 2 1
8 B 2 3 1.0 2.5 2 1
9 B 2 3 3.0 3.0 2 1
I tried to do this with defining a lambda returning two value but failed. Tried even to create multiple columns and then stack them, but it's really dirty.
bb = []
for thing in list_of_things:
new_df = df[df['Thing']=='{}'.format(thing)]
df = df.sort_values('x',ascending=False)
df['corner 1_x'] = df['x']+df['length_x']/2
df['corner 1_y'] = df['y']
df['corner 2_x'] = df['x']+1df['x_length']/2
df['corner 2_y'] = df['y']-df['length_y']/2
.........
Note also that the first corner's coordinates need to be repeated as I later what to use geopandas to transform each of these sets of coordinates into a POLYGON.
What I am looking for is a way to generate these rows is a fast and clean way.
You can use apply to create your corners as lists and explode them to the four rows per group.
Finally join the output to the original dataframe:
df.join(df.apply(lambda r: pd.Series({'corner_x': [r['x']+r['length_x']/2, r['x']-r['length_x']/2],
'corner_y': [r['y']+r['length_y']/2, r['y']-r['length_y']/2],
}), axis=1).explode('corner_x').explode('corner_y'),
how='right')
output:
Thing x y length_x length_y corner_x corner_y
0 A 1 3 1 2 1.5 4
0 A 1 3 1 2 1.5 2
0 A 1 3 1 2 0.5 4
0 A 1 3 1 2 0.5 2
1 B 2 3 2 1 3 3.5
1 B 2 3 2 1 3 2.5
1 B 2 3 2 1 1 3.5
1 B 2 3 2 1 1 2.5

How to use Gnuplot to print 3D plots (splot) with error bars and different linespoints

using Gnuplot to plot 3D charts with splot and errors with zerror does not allow us to have different lines with points. Here are examples. I would like to use splot with error bars and still differentiate lines by different points. Like it is mentioned here:
The operation of with is also the same as in plot, except that the
plotting styles available to splot are limited to lines, points,
linespoints, dots, and impulses; the error-bar capabilities of plot
are not available for splot.
Is there another solution for this problem in Gnuplot?
As you note, there doesn't seem to be a direct plotting style for drawing error bars in 3D. It is possible to manipulate the input data to pseudo-draw the error bars with lines style.
Sample Script:
$inputdata <<EOD
# x y z zlow zhigh
1 1 1 0 2
2 1 2 1 3
3 1 3 2 4
4 1 4 3 5
5 1 5 4 6
1 2 5 1 7
2 2 4 1 7
3 2 3 1 7
4 2 2 1 7
5 2 1 1 7
1 3 3 1 4
2 3 3 2 5
3 3 3 3 6
4 3 3 2 5
5 3 3 1 4
EOD
# construct errorbar's line segments data
set table $first
plot $inputdata using 1:2:4:($1-0.1):4:5:0 with table
set table $second
plot $inputdata using 1:2:5:($1+0.1):4:5:0 with table
unset table
# summarize data into data block $errbars
stats $inputdata using 0 nooutput
set print $errbars
do for [i=1:STATS_records] {
print $first[i]
print $second[i]
print ""
print ""
}
set print
set xrange [0:6]
set yrange [0:4]
set key noautotitle
splot $inputdata using 1:2:3:2 with linespoints pt 7 lc variable, \
$errbars using 1:2:3:2 with lines lc variable, \
$errbars using 4:2:5:2 with lines lc variable, \
$errbars using 4:2:6:2 with lines lc variable
pause -1
It uses the line-wise data (x,y,z,zlow,zhigh) of the data points and error range as inputs to build the data to draw the error bars and whiskers. Once that's done, we can draw each part of the error bar in lines style.
Result:
Here's another solution using vector style which is actually much simpler than above script.
Sample script:
$inputdata <<EOD
# x y z zlow zhigh
1 1 1 0 2
2 1 2 1 3
3 1 3 2 4
4 1 4 3 5
5 1 5 4 6
1 2 5 1 7
2 2 4 1 7
3 2 3 1 7
4 2 2 1 7
5 2 1 1 7
1 3 3 1 4
2 3 3 2 5
3 3 3 3 6
4 3 3 2 5
5 3 3 1 4
EOD
set xrange [0:6]
set yrange [0:4]
unset key
set style arrow 3 heads size 0.05,90 lc variable
splot $inputdata using 1:2:3:2 with linespoints pt 7 lc variable, \
$inputdata using 1:2:4:(0):(0):($5-$4):2 with vectors arrowstyle 3
pause -1
Thanks.

How do I calculate the probability of every value in a dataframe column quickly in Python?

I want to calculate the probability of all the data in a column dataframe according to its own distribution.For example,my data like this:
data
0 1
1 1
2 2
3 3
4 2
5 2
6 7
7 8
8 3
9 4
10 1
And the output I expect like this:
data pro
0 1 0.155015
1 1 0.155015
2 2 0.181213
3 3 0.157379
4 2 0.181213
5 2 0.181213
6 7 0.048717
7 8 0.044892
8 3 0.157379
9 4 0.106164
10 1 0.155015
I also refer to another question(How to compute the probability ...) and get an example of the above.My code is as follows:
import scipy.stats
samples = [1,1,2,3,2,2,7,8,3,4,1]
samples = pd.DataFrame(samples,columns=['data'])
print(samples)
kde = scipy.stats.gaussian_kde(samples['data'].tolist())
samples['pro'] = kde.pdf(samples['data'].tolist())
print(samples)
But what I can't stand is that if my column is too long, it makes the operation slow.Is there a better way to do it in pandas?Thanks in advance.
Its own distribution does not mean kde. You can use value_counts with normalize=True
df.assign(pro=df.data.map(df.data.value_counts(normalize=True)))
data pro
0 1 0.272727
1 1 0.272727
2 2 0.272727
3 3 0.181818
4 2 0.272727
5 2 0.272727
6 7 0.090909
7 8 0.090909
8 3 0.181818
9 4 0.090909
10 1 0.272727

how to calculate standard deviation from different colums in shell script

I have a datafile with 10 columns as given below
ifile.txt
2 4 4 2 1 2 2 4 2 1
3 3 1 5 3 3 4 5 3 3
4 3 3 2 2 1 2 3 4 2
5 3 1 3 1 2 4 5 6 8
I want to add 11th column which will show the standard deviation of each rows along 10 columns. i.e. STDEV(2 4 4 2 1 2 2 4 2 1) and so on.
I am able to do by taking tranpose, then using the following command and again taking transpose
awk '{x[NR]=$0; s+=$1} END{a=s/NR; for (i in x){ss += (x[i]-a)^2} sd = sqrt(ss/NR); print sd}'
Can anybody suggest a simpler way so that I can do it directly along each row.
You can do the same with one pass as well.
awk '{for(i=1;i<=NF;i++){s+=$i;ss+=$i*$i}m=s/NF;$(NF+1)=sqrt(ss/NF-m*m);s=ss=0}1' ifile.txt
Do you mean something like this ?
awk '{for(i=1;i<=NF;i++)s+=$i;M=s/NF;
for(i=1;i<=NF;i++)sd+=(($i-M)^2);$(NF+1)=sqrt(sd/NF);M=sd=s=0}1' file
2 4 4 2 1 2 2 4 2 1 1.11355
3 3 1 5 3 3 4 5 3 3 1.1
4 3 3 2 2 1 2 3 4 2 0.916515
5 3 1 3 1 2 4 5 6 8 2.13542
You just use the fields instead of transposing and using the rows.

Excel macro 3D chart

i have the following data in one sheet:
x y offset
1 1 2
1 2 2
1 3 3
1 4 4
2 1 5
2 2 6
2 3 2
2 4 2
3 1 3
3 2 4
3 3 5
3 4 6
4 1 8
4 2 7
4 3 0
4 4 9
and i want to display the offsets in a 3 dimensional way using an excel macro. In other words, here x and y are the coordinates, offsets are the z values. I just want to get a surface/columns over the xy plane. I searched awhile in the internet, but don't find much useful stuffs. Could you give me any hints?
Thanks in advance,
John
If you reformat your data, you will be able to use a regular Excel diagram type (3D columns) to graph the data:
1 2 3 4
1 2 2 3 4
2 5 6 2 2
3 3 4 5 6
4 8 7 0 9
VBA code:
Sub graphData()
Range("D3:H7").Select
ActiveSheet.Shapes.AddChart.Select
ActiveChart.SetSourceData Source:=Range("'Tabelle1'!$D$3:$H$7")
ActiveChart.ChartType = xl3DColumn
End Sub
You would have to set your range accordingly.

Resources