File Exchange

image thumbnail

wgPlot - Weighted Graph Plot (a better version of gplot)

version (185 KB) by Mike Wu
Plot graphs with weighted vertices and weighted edges from a weighted adjacency matrix.


Updated 23 Jun 2009

View License

Plot graphs just like gplot. But allow user to input an adjacency matrix with weighted edges and/or weighted vertices. The Edge weights are mapped to a colormap. The vertex weights are proportional to the vertex size. Using parameter-value pairs, user can even specify the vertex scaling factor, edge width, and the colormap used to show other meta data associated with the vertices. (Couple of the graph included as example were from David Gleich's matlabBGL package.)

Comments and Ratings (14)

hi sir
I cannot run the simple example, I get the following error:

Error using scatter (line 70)
S must be a scalar or a vector of the same length as X.

Error in wgPlot (line 153)

Error in wgPlotDemo (line 17)

what should I do?

Nice and handy extension of gplot !

I have plotted a graph by wgplot. The color of the vortices must correspond the colorbar but it does not
What to do now?


Xinwei Shen


Thanks for this very useful tool.

I have two question to modify this program:

1- What should I do see the results of edges normalized between 0 and 1? As in the fig shown in this page it is between 0.24 to 9.97.

2- What should I do map edge weights to edge width (thickness)rather than edge colormap?


Even after I fixed all the other bugs in wgPlotDemo, the last of the demos uses fruchterman_reingold_force_directed_layout, which was not included in wgPlotDemo. I downloaded that off of the mathBgl package, but that function refers to another function called fruchterman_reingold_mex which was not in that package! So now I'm not sure what to do. Any hints on where to find that function?


I cannot run the simple example, I get the following error:

Error using scatter (line 68)
S must be a scalar or a vector the same length as X.

Error in wgPlot (line 153)


I commented out axesArea to get the network plot into a figure with other subplots and it works exactly as I need it. Work well and fast even for a large number of edges.

Great program. Contains exactly what I'm looking for. I'm just having issues with the vertices having color. I'd like to have them all be a uniform size, but have the color change with weight. Or have both the color and size change would work too. The issue I'm having is that when the weight values are inputted some of the nodes do not show a weight. Any suggestions?


Very useful, nice display, computationally fast. Good job, thank you!

Please apply the following changes:

1. file: wgPlotDemo.m, line: 2, load('cores_example.mat')
2. file: wgPlotDemo.m, line: 46, load('cs-stanford.mat')
3. file: axesArea.m, line: 25, if ishghandle(varargin{1})
4. file: wgPlot.m, line: 150, hV=scatter(coord(qq,1),coord(qq,2),vWt(qq),vrtxCol(qq),'filled');
5. file: wgPlot.m, line: 153, hV=scatter(coord(qq,1),coord(qq,2),vWt(qq),'filled','MarkerFaceColor',[1,0.5,0.2]);


Even for a very simple example, i get an error:

>> wgplot(sprand(10,10,0.2), rand(10,2));

> In wgPlot at 36
In corrcoeff at 44
??? Error using ==> ishghandle
Too many input arguments.

Error in ==> axesArea at 25
if ishghandle(varargin{1},'axes')

Error in ==> wgPlot at 36
axesArea(h,[6 7 5 5]);

What's wrong?


included a missing helper function prh.m

fix bug on plotting colored/sized markers over the default marker when user specify the vertex weight/meta data.

Fixes a minor but that plots all the vertices even when some of them are not connected to any other vertices. Now it only plots vertices that have connections by default when the adjacency matrix has lot of row/columns with no connections.

Added a missing helper file for setting the plot area for plotting the graph. Also updated wgPlot to include parameter-value pairs for specifying the marker style.

Added an missing auxiliary file for setting the axes' plot area. And updated the wgPlot to include a parameter for changing the marker style.

MATLAB Release Compatibility
Created with R2009a
Compatible with any release
Platform Compatibility
Windows macOS Linux

Inspired by: gplotwl, MatlabBGL