gnuplot: scale axis of matrix plot - gnuplot

I have a matrix, output.dat:
0 0 0 0 0 0 3 7 1 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 11 16 6 1 0 0 0 0 0 0 0 0 0
0 0 0 0 0 7 8 4 16 4 1 0 0 0 0 0 0 0 0 0
0 0 0 0 0 2 2 5 11 3 1 0 0 0 0 0 0 0 0 0
0 0 0 0 0 3 1 9 10 9 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 12 28 13 11 5 0 0 0 0 0 0 0 0 0 0
0 0 0 0 1 6 17 33 14 2 0 5 2 0 0 0 0 0 0 0
0 0 0 0 0 1 13 15 11 6 0 0 5 7 0 0 0 0 0 0
0 0 0 0 0 0 3 3 8 3 0 0 0 3 0 0 0 0 0 0
0 0 0 0 0 0 0 8 8 8 1 2 1 3 2 0 0 0 0 0
0 0 0 0 0 0 0 1 17 10 4 7 4 12 3 0 0 0 0 0
0 0 0 0 0 3 2 3 6 22 9 5 8 5 1 0 0 0 0 0
0 0 0 0 0 1 5 7 10 35 4 6 6 9 4 0 0 0 0 0
0 0 0 0 0 2 12 12 30 52 23 11 8 7 5 1 0 0 0 0
0 0 0 0 1 7 25 16 33 30 26 16 21 19 5 2 0 0 0 0
0 0 0 0 0 0 12 36 19 22 28 19 30 17 9 0 0 0 0 0
0 0 0 0 0 11 18 12 37 32 27 26 33 21 10 12 3 0 0 0
0 0 0 0 0 11 14 23 44 59 45 26 28 9 3 7 0 0 0 0
0 0 0 0 0 0 0 8 19 23 22 11 34 32 25 7 0 0 0 0
0 0 0 0 0 0 0 0 4 8 9 16 21 26 20 11 12 4 6 2
Using this in a bash script results in a perfectly fine looking plot of the matrix:
echo "set terminal png font arial 30 size 1600,1200;
set output 'output.png';set xrange [1:20];set yrange [1:20];set xlabel 'x';set ylabel 'y';
set pm3d map;set pm3d interpolate 0,0;splot 'output.dat' matrix" | gnuplot
However, I'd like the x-axis and y-axis to say "0...1" instead of "1...20". If I simply change the xrange [1:20] to [0:1] no data is plotted. And scaling the data doesn't work. Using xticlabels (at least as I understand it) hasn't successfully changed the axes either.
How can I change the x and y to say "0...1" instead of "1...20"?

I don't know what you tried, but scaling in the using statement works fine:
echo "set terminal pngcairo;set autoscale fix; set tics out nomirror;
set xlabel 'x';set ylabel 'y'; set pm3d map interpolate 0,0;
splot 'output.dat' matrix using (\$1/19.0):(\$2/19.0):3" | gnuplot > output.png

Related

How to display dataframe without break in Tkinter app

Im using code bellow to display pandas dataframe, but in my tkinter app i get columns displayed and splited with '\'
def on_show_frame(self, event):
T = tk.Text(self, height=30, width=120, wrap=None)
T.grid(row=2, column=4, columnspan=14, rowspan=14, padx=10, pady=10)
T.insert(tk.END, self.controller.df)
Is there option to add to tk.Text to fix this problem? Soo data is displayed without break.
Here is how it looks in my app ,data display is contionued after all rows:
datetime mean std sum 1 2 3 4 5 6 7 8 9 \
0 2017-07-12 08:00:00 1.805556 2.447383 65 8 9 1 0 0 2 0 0 0
1 2017-07-12 08:01:00 0.833333 1.133893 30 0 0 1 0 0 1 0 0 0
2 2017-07-12 08:02:00 1.027778 1.182881 37 0 0 1 0 0 2 0 2 0
3 2017-07-12 08:03:00 0.944444 1.286067 34 0 0 1 0 0 0 0 1 0
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 \
0 0 0 3 1 0 3 0 1 1 1 0 0 1 3 0 0 2 0
1 0 1 2 4 0 3 1 2 0 1 0 0 2 4 0 2 2 0
2 1 1 3 0 0 3 1 2 1 2 1 0 2 3 0 2 0 0
3 1 1 2 1 0 3 1 3 0 1 1 0 2 4 0 0 4 0
etc.
238 1 1 0 0 0 2 0 0 0 0 1 0 1 0 0 0 0 0
239 1 1 0 0 2 0 0 0 0 0 2 0 3 0 0 0 0 0
240 0 4 0 0 0 1 0 0 0 0 1 0 2 0 0 0 1 0
28 29 30 31 32
0 0 3 1 1 2
1 0 1 1 1 1
Than you for all help in advance.

