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

dpb
dpb 대략 11시간 전
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 대략 9시간 전
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 대략 9시간 전
편집: dpb 대략 7시간 전
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 대략 4시간 전
Thanks for your help, sorry I didn't communicate properly

댓글을 달려면 로그인하십시오.

 채택된 답변

Christine Tobler
Christine Tobler 2026년 7월 2일 14:41

0 개 추천

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

Timothy
Timothy 대략 9시간 전
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 대략 4시간 전
Plotting two graphs on top of each other is a novel solution, great idea.
dpb
dpb 대략 11시간 전
편집: dpb 대략 10시간 전
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...

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

제품

릴리스

R2024b

질문:

2026년 7월 2일 13:08

편집:

dpb
대략 12시간 전

Community Treasure Hunt

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

Start Hunting!

Translated by