Shape of lines on a graph plot

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 Comments

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.
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
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.
Thanks for your help, sorry I didn't communicate properly

Sign in to comment.

 Accepted Answer

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.

3 Comments

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.
Plotting two graphs on top of each other is a novel solution, great idea.

Sign in to comment.

More Answers (0)

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Products

Release

R2024b

Asked:

about 23 hours ago

Commented:

about 3 hours ago

Community Treasure Hunt

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

Start Hunting!