How to create a confusion matrix from an incomplete dataframe in python

I have a dataframe which looks like this:
I1 I2 V
0 1 1 300
1 1 5 7
2 1 9 3
3 2 2 280
4 2 3 4
5 5 1 5
6 5 5 400
I1 and I2 represent indexes while V represent values.
The indexes with values equal to 0 have been omitted, but I'd like to get a confusion matrix showing all the values, i.e. something like this:
1 2 3 4 5 6 7 8 9
1 300 0 0 0 7 0 0 0 3
2 0 280 4 0 0 0 0 0 0
3 0 0 0 0 0 0 0 0 0
4 0 0 0 0 0 0 0 0 0
5 5 0 0 0 400 0 0 0 0
6 0 0 0 0 0 0 0 0 0
7 0 0 0 0 0 0 0 0 0
8 0 0 0 0 0 0 0 0 0
9 0 0 0 0 0 0 0 0 0
How can I do it?
Thanks in advance!
Use set_index with unstack for reshape, for append missing values add reindex and for data cleaning rename_axis :
r = range(1, 10)
df = (df.set_index(['I1','I2'])['V']
.unstack(fill_value=0)
.reindex(index=r, columns=r, fill_value=0)
.rename_axis(None)
.rename_axis(None, axis=1))
print (df)
1 2 3 4 5 6 7 8 9
1 300 0 0 0 7 0 0 0 3
2 0 280 4 0 0 0 0 0 0
3 0 0 0 0 0 0 0 0 0
4 0 0 0 0 0 0 0 0 0
5 5 0 0 0 400 0 0 0 0
6 0 0 0 0 0 0 0 0 0
7 0 0 0 0 0 0 0 0 0
8 0 0 0 0 0 0 0 0 0
9 0 0 0 0 0 0 0 0 0
Detail:
print (df.set_index(['I1','I2'])['V']
.unstack(fill_value=0))
I2 1 2 3 5 9
I1
1 300 0 0 7 3
2 0 280 4 0 0
5 5 0 0 400 0
Alternative solution with pivot, if all values are integers:
r = range(1, 10)
df = (df.pivot('I1','I2', 'V')
.fillna(0)
.astype(int)
.reindex(index=r, columns=r, fill_value=0)
.rename_axis(None)
.rename_axis(None, axis=1))
print (df)
1 2 3 4 5 6 7 8 9
1 300 0 0 0 7 0 0 0 3
2 0 280 4 0 0 0 0 0 0
3 0 0 0 0 0 0 0 0 0
4 0 0 0 0 0 0 0 0 0
5 5 0 0 0 400 0 0 0 0
6 0 0 0 0 0 0 0 0 0
7 0 0 0 0 0 0 0 0 0
8 0 0 0 0 0 0 0 0 0
9 0 0 0 0 0 0 0 0 0
Option 1: Using numpy you can
In [150]: size = df[['I1', 'I2']].values.max()
In [151]: arr = np.zeros((size, size))
In [152]: arr[df.I1-1, df.I2-1] = df.V
In [153]: idx = np.arange(1, size+1)
In [154]: pd.DataFrame(arr, index=idx, columns=idx).astype(int)
Out[154]:
1 2 3 4 5 6 7 8 9
1 300 0 0 0 7 0 0 0 3
2 0 280 4 0 0 0 0 0 0
3 0 0 0 0 0 0 0 0 0
4 0 0 0 0 0 0 0 0 0
5 5 0 0 0 400 0 0 0 0
6 0 0 0 0 0 0 0 0 0
7 0 0 0 0 0 0 0 0 0
8 0 0 0 0 0 0 0 0 0
9 0 0 0 0 0 0 0 0 0
Option 2: Using scipy.sparse.csr_matrix
In [178]: from scipy.sparse import csr_matrix
In [179]: size = df[['I1', 'I2']].values.max()
In [180]: idx = np.arange(1, size+1)
In [181]: pd.DataFrame(csr_matrix((df['V'], (df['I1']-1, df['I2']-1)), shape=(size, si
...: ze)).toarray(), index=idx, columns=idx)
Out[181]:
1 2 3 4 5 6 7 8 9
1 300 0 0 0 7 0 0 0 3
2 0 280 4 0 0 0 0 0 0
3 0 0 0 0 0 0 0 0 0
4 0 0 0 0 0 0 0 0 0
5 5 0 0 0 400 0 0 0 0
6 0 0 0 0 0 0 0 0 0
7 0 0 0 0 0 0 0 0 0
8 0 0 0 0 0 0 0 0 0
9 0 0 0 0 0 0 0 0 0

