Create graph having nodes with no labels and no separations between its edges with Graphviz - graph

I want to generate this kind of graphs with graphviz :
I tried the following code :
graph{
node [shape=none label=""]
1 [pos="0,0!"]
2 [pos="1.2145,0.694!"]
3 [pos="1.2145,2.082!"]
4 [pos="0.0,2.776!"]
5 [pos="-1.2145,2.082!"]
6 [pos="-1.2145,0.694!"]
1 -- 2
2 -- 3
3 -- 4
4 -- 5
5 -- 6
6 -- 1
}
But I get the following output
Is it possible to make nodes without labels and edges without any separation between than ?
Thanks for your answers.

digraph D {
graph [nodesep=.02]
node [shape=hexagon]
A B C
}
Gives this:
And this:
digraph D {
graph [nodesep=.02]
node [shape=hexagon orientation=30]
A B C
}
Gives this:

Related

How to know if there is a different element in one array in Scilab?

My goal is to check if there are misplaced objects in one array.
for example the array is
2.
2.
2.
2.
2.
1.
3.
1.
3.
3.
3.
1.
3.
1.
1.
1.
1.
I want to know if the first 5 elements, 6 to 13 and 14-17 are the same.
The purpose of this is to identify the misplaced elements in a clustering solution.
I have tried for the first 5 elements
ISet=5
IVer=7
IVir=5
for i=1:ISet
if(isequal(FIRSTMIN(i,1,2),FIRSTMIN(i+1,1,2))==%f)
numMisp=numMisp+1
mprintf("Set misp: %i",numMisp)
end
end
For the next 6 to 13 elements
for i=ISet+1:IVer+ISet-1
if(isequal(FIRSTMIN(i,1,2),FIRSTMIN(i+1,1,2))==%f)
mprintf("%i %i Ver misp: %i\n",FIRSTMIN(i,1,2),FIRSTMIN(i+1,1,2),i)
numMisp=numMisp+1
end
end
For the next 14 to 17 elements
for i=IVer+ISet:IVer+IVir-1
if(isequal(FIRSTMIN(i,1,2),FIRSTMIN(i+1,1,2))==%f)
mprintf("%i %i Ver misp: %i\n",FIRSTMIN(i,1,2),FIRSTMIN(i+1,1,2),i)
numMisp=numMisp+1
mprintf("Vir misp: %i",i)
end
end
You can use unique for that purpose. For example the following test checks if the first five elements are the same
x=[2 2 2 2 2 1 3 1 3 3 3 1 3 1 1 1 1];
if length(unique(x(1:5))) == 1
//
end
You can do the the same for the other clusters by replacing 1:5 by 6:13 then 14:17.

Error in lis[[i]] : attempt to select less than one element

This code is meant to compute the total distance of some given coordinates, but I don't know why it's not working.
The error is: Error in lis[[i]] : attempt to select less than one element.
Here is the code:
distant<-function(a,b)
{
return(sqrt((a[1]-b[1])^2+(a[2]-b[2])^2))
}
totdistance<-function(lis)
{
totdis=0
for(i in 1:length(lis)-1)
{
totdis=totdis+distant(lis[[i]],lis[[i+1]])
}
totdis=totdis+distant(lis[[1]],lis[[length(lis)]])
return(totdis)
}
liss1<-list()
liss1[[1]]<-c(12,12)
liss1[[2]]<-c(18,23)
liss1[[4]]<-c(29,25)
liss1[[5]]<-c(31,52)
liss1[[3]]<-c(24,21)
liss1[[6]]<-c(36,43)
liss1[[7]]<-c(37,14)
liss1[[8]]<-c(42,8)
liss1[[9]]<-c(51,47)
liss1[[10]]<-c(62,53)
liss1[[11]]<-c(63,19)
liss1[[12]]<-c(69,39)
liss1[[13]]<-c(81,7)
liss1[[14]]<-c(82,18)
liss1[[15]]<-c(83,40)
liss1[[16]]<-c(88,30)
Output:
> totdistance(liss1)
Error in lis[[i]] : attempt to select less than one element
> distant(liss1[[2]],liss1[[3]])
[1] 6.324555
Let me reproduce your error in a simple way
>list1 = list()
> list1[[0]]=list(a=c("a"))
>Error in list1[[0]] = list(a = c("a")) :
attempt to select less than one element
So, the next question is where are you accessing 0 index list ?
(Indexing of lists starts with 1 in R )
As Molx, indicated in previous posts : "The : operator is evaluated before the subtraction - " . This is causing 0 indexed list access.
For ex:
> 1:10-1
[1] 0 1 2 3 4 5 6 7 8 9
>1:(10-1)
[1] 1 2 3 4 5 6 7 8 9
So replace the following lines of your code
>for(i in 1:(length(lis)-1))
{
totdis=totdis+distant(lis[[i]],lis[[i+1]])
}

Gnuplot - plotting label with different lines in hypertext

