Digraph EdgeCData not plotting correct color.
Afficher commentaires plus anciens
I am trying to plot a digraph with edges colored using colors from XKCD's color list on the File Exchange. The problem is that the edge colors do not plot correctly. Here is my code:
fig=uifigure; % Initialize a new figure.
load(filePath,'rgblist'); % Load the matrix of rgb triples (N x 3)
% Find which rows in the rgblist matrix contain the correct colors. RGB
% triples are rounded here to account for MATLAB's rounding error.
edgeColorsIdx=NaN(size(Digraph.Edges.Color,1),1);
for i=1:size(Digraph.Edges.Color,1)
edgeColorsIdx(i)=find(ismember(round(rgblist,3),round(Digraph.Edges.Color(i,:),3),'rows')==1);
end
colormap(fig,rgblist); % Set the colormap of the specified figure to rgblist.
% Plot the Digraph with standard blue nodes, and one color per edge.
plot(fig,Digraph,'XData',Digraph.Nodes.Coordinates(:,1),'YData',Digraph.Nodes.Coordinates(:,2),'NodeLabel',Digraph.Nodes.FunctionNames,'NodeColor',[0 0.447 0.741],...
'EdgeCData',edgeColorsIdx);
This code finds the correct color indices, because I can plot them properly using patch or any other type of plot. I also think that the colormap is being properly set, because
isequal(colormap(fig),rgblist)
returns 1. But when plotting the Digraph, it plots the wrong color edges! What am I doing wrong? Thanks!
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Graph and Network Algorithms dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!