Sumproduct ranges excluding rows with sum=0 or row containing blank cells

Here is a sample data set:
1 2 3 4 5 6 7 8 9 10 11 12
a 20 0 9 0 0 0 0 0 0 0 5 9
a 0 10 0 0 0 0 0 0 0 0 0 10
a 20 10 0 0 0 0 0 0 0 0 0 18
a 0 10 7 0 0 0 0 0 0 0 18
a 0 0 2 0 0 0 0 5 4.5 0 0 18
a 0 10 8 0 0 0 0 0 0 0 5 8
b 0 10 6 0 0 0 0 0 0 0 0 0
b 10 0 9 0 0 0 0 0 0 0 0 5
b 0 10 9 3.5 0 0 0 0 0 0 0
b 0 10 5 0 0 0 0 0 0 0 5 8
b 10 8 6 0 0 0 0 0 0 0 5 10
b 0 15 24 0 5 0 0 0 0 0 5 9
c 0 0 8 0 4.5 0 0 5 0 0 0 0
c 0 0 0 0 0 0 0 0 0 0 0 0
c 10 10 27 0 0 0 0 0 0 0 0
c 5 20 5 0 10 0 0 0 0 0 0 0
c 10 10 10 0 0 0 0 0 0 0 0 10
d 0 0 0 0 0 0 0 0 0 0 0 0
d 10 5 5 0 0 0 0 0 0 5 10
I have to calculate the circular vector length (r) of each type: a, b, c and d.
The individuals of each set containing blank or like the second c containing all 0's give error for the formula I am using which forces me to calculate r for each individual first using formula-
For first a (in O column):
=IF(OR(COUNTBLANK(B2:M2)>0,SUM(B2:M2)=0),"",SQRT(SUMPRODUCT(B2:M2,B$1:M$1)^2+SUMPRODUCT(B2:M2,B$1:M$1)^2)/SUM(B2:M2))
Then for average over all a with:
=IF(SUMIFS(O$2:O$20,A$2:A$20,Q2)=0,"",AVERAGEIFS(O$2:O$20,A$2:A$20,Q2))
What I need is something to combine both formula so that excel:
First checks for matching type: a, b, c, d
Excludes rows with blanks or sum=0
Sumproduct each remaining row
Average over all a's for example
Any help is greatly appreciated

':' expected error in gnuplot while plotting multi column data file

plotFile_bin.p
1 #Chart properties
2 set title "Cumulative binning"
3 set terminal svg size 1200,1800
4 set out '/ethCfmTopo/2way_delay/data/spoke-ntp/cumulative_binning.svg'
5 set multiplot layout 10,1 title "Multiplot"
6 set autoscale y
7 set autoscale x
8 set ylabel "Iterations"
9 set xlabel "Round trip ms"
10 set style data histogram
11 set style fill solid border
12 set xtics scale 0 nomirror rotate by -45
13 plot for [COL=2:9] '/ethCfmTopo/2way_delay/data/spoke-ntp/data_binningbin.log' using COL:xticlabels(1) title columnheader, for [COL=2:9] '' using 0:COL:COL w labels title columnheader
while running the above code i am getting ':' expected error, Searched it in many forums not getting any clue. Can anyone please help on this ?
Error Output
#gnuplot plotFile_bin.p
plot for [COL=2:9] '/ethCfmTopo/2way_delay/data/spoke-ntp/data_binningbin.log' using COL:xticlabels(1) title columnheader, for [COL=2:9] '' using 0:COL:COL w labels title columnheader
^
"plotFile_bin.p", line 13: ':' expected
below is my datafile:
0 0 0 0 0 0 0 0 0
1.01-1.1 0 0 0 0 0 0 0 0
1.1-1.2 1 2 4 6 0 2 3 3
1.2-1.3 173 168 188 248 189 234 206 216
1.3-1.4 1529 1638 1755 1765 1816 1842 1683 1662
1.4-1.5 785 671 546 463 479 408 597 600
1.5-1.6 1 4 0 1 5 3 3 0
1.6-1.7 1 0 0 0 0 0 0 0
1.7-1.8 1 1 1 2 3 0 0 1
1.8-1.9 2 0 4 1 3 3 0 3
1.9-2 0 1 0 2 4 1 0 2
2-2.3 1 1 0 0 0 0 1 0
2.3-2.6 0 0 1 0 0 0 0 0
2.6-3 0 0 0 0 0 0 0 0
3-4 0 0 0 0 0 0 1 0
4-5 1 0 0 0 0 0 0 0
5-7 0 0 0 0 0 0 0 0
7-10 1 1 1 1 0 0 0 1
10-16 4 13 0 9 0 7 6 11
16-21 0 0 0 2 1 0 0 1
21-31 0 0 0 0 0 0 0 0
>31 0 0 0 0 0 0 0 0
Update to at least gnuplot 4.4.0. The support for iteration (plot for [COL=2:9] ...) was added there.