Having the following text file
0 0 net0 aaaa bbbb cccc
1 1 net1 zzz
2 2 net2 xxx
3 3 net3 yyy
4 5 net4 ttt 0 0
5 5 net5
I need to plot all points described by the first two columns as x,y coordinates and anchoring the informations reported in the following columns (say 3:6) at each point.These info have to be plot separated by newlines, e.g. the point in (0,0) should report (when mouse over it)
net0
aaaa
bbbb
cccc
The script I'm using is the following but it works only with three columns
set terminal canvas enhanced mousing
set termoption enhanced
set label at 0,0 "Origin"
set title 'mouse over points'
plot 'test.txt' using 1:2:3 with labels hypertext point pt 7 ps var lc rgb "black"
It seems that the datafile modifier using works only with three entries.
Any help?
It is unfortunate that your text is not surrounded by "". Nevertheless, you can handle your issue with gnuplot without any external tool.
You didn't specify whether your data columns are separated by TAB or by space.
In the following, I assume that they are separated by single space (code needs to be adapted accordingly if not).
Procedure:
Read the data as full line by setting set datafile separator "\n"
extract the numbers with word()
take the rest of the line as your label text
replace spaces by '\n'
Code:
### Hypertext with columns
reset session
$Data <<EOD
0 0 net0 aaaa bbbb cccc
1 1 net1 zzz
2 2 net2 xxx
3 3 net3 yyy
4 5 net4 ttt 0 0
5 5 net5
EOD
# replace function
# replaces string s1 by string s2 in string s
Replace(s,s1,s2) = (RP_s="", RP_n=1, (sum[RP_i=1:strlen(s)] \
((s[RP_n:RP_n+strlen(s1)-1] eq s1 ? (RP_s=RP_s.s2, RP_n=RP_n+strlen(s1)) : \
(RP_s=RP_s.s[RP_n:RP_n], RP_n=RP_n+1)), 0)), RP_s)
set datafile separator "\n"
GetNumber(n) = real(word(strcol(1),n))
GetText(s) = (s[strstrt(s," ")+1:])[strstrt(s[strstrt(s," ")+1:]," ")+1:]
TextToColumn(s) = Replace(GetText(s),' ','\n')
plot $Data u (GetNumber(1)):(GetNumber(2)):(TextToColumn(strcol(1))) w labels hypertext \
point pt 7 ps 3 lc rgb "red" notitle
### end of code
Result:

SAS: PROC SGPLOT BY GROUP auto file names

I am plotting some data using BY GROUP option. While I am able to use #byval option to automatically put BY GROUP value in title of each plot, but I want to save each plot individually and want to name it after #byval instead of calling it - SGPLOT01, SGPLOT02 ...
e.g. Lets say I have:
data xyz;
input type$ x y1 y2##;
cards;
A 1 5 7
A 2 7 9
A 3 8 10
B 1 5 7
B 2 7 9
B 3 8 10
;;
RUN;
PROC SGPLOT DATA=xyz;
by type;
series1 x=x y=y1/markers;
series2 x=x y=y2/markers;
title "#byval";
RUN;
In this example, two plots will be created one each for type A and B. But program will automatically name them as SGPLOT1.pdf and SGPLOT2.pdf. I would rather want to name them A.pdf and B.pdf, and want to save them to directory "C:/SGPLOTS/".
Thanks for your help.
One option is to use ODS and put use a macro to print each TYPE separately, like in the following example.
data xyz;
input type$ x y1 y2 ##;
cards;
A 1 5 7
A 2 7 9
A 3 8 10
B 1 5 7
B 2 7 9
B 3 8 10
;
RUN;
ods listing close;
%macro plot_it(type=);
goptions reset
device = sasprtc
target = sasprtc
;
ods pdf file="C:/SGPLOTS/&type..pdf" notoc;
PROC SGPLOT DATA=xyz;
by type;
where type = "&type";
series x=x y=y1/markers;
series x=x y=y2/markers;
title "#byval";
RUN;
ods pdf close;
%mend plot_it;
%plot_it(type=A);
%plot_it(type=B);
You want to add the variable name within parentheses, after #BYVAL. In this example you want to put #byval(type) in your title.
I have put your example within something SAS calls an "HTML sandwich," which is two lines on top and two lines on the bottom. In addition I added the helpbrowser option, which tells SAS to use its own capabilities to display the html output.
option helpbrowser=sas;
/**** top of html sandwich *****/
ods html ;
ods graphics on;
/*******************************/
data xyz;
input type$ x y1 y2##;
cards;
A 1 5 7
A 2 7 9
A 3 8 10
B 1 5 7
B 2 7 9
B 3 8 10
;;
RUN;
PROC SGPLOT DATA=xyz;
by type;
series x=x y=y1/markers;
series x=x y=y2/markers;
title "Here is the type: #byval(type)";
RUN;
/**** bottom of html sandwich *****/
ods graphics off;
ods html close;
/**********************************/

Gnuplot: Multiple Stacked Histograms, each group using the same key

I am trying to create a plot with multiple stacked histograms like example 8 here. But for my data, each group has the same four categories.
How do I change the colors and the key so that colors go Red, Green, Blue, Pink for every stacked column? And so the key only has one copy each of the 4 things I am plotting?
Here is the line I'm using to plot:
plot newhistogram "1", 'addresses.dat' using 2:xtic(1) t 2, '' u 3 t 3, \
'' u 4 t 4, '' u 5 t 5, newhistogram "2", '' u 6 t 6, '' u 7 t 7, '' u 8 t 8,\
'' u 9 t 9
My data is in the same format as the example I linked to above:
Address PAL_Code BASH App Kernel PAL_Code BASH App Kernel
FFT 1 1 2 2 1 1 3 4
RADIX 1 2 3 4 1 2 4 5
LU 1 3 4 5 1 3 5 6
Thank you so much if you can help!
use the ltspecifier behind newhistogram in order to specify the first color gnuplot should use. I wrote a little script that might does what you want;)
set style data histogram
set style histogram rowstack gap 1
set style fill solid border -1
set boxwidth 0.9
set key autotitle columnheader
set key outside below center horizontal
plot newhistogram "1" lt 1, 'addresses.dat' u 2:xtic(1), '' u 3, '' u 4, '' u 5,\
newhistogram "2" lt 1, 'addresses.dat' u 6:xtic(1) notitle, '' u 7 notitle, \
'' u 8 notitle, '' u 9 notitle
Hope that helps
Cherio
Woltan

Resources