Hi, I'm creating a digraph object in a matlab app to show a network of nodes and connecting edges that are generated from pre existing data. The graphs end up looking like this:
What I want to know is whether there is anyway to change the shape of the connecting edges that are displayed for example to reduce the severity of the curve (ideally even to a straight line) or to add arrows to show the direction of each edge. I know the thickness and colour can be changed but this is not helpful for my purposes.

4 commentaires

dpb
dpb il y a 44 minutes
What is used to generate the attached? For a chance for help, attach a minimum working example that folks can poke at. Paste the code in as text and format with the "CODE" button (or select and use Ctrl-E or Ctrl-E first then paste). If it needs external data, then attach that file.
Timothy
Timothy il y a 37 minutes
It doesn't so much matter about the specific graph, I just want to know if MATLAB can alter the shape of lines on graph/digraph plot objects
dpb
dpb il y a environ 5 heures
Modifié(e) : dpb il y a environ 3 heures
Of course it matters completely -- what can be modified depends entirely upon what the specific graphics object exposes to the user as settable properties.
If your query here is whether you can control the eccentricity of the ovals in your example, I'd venture the answer will be "No" unless you can get at the underlying object -- which I'll wager is probably going to be hidden.
But, again, give us something to poke at; others may come along that are more familiar than I but why make folks work harder to try to help since it is going to take digging into?
If the above are rendered by using rectangle, the curvature can be modified, but to go through the given points(+) there's only so much that it can do...
subplot(1,3,1)
rectangle('Position',[0 0 2 4],'Curvature',0.2)
axis equal
subplot(1,3,2)
rectangle('Position',[0 0 2 4],'Curvature',0.8)
axis equal
subplot(1,3,3)
rectangle('Position',[0 0 2 4],'Curvature',1)
axis equal
MATLAB doesn't have a builtin circle() or ellipse() function, they're done parametrically which the appearance of the digraph means is probably how it's rendered.
(+) Actually, rectangle can't be what was used here--I'd kinda' forgotten it defines the LLH corner and then width and height, not four corner points.
Timothy
Timothy il y a 38 minutes
Thanks for your help, sorry I didn't communicate properly

Connectez-vous pour commenter.

 Réponse acceptée

Christine Tobler
Christine Tobler le 2 Juil 2026 à 14:41
Here is some example code that looks pretty similar. An easy way to get the curves to stand out less is to change the limits on the x axis:
g = graph([1:4 2:5], [2:5 1:4]);
plot(g, XData=zeros(1, 5), YData=[1 2 4 8 10])
xlim([-5 5])
A digraph object should have arrows to indicate the direction - you are probably using the graph object, like I did above. Here is digraph:
g = digraph([1:4 2:5], [2:5 1:4]);
plot(g, XData=zeros(1, 5), YData=[1 2 4 8 10])
xlim([-5 5])
You mentioned wanting a straight line - in that case, would you want to have just one edge connecting each pair of nodes? The curves are there to allow the two edges to have distinct weights or directions, for example.

4 commentaires

Timothy
Timothy il y a 33 minutes
What I want is to have one line with an arrow pointing both ways to show that it is bidirectional but so that I can still treat it as two separate routes...
I see - so basically you have an undirected graph, and would like to plot arrows pointing both ways for visualization?
The graph object doesn't allow this directly, but the following might be the easiest way to get there:
g = graph(1:4, 2:5, 5:8);
x=zeros(1, 5);
y=[1 2 4 8 10];
% Get directed graph with arrows pointing in one direction
dg = digraph(triu(adjacency(g, 'weighted')));
plot(dg, XData=x, YData=y, EdgeLabel=dg.Edges.Weight);
hold on;
plot(flipedge(dg), XData=x, YData=y, SeriesIndex=1);
This just plots two directed graphs on top of each other, with the direction reversed. SeriesIndex=1 makes both graphs use the same color from the standard color order.
If you want more general changes to how the edges are plotted, your best option would be to plot them directly using a line plot.
Timothy
Timothy il y a environ une heure
Plotting two graphs on top of each other is a novel solution, great idea.
dpb
dpb il y a environ une heure
Modifié(e) : dpb il y a 7 minutes
Actually, with experience you'll find that plotting multiple plots or pieces on top of each other or overlaying axes is a very common coding paradigm with MATLAB handle graphics in order to achieve desired result. As is using artificial NaN entries to be able to hide parts of lines or bars...

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur 2-D and 3-D Plots dans Centre d'aide et File Exchange

Produits

Version

R2024b

Question posée :

le 2 Juil 2026 à 13:08

Modifié(e) :

dpb
il y a environ 7 heures

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by