Graph plot: vertex attributes, node size, arrow head for loops, why are loops on nodes

asked 2020-12-17 19:43:31 +0200

Cyrille gravatar image

updated 2020-12-19 14:45:39 +0200

slelievre gravatar image

Sorry, some of you think that I do not read the docs but the truth is that even reading them I cannot find my way.

Before using SageMath I was mainly working with PSTricks with which I have no problem drawing what I expect. If only it could be incorporated completely it would be a great moment.

Here is my problem: the code below works but I do not understand how to set the vertex attributes, the size of nodes, and so on.

A = matrix([

D = DiGraph(A, format='adjacency_matrix'), vertex_size=100)

Grid graph with unsatisfactory loops

But I do not understand how to set the vertex attributes, the size of the nodes, and so on. I even wonder why loops have no arrow head, why loops are plotted on top of nodes rather than underneath them. This is for my very strange since I have understood how to change the colors of the arcs. I truly need help (sorry to waste your time). I would also like to know if one can use images as vertex attributes.


Added to answer @slelievre's comments

First of all my above code is only 3 lines. I have made many tries to insert vertex_attributes. None works.

Here is what I am able to achieve with PSTricks:

Graph produced with PSTricks

I can provide the code. As I told you (this is also an answer to the comment to @dazedANDconfused), I work now mainly in html with SageCell because it's mandatory in these lockdown times. Most of my students (in economics) are poorly endowed in computers (some work with tablets or even phones). With html embedded SageCells I can overcome all those difficulties since computation are not realized in situ.

I was delighted in discovering Latex2js since their exemples are incredible. But all my trials are poor. It is not complete and their sandbox doesn't work (at least for me). But I think also that as SageMath is a pure killing software, it must be raised to that level.

Science is a pure public good. We are paid by government to increase common knowledge. But it is difficult to share it if you must pay for being published or to acquire software.

PSTricks code and node images as requested by slelievre

Note: my LaTeX preamble uses lots of PStricks packages and I do not remember which are used for this particular graph (I use also *graphix).

\cnodeput[linestyle=none,fillstyle=solid, fillcolor=white, shadow=true,blur=true](2.2,1.4){AA}{\tiny2/\textcolor{venetianred}3}
\cnodeput[linestyle=none,fillstyle=solid, fillcolor=white, shadow=true,blur=true](0.4,1.2){BB}{\tiny\textcolor{venetianred}{3}/2}
\cnodeput[linestyle=none,fillstyle=solid, fillcolor=white, shadow=true,blur=true](-1,-1){CC}{\tiny\textcolor{venetianred}{3}/2}
\cnodeput[linestyle=none,fillstyle=solid, fillcolor=white, shadow=true,blur=true](2,-1.6){DD}{\tiny2/\textcolor{venetianred}{3}}
\cnodeput[linestyle=none,fillstyle=solid, fillcolor=white, shadow=true,blur=true](-.5,2.6){EE}{\tiny\textcolor{venetianred}{4}/1}
\cnodeput[linestyle=none,fillstyle=solid, fillcolor=white, shadow=true,blur=true](-1.6,-.2){FF}{\tiny\textcolor{venetianred}{4}/1}
\cnodeput[linestyle=none,fillstyle=solid, fillcolor=white, shadow=true,blur=true](1.,-1.4){GG}{\tiny\textcolor{venetianred}{3}/2}
\cnodeput[linestyle=none,fillstyle=solid, fillcolor=white, shadow=true,blur=true](-2.6,0){HH}{\tiny\textcolor{venetianred}{3}/2}
\cnodeput[linestyle=none,fillstyle=solid, fillcolor=white, shadow=true,blur=true](.2,-1.6){II}{\tiny1/\textcolor{venetianred}{4}}
\cnodeput[linestyle=none,fillstyle=solid, fillcolor=white, shadow=true,blur=true](-1,-2.4){KK}{\tiny2/\textcolor{venetianred}{3}}
\caption{\textsc{Scores dans les confrontations deux à deux}}\label{condorcetcomp}

Node images: a · b · c · d · e.

Good luck working on that but I think it will be simpler to extend the show command to use PSTricks. That would make SageMath a pure wonder!

edit retag flag offensive close merge delete


Can you share an example (maybe prepared with PSTricks) of what you would like to achieve?

slelievre gravatar imageslelievre ( 2020-12-17 23:28:35 +0200 )edit

Thank you for asking so many questions.

Thanks for often providing some code to get answerers something to start from.

It's not clear how you are using vertex_attrs above.

Regarding vertex size, try using vertex_size=400 or vertex_size=1600. Notice the difference?

slelievre gravatar imageslelievre ( 2020-12-17 23:53:41 +0200 )edit

If you're interested in producing professional looking graphs then LaTeX is the way to go using the packages tkz-graph and tkz-berge. These can work with Sage via the sagetex package. You can see some examples here or here or, for digraphs here. In these cases, the edges vertex sizes, labels, etc are set through LaTeX. The cooperation between Sage and LaTex is not "incorporated completely" but does a decent job.

dazedANDconfused gravatar imagedazedANDconfused ( 2020-12-18 05:06:01 +0200 )edit

dazedANDconfused it's a good suggestion. My problem is that i have decided to work mainly with html including sagecells because it's a trully wonderfull machinery. Many of my students haven't the capacity of a good computation because they are working on tablets even on phone. And we need this because right now in my university we are teaching on internet. With html embedded SageMAthCells this difficulty is overcomed (to the limit of what they use to navigate on internet). But until now there are some limitation I would appreciate to be adapted.

Cyrille gravatar imageCyrille ( 2020-12-18 07:22:26 +0200 )edit

@Cyrille -- thanks for providing an example of desired output. Ideally, please also provide the PSTricks code, as well as the individual images for the nodes.

slelievre gravatar imageslelievre ( 2020-12-18 10:50:36 +0200 )edit