Wondering about Virtuoso's database commit durability – switch settings ?)

I am running/testing the openlinksw.com Virtuoso database server and am noticing something odd – there appears to be no transaction logging.
Likely there is a switch/parm that needs to be set to enable logging of the individual commits/transactions, but I have not found in the documentation.
I have a script that looks like this:
set autocommit manual;
ttlp(file_to_string_output ('./events.nq/00000000'), 'bruce', 'bob', 512);
commit work;
ttlp(file_to_string_output ('./events.nq/00000001'), 'bruce', 'bob', 512);
commit work;
<repeat ttlp/commit pair many times>
Each of the 19,978 input files contains 50 quads.
I ran:
bin/isql < script.sql
and while it was running, I ran 'vmstat 1'. The script takes about 4
minutes to finish, which gives a rate of about 83 commits per second.
However, vmstat's 'bo' (blocks out) column only occassionally showed
disk i/o. Most of the time, 'bo' was zero, with occassional bursts of
activity. I would expect that, for each commit to be durable, there
would have to be at least a small bit of i/o per commit for
transaction logging. Am I doing something wrong? I'm using the
default database parameters.
Example vmstat 1 output:
procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu-----
r b swpd free buff cache si so bi bo in cs us sy id wa st
2 0 113900 34730612 527836 11647812 0 0 0 0 4024 2928 6 1 94 0 0
1 0 113900 34729992 527840 11647876 0 0 0 36 4035 2727 6 0 93 1 0
2 0 113900 34729392 527840 11648440 0 0 0 0 3799 2612 6 1 94 0 0
1 0 113900 34728896 527840 11649004 0 0 0 0 3814 2693 6 0 94 0 0
1 0 113900 34724100 527840 11649556 0 0 0 0 3775 2653 6 1 94 0 0
1 0 113900 34723008 527840 11650128 0 0 0 8 3696 2838 6 0 94 0 0
1 0 113900 34722512 527844 11650708 0 0 0 16 3594 2996 6 0 93 0 0
1 0 113900 34721892 527844 11651868 0 0 0 0 4073 3066 6 0 94 0 0
1 0 113900 34721272 527844 11652488 0 0 0 0 4175 3077 6 1 94 0 0
1 0 113900 34721024 527844 11652568 0 0 0 5912 3744 2929 6 1 94 0 0
1 0 113900 34719540 527844 11653696 0 0 0 60 3786 3143 6 1 93 0 0
1 0 113900 34719044 527844 11653772 0 0 0 32 3809 2911 6 1 94 0 0
1 0 113900 34718052 527844 11654396 0 0 0 0 3963 2842 6 1 94 0 0
1 0 113900 34717060 527844 11654988 0 0 0 0 3956 2904 6 1 94 0 0
1 0 113900 34714748 527844 11656140 0 0 0 0 3920 2928 6 1 94 0 0
1 0 113900 34714144 527844 11656212 0 0 0 4 4059 2984 6 1 93 1 0
1 0 113900 34713656 527848 11657360 0 0 0 16 3945 2908 6 1 94 0 0
1 0 113900 34712540 527848 11657972 0 0 0 0 3978 2984 6 1 93 0 0
1 0 113900 34712044 527848 11658052 0 0 0 0 3758 2889 6 1 94 0 0
1 0 113900 34711088 527848 11658640 0 0 0 0 3643 2712 6 1 94 0 0
1 0 113900 34710468 527848 11659224 0 0 0 0 3763 2812 6 1 94 0 0
Running on
Version: 7.1
64-bit linux

Resources