Giter Site home page Giter Site logo

ericmjl / nxviz Goto Github PK

View Code? Open in Web Editor NEW
450.0 23.0 86.0 3.68 MB

Visualization Package for NetworkX

Home Page: https://ericmjl.github.io/nxviz

License: MIT License

Python 92.34% Shell 5.30% Makefile 0.24% Dockerfile 2.13%
network-visualization networkx network visualization

nxviz's Introduction

nxviz: Composable and rational network visualizations in matplotlib

nxviz is a package for building rational network visualizations using matplotlib as a backend. Inspired heavily by the principles espoused in the grammar of graphics, nxviz provides ways to compose a graph visualization together by adhering to the following recipe:

  1. Prioritize node placement, mapping data to position and visual properties,
  2. Draw in edges, mapping data to visual properties,
  3. Add in annotations and highlights on the graph.

nxviz is simultaneously a data visualization research project, art project, and declarative data visualization tool. We hope you enjoy using it to build beautiful graph visualizations.

Installation

Official Releases

nxviz is available on PyPI:

pip install nxviz

It's also available on conda-forge:

conda install -c conda-forge nxviz

Pre-releases

Pre-releases are done by installing directly from git:

pip install git+https://github.com/ericmjl/nxviz.git

Quickstart

To make a Circos plot:

# We assume you have a graph G that is a NetworkX graph object.
# In this example, all nodes possess the "group" and "value" node attributes
# where "group" is categorical and "value" is continuous,
# and all edges have the "edge_value" node attribute as well.

import nxviz as nv
ax = nv.circos(
    G,
    group_by="group",
    sort_by="value",
    node_color_by="group",
    edge_alpha_by="edge_value"
)

nv.annotate.circos_group(G, group_by="group")

For more examples, including other plots that can be made, please see the examples gallery on the docs.

nxviz's People

Contributors

alirezatheh avatar ashu16993 avatar bcajes avatar cdiener avatar cokelaer avatar earmingol avatar eduardacenteno avatar ericmjl avatar fding253 avatar gitter-badger avatar imgbotapp avatar norakassner avatar pre-commit-ci[bot] avatar pyup-bot avatar rabeez avatar rmkd avatar straussmaximilian avatar thijshrm avatar walter-hernandez avatar yashrajsinh-jadeja avatar zktuong avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

nxviz's Issues

KeyError: Cannot set node orders, grouping or colors according to some node attributes.

  • nxviz version: 0.3.2
  • Python version: 3.6.3
  • Operating System: Windows 7 Enterprise Service Pack 1
  • Using the Jupyter Notebook in Anaconda

Description

nxviz gives me a KeyError when attempting to set node orders and colors according to some of my node attributes. It works for the bipartite and centrality measures, but not for other attributes I've stored (like 'ORGANIZATION' or 'COUNTRY'), although I've confirmed that all these attributes are stored in the same way.

The 'ORGANIZATION' or 'COUNTRY' dictionaries contain strings with the names of countries or organizations of people in the dataset. I wonder if the error is caused by nxviz not being able to read strings as compared to the integers and floats in the centrality dictionaries.

@ericmjl speculated that the reason could be the number of variables exceeding the number of available colors in the colormap. But setting color according to a centrality measure seems to correctly produce a color map with a scale corresponding to measures: nxviz visualization with node color set according to a centrality measure

What I Did

c2 = CircosPlot(G, node_order='degree_centrality', node_grouping='bipartite', node_color='COUNTRY')

---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
<ipython-input-15-4f179e07c4c4> in <module>()
----> 1 c2 = CircosPlot(G, node_order='degree_centrality', node_grouping='bipartite', node_color='MEP')

~\AppData\Local\Continuum\anaconda3\lib\site-packages\nxviz\plots.py in __init__(self, graph, node_order, node_size, node_grouping, node_color, edge_width, edge_color, data_types, nodeprops, edgeprops)
    245                           node_color=node_color, edge_width=edge_width,
    246                           edge_color=edge_color, data_types=data_types,
--> 247                           nodeprops=nodeprops, edgeprops=edgeprops)
    248 
    249     def compute_node_positions(self):

~\AppData\Local\Continuum\anaconda3\lib\site-packages\nxviz\plots.py in __init__(self, graph, node_order, node_size, node_grouping, node_color, edge_width, edge_color, data_types, nodeprops, edgeprops)
     88         if self.node_color:
     89             self.node_colors = []
---> 90             self.compute_node_colors()
     91         else:
     92             self.node_colors = ['blue'] * len(self.nodes)

~\AppData\Local\Continuum\anaconda3\lib\site-packages\nxviz\plots.py in compute_node_colors(self)
    158     def compute_node_colors(self):
    159         """Compute the node colors. Also computes the colorbar."""
--> 160         data = [self.graph.node[n][self.node_color] for n in self.nodes]
    161         data_reduced = sorted(list(set(data)))
    162         dtype = infer_data_type(data)

~\AppData\Local\Continuum\anaconda3\lib\site-packages\nxviz\plots.py in <listcomp>(.0)
    158     def compute_node_colors(self):
    159         """Compute the node colors. Also computes the colorbar."""
--> 160         data = [self.graph.node[n][self.node_color] for n in self.nodes]
    161         data_reduced = sorted(list(set(data)))
    162         dtype = infer_data_type(data)

KeyError: 'MEP'

Don't put a full list of "==" in the requirements.txt used for wheel creation

  • nxviz version: 0.6.0
  • Python version: 3.6.6 (WinPython64-3.6.6.2Qt5.exe)
  • Operating System: Windows 10

Description

Installing nxviz in WinPython distro causes disruption because of the exact constraints "==" imposed in nxviz wheel generates an update of the included numpy-1.15.4+MKL, and the loss of the MKL DLLs.

What I Did

Please reduce your contraints in requirements.txt to what you really need.

see winpython/winpython#723



ImportError: DLL load failed: The specified module could not be found. on WinPython 3.6.6

  • nxviz version: 0.6.0
  • Python version: 3.6.6
  • Operating System: Windows 10

Description

from nxviz import MatrixPlot

Running example code from 2-networkx-basics-instructor.ipynb

What I Did

from nxviz import MatrixPlot

Paste the command(s) you ran and the output.
If there was a crash, please include the traceback here.

from nxviz import MatrixPlot


ImportError Traceback (most recent call last)
in ()
----> 1 from nxviz import MatrixPlot
2
3 m = MatrixPlot(G)
4 m.draw()
5 plt.show()

E:\WPy-3662\python-3.6.6.amd64\lib\site-packages\nxviz_init_.py in ()
----> 1 from nxviz.plots import ArcPlot, CircosPlot, MatrixPlot, GeoPlot # NOQA
2
3 version = "0.6.0"

E:\WPy-3662\python-3.6.6.amd64\lib\site-packages\nxviz\plots.py in ()
15 text_alignment)
16 from .polcart import to_degrees
---> 17 from .utils import (cmaps, infer_data_type, is_data_diverging, items_in_groups,
18 n_group_colorpallet, num_discrete_groups, to_pandas_edges,
19 to_pandas_nodes)

E:\WPy-3662\python-3.6.6.amd64\lib\site-packages\nxviz\utils.py in ()
2
3 import pandas as pd
----> 4 import seaborn as sns
5 from matplotlib.colors import ListedColormap
6 from palettable.colorbrewer import diverging, qualitative, sequential

E:\WPy-3662\python-3.6.6.amd64\lib\site-packages\seaborn_init_.py in ()
4
5 # Import seaborn objects
----> 6 from .rcmod import *
7 from .utils import *
8 from .palettes import *

E:\WPy-3662\python-3.6.6.amd64\lib\site-packages\seaborn\rcmod.py in ()
3 import functools
4 import matplotlib as mpl
----> 5 from . import palettes, _orig_rc_params
6
7

E:\WPy-3662\python-3.6.6.amd64\lib\site-packages\seaborn\palettes.py in ()
10 from .external.six.moves import range
11
---> 12 from .utils import desaturate, set_hls_values, get_color_cycle
13 from .colors import xkcd_rgb, crayons
14

E:\WPy-3662\python-3.6.6.amd64\lib\site-packages\seaborn\utils.py in ()
5
6 import numpy as np
----> 7 from scipy import stats
8 import pandas as pd
9 import matplotlib as mpl

E:\WPy-3662\python-3.6.6.amd64\lib\site-packages\scipy\stats_init_.py in ()
343 from future import division, print_function, absolute_import
344
--> 345 from .stats import *
346 from .distributions import *
347 from .morestats import *

E:\WPy-3662\python-3.6.6.amd64\lib\site-packages\scipy\stats\stats.py in ()
167 from scipy._lib.six import callable, string_types
168 from scipy._lib._version import NumpyVersion
--> 169 import scipy.special as special
170 import scipy.linalg as linalg
171 from . import distributions

E:\WPy-3662\python-3.6.6.amd64\lib\site-packages\scipy\special_init_.py in ()
638 from .sf_error import SpecialFunctionWarning, SpecialFunctionError
639
--> 640 from ._ufuncs import *
641
642 from .basic import *

ImportError: DLL load failed: The specified module could not be found.

node_labels, edge_width, node_size are not working with ArcPlot?

networkx version: 2.0
nxviz version: 0.3.6
Python: 3.5.2
Operating System: Linux-4.4.96+-x86_64-with-Ubuntu-16.04-xenial

Description

I want node labels to show up in the ArcPlot. They don't.

Incidentally, I also want edge_width and node_size to vary by magnitude and they don't.

Am I doing something wrong (i.e. maybe the nodes are big and hide the labels?), or is this a TODO, or should the docs be updated to say this is not supported?

What I Did

import networkx as nx
import nxviz

G = nx.DiGraph()

NODES_EBUNCH = [
    ('A', {'n_visitors': '1'}),
    ('B', {'n_visitors': '3'}),
    ('C', {'n_visitors': '4'}),
]

G.add_nodes_from(NODES_EBUNCH)  # use attr_dict if you don't have to vary e.g. color by node

# An ebunch appears to be a list of 2- or 3-tuples
EDGES_EBUNCH = [
    ('A', 'B', 10),
    ('A', 'C', 20),
    ('B', 'C', 250),
    ('C', 'B', 100),
]

G.add_weighted_edges_from(
    EDGES_EBUNCH,
)

c = nxviz.ArcPlot(G, node_labels=True,
                     node_size='n_visitors',
                     node_color='n_visitors',
                     edge_width='weight')
c.draw()

image

Group label incorrectly positioned

  • nxviz version: 0.3.6
  • Python version: 3.6
  • Operating System: macosx

Description

I have a larger network with group labels, I am trying to label and color the nodes by their respective groups in a Circos plot. When doing this for a network of 1000 nodes and 7 groups, the group labels are not positioned correctly. In particular this occurs when one group is much larger than the others. I would expect the labels (when group label "middle" is used) to appear adjacent to the respective group it is labelled for.

What I Did

import networkx as nx
import nxviz
import numpy as np
import matplotlib.pyplot as plt

G = nx.fast_gnp_random_graph(1000,0.001)
for n,d in G.nodes(data=True):
    a = np.random.uniform()
    if a < 0.70:
        G.node[n]['class'] = "Big"
    elif a < 0.75:
        G.node[n]['class'] = "tiny1"
    elif a < 0.80:
        G.node[n]['class'] = "tiny2"
    elif a < 0.85:
        G.node[n]['class'] = "tiny3"
    elif a < 0.90:
        G.node[n]['class'] = "tiny4"
    elif a < 0.95:
        G.node[n]['class'] = "tiny5"
    else:
        G.node[n]['class'] = "tiny6"

c = nxviz.plots.CircosPlot(G,
                           node_grouping='class',
                           node_color='class',
                           node_order='class',
                           node_labels=False,
                           group_label_position='middle',
                           group_label_color='class'
                           )

c.draw()
plt.show()

randomgraphgrouplabels

AttributeError: 'NodeView' object has no attribute 'index'

  • nxviz version: 0.3.2
  • Python version: 3.6.3
  • Operating System: Windows 7 Enterprise Service Pack 1
  • Using the Jupyter Notebook in Anaconda

Description

When attempting to make any CircosPlot from a NetworkX 2.0 Graph object, I get the following error: "AttributeError: 'NodeView' object has no attribute 'index'". Does this have something to do with NetworkX 2.0 compatibility? I've updated nxviz to the latest github version which lists NetworkX 2.0 in the requirements, so I'm confused as to what's causing this.

What I Did

Here's an example with a random graph.

G3 = nx.Graph()
G3.add_nodes_from(range(10))
G3.add_edges_from([(0,1), (0,3), (2,4), (1,2), (2,7), (0,9), (5,6), (3,8), (1,9), (4,8)])
c3 = CircosPlot(G3)

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-18-97dd4ee1b584> in <module>()
----> 1 c3 = CircosPlot(G3)

~\AppData\Local\Continuum\anaconda3\lib\site-packages\nxviz\plots.py in __init__(self, graph, node_order, node_size, node_grouping, node_color, edge_width, edge_color, data_types, nodeprops, edgeprops)
    245                           node_color=node_color, edge_width=edge_width,
    246                           edge_color=edge_color, data_types=data_types,
--> 247                           nodeprops=nodeprops, edgeprops=edgeprops)
    248 
    249     def compute_node_positions(self):

~\AppData\Local\Continuum\anaconda3\lib\site-packages\nxviz\plots.py in __init__(self, graph, node_order, node_size, node_grouping, node_color, edge_width, edge_color, data_types, nodeprops, edgeprops)
    122 
    123         # Compute each node's positions.
--> 124         self.compute_node_positions()
    125 
    126     def check_data_types(self, data_types):

~\AppData\Local\Continuum\anaconda3\lib\site-packages\nxviz\plots.py in compute_node_positions(self)
    259         self.nodeprops['linewidth'] = radius * 0.01
    260         for node in self.nodes:
--> 261             x, y = get_cartesian(r=radius, theta=node_theta(self.nodes, node))
    262             xs.append(x)
    263             ys.append(y)

~\AppData\Local\Continuum\anaconda3\lib\site-packages\nxviz\geometry.py in node_theta(nodelist, node)
     19     assert node in nodelist, 'node must be inside nodelist.'
     20 
---> 21     i = nodelist.index(node)
     22     theta = -np.pi + i*2*np.pi/len(nodelist)
     23 

AttributeError: 'NodeView' object has no attribute 'index'

Edge width does not work with Circos plots.

  • nxviz version: 0.5.0
  • Python version: 3.5
  • Operating System: Mac OS High Sierra

Description

Thanks a lot for the very nice visualisations!

I tried several ways to set the width of the edges in a circos plot. Until I just tried the code sample that is provided in the library, which does also not work. So I guess there is some bug that got into the library. Could it be that the edge width also does not work for the arc plot? I haven't investigated this further, but I was also not able to do it there.

What I Did

Here is the code I ran and the ouput. It's the same code as in nxviz/examples/circos/edge_width.py

screen shot 2018-11-23 at 23 51 06

What's the right API? Declarative or flexible?

I've been thinking a bit about altair, and how they have a very nice declarative grammar for statistical plots. I think the same can be achieved for nxviz.

Thinking first from the user-facing API, I think a good starting point is to expose something like:

b = BasePlot(G, node_color_by='key_name', edge_color_by='key_name')

Under the hood, we can iterate through all nodes and all edges and their metadata, and use sensible defaults to identify a colour keyword/hexdecimal/RGB value using the matplotlib colour maps.

A dictionary of key-value mapping needs to be stored with the object, such that the keys refer to the metadata value, and the value refers to the keyword/hexdecimal/RGB value.

On the other hand, I can see how this can easily get really messy... the API has to assume as many categories as nodes/edges, and this can mean a really messy colouring/visual. The current API as it stands leaves these details to the user to figure out, and the plotting object only takes care of laying out nodes and edges properly. May be good to stick with this simple case first.

Screenshots!

Description

Hi, I think it would be really useful to have screenshots on the readme. For a visualisation package this makes the first impression and saves the user installing just to see an example.

What do you think?
Many thanks,
Dom

Label for the nodes

  • nxviz version: current version as of July 31 2017
  • Python version: 3.6
  • Operating System: linux

Description

Is there a way for labels for the nodes to show up in the plot?

Thanks!

* nxviz version: 0.6.0

  • nxviz version:
  • Python version:
  • Operating System:

Description

Describe what you were trying to get done.
Tell us what happened, what went wrong, and what you expected to happen.

What I Did

Paste the command(s) you ran and the output.
If there was a crash, please include the traceback here.

Python 3.5 support for f-strings?

  • nxviz version:
    Development version
  • Python version:
    3.5
  • Operating System:
    Ubuntu 16.04

Description

Is there any idea to make the f-string syntax of nxviz backcompatible with Python 3.5?
Unfortunately I cannot import it as I get the following error:

>>> import nxviz
File "/home/user/workspace/nxviz/nxviz/plots.py", line 1112
    .encode(alt.X(f'{self.node_lon}:Q',
                                 ^
SyntaxError: invalid syntax

Issue: building the docs!

The docs aren't built right now. Leaving this issue open so that I have a reminder to build the docs.

colormap changes

Hi,

Would it be possible to expose a cmap kwargs for the respective plots? The accent colours on certain devices make it difficult, especially for colour blind individuals, to distinguish the colours. I used the set13 or paired colormaps from palettable.colorbrewer. It would be nice if the user can supply his/her own colour map.

Bug in __init__

  • nxviz version: 0.3.2
  • Python version: 3.5
  • Operating System: OSX

Description

I was trying to import nxviz into a Jupyter notebook and hit this error.

What I Did

import nxviz as nv

Traceback (most recent call last):

  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/IPython/core/interactiveshell.py", line 2862, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)

  File "<ipython-input-4-0cc1ed72028f>", line 2, in <module>
    import nxviz as nv

  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/nxviz/__init__.py", line 1, in <module>
    from nxviz.plots import ArcPlot, CircosPlot, MatrixPlot  # NOQA

  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/nxviz/plots.py", line 87
    logging.debug(f'INIT: {self.sm}')
                                   ^
SyntaxError: invalid syntax

[DOC] Write Jupyter + conda installation documentation

This is a recurring issue, in that newcomer users do not know how to correctly interact with Jupyter and conda environments.

Leaving this note for myself:

  1. Create conda environment.
  2. Activate conda environment.
  3. Install kernel.
  4. Install package.
  5. Now Jupyter will recognize your kernel, and you will be able to import package.

These docs need to go on Jupyter's website, not individual package maintainer's websites.

Related to #553 and #361.

Polar<-->Cartesian functions

I've uploaded a separate package called polcart, which provides the conversion between (r, theta) and (x, y) coordinates. I decided to separate this portion out because it's so commonly found elsewhere that I thought it'd be a generally useful tool.

The original repo is also available on my GitHub account.

I will start changing the function calls in Circos and Hive to use polcart instead.

Test coverage needs to increase

I'd like to have the test coverage bumped up. We've got a few new features added but they haven't been tested extensively yet.

Importing nxviz fails in python 3.4.3

  • nxviz version: 0.3.4
  • Python version: 3.4.3
  • Operating System: Linux Mint Rosa (Ubuntu based)

Description

I was trying to import nxviz, but I get an invalid syntax.

What I Did

I installed nxviz using pip3 install nxviz, then tried to use it, but it fails to properly import. I am not sure why it fails, a similar mistake only happened to someone else when using python 2.7.

import sys
print(sys.version)
## network graphs
import networkx as nx
import nxviz as nv

Output:

3.4.3 (default, Nov 28 2017, 16:41:13) 
[GCC 4.8.4]
Traceback (most recent call last):

  File "/usr/local/lib/python3.4/dist-packages/IPython/core/interactiveshell.py", line 2910, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)

  File "<ipython-input-36-373cb9dec556>", line 34, in <module>
    import nxviz as nv

  File "/usr/local/lib/python3.4/dist-packages/nxviz/__init__.py", line 1, in <module>
    from nxviz.plots import ArcPlot, CircosPlot, MatrixPlot  # NOQA

  File "/usr/local/lib/python3.4/dist-packages/nxviz/plots.py", line 294
    patch = patches.PathPatch(path, lw=1, **self.edgeprops, zorder=1)
                                                          ^
SyntaxError: invalid syntax

Any idea what could be wrong?

AttributeError: no attribute 'groups'

  • nxviz version: 0.3.6
  • Python version: 3.6
  • Operating System: macosx

Description

Running the examples in the git examples folder generates an attribute error, after a fresh install from the git repo.

What I Did

(test-nxviz) ╭─[~/git/nxviz/examples/circos]─[jq2@sweetgum]─[0]─[10891]
╰─[:)] % python barbell.py
Traceback (most recent call last):
  File "barbell.py", line 16, in <module>
    c.draw()
  File "/Users/jq2/miniconda/envs/test-nxviz/lib/python3.6/site-packages/nxviz/plots.py", line 182, in draw
    if self.groups:
AttributeError: 'CircosPlot' object has no attribute 'groups'

importing nxviz fails in python 2.7

  • nxviz version:
  • Python version: 2.7
  • Operating System: Ubuntu 16.04

Description

I installed nxviz as sudo pip install nxviz (no error)
but when I try to import it in IPython it says:

In 1 : import nxviz as nv
File "/usr/local/lib/python2.7/dist-packages/nxviz/plots.py", line 232
patch = patches.PathPatch(path, lw=1, **self.edgeprops, zorder=1)
^
SyntaxError: invalid syntax

What I Did

In Python 3 the issue does not appear

edge_color and Node_size not changing with keys

  • nxviz version: 0.3.5
  • Python version:3.6.3
  • Operating System: Windows-7

Description

I was trying to pass attribute keys for costuming node_size and edge_color.
However, don't see any changes in the in the plot neither received an error or exception.

What I Did

c_sol_set = nv.CircosPlot(ticket_graph,
    node_color='Resolution_Set_Name', 
    node_grouping = 'Resolution_Set_Name',
    node_order = 'dc',
    node_size = 'dc',
    edge_color='Ticket_Log_Parse.Active_Org',
    node_labels=True,figsize = (15,15) )

c_sol_set.draw()
plt.show()

Paste the command(s) you ran and the output.
If there was a crash, please include the traceback here.

image

edge labels in CircosPlot

Hi,

I'm trying to set edge labels in a CircosPlot (see under) via the edgeproperties argument, but I don't know which matplotlib line property I should use for it. Do you have any idea how this could be done? I'm aware of
the fact that this will result in serious overplotting, but I need the information at least temporarily to interpret the CircosPlot. Maybe a legend would be a solution to deal with the eventual overplotting?

c = CircosPlot(G, node_color='prestroke_GDS_T0', node_order='network_group_id', node_grouping='prestroke_GDS_T0', group_label_position='middle', edge_color='color', figsize=(30,30), edgeprops={'facecolor':'None','alpha':0.2,'label':'network_group_id'})

gds_net

Node color issues - accent errors

  • nxviz version: 0.3.1
  • Python version: 3.6

Description

Attempt to add colour to Arcmap fails

What I Did

Invalid Accent colormap errors result when running ArcPlot(M, node_color='Category', node_order='degree') on more than a certain number of categories.

Error when attempting to create Circos plot

  • nxviz version: 2.1
  • Python version: 3.5.2 |Anaconda 4.2.0 (64-bit)| (default, Jul 5 2016, 11:41:13) [MSC v.1900 64 bit (AMD64)]
  • Operating System: Windows 10
  • Browser: Firefox 61.0.1 (64-bit)

Description

Hi Eric,
You saw this in person at the tutorial at SciPy, but here's a ticket for your reference.
I get an error when trying to produce a Circos plot using the code in cell 3 from the notebook 4-cliques-triangles-structures-student.ipynb from the SciPy 2018 Network Analysis tutorial.

What I Did

# Make a Circos plot of the graph
from nxviz import CircosPlot

c = CircosPlot(G)
c.draw()

Yielded error:


AttributeError Traceback (most recent call last)
in ()
2 from nxviz import CircosPlot
3
----> 4 c = CircosPlot(G)
5 c.draw()

C:\Users\Kelly\Anaconda3\lib\site-packages\nxviz\plots.py in init(self, graph, node_order, node_size, node_grouping, node_color, edge_width, edge_color, data_types, nodeprops, edgeprops)
183 node_color=node_color, edge_width=edge_width,
184 edge_color=edge_color, data_types=data_types,
--> 185 nodeprops=nodeprops, edgeprops=edgeprops)
186
187 def compute_node_positions(self):

C:\Users\Kelly\Anaconda3\lib\site-packages\nxviz\plots.py in init(self, graph, node_order, node_size, node_grouping, node_color, edge_width, edge_color, data_types, nodeprops, edgeprops)
85
86 # Compute each node's positions.
---> 87 self.compute_node_positions()
88
89 def check_data_types(self, data_types):

C:\Users\Kelly\Anaconda3\lib\site-packages\nxviz\plots.py in compute_node_positions(self)
197 self.nodeprops['linewidth'] = radius * 0.01
198 for node in self.nodes:
--> 199 x, y = get_cartesian(r=radius, theta=node_theta(self.nodes, node))
200 xs.append(x)
201 ys.append(y)

C:\Users\Kelly\Anaconda3\lib\site-packages\nxviz\geometry.py in node_theta(nodelist, node)
13 assert node in nodelist, 'node must be inside nodelist.'
14
---> 15 i = nodelist.index(node)
16 theta = -np.pi + i2np.pi/len(nodelist)
17

AttributeError: 'NodeView' object has no attribute 'index'

difficulty importing nxviz in Python 3.6.5

  • nxviz version: (unsure)
  • Python version: 3.6.5
  • Operating System: Windows 7 (using Jupyter Notebook through Anaconda)

Description

I am trying to visualize my data in a network, and so began working with the networkx module in Python 3.6.5. The import of networkx worked just fine, but when I attempted to import the nxviz module as well, I received an error message (see below).

What I Did

import nxviz as nv

---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-2-870a416d29dd> in <module>()
----> 1 import nxviz as nv

ModuleNotFoundError: No module named 'nxviz'

Any help would be greatly appreciated!

circos plot with multiple rings

One of the features of circos plots is the ability to draw multiple ideograms on a plot. None of the examples show this and I'm not clear if this is supported by NetworkX or nxviz. Is this possible?

I basically want to series of chromosomes, then draw another circle within the first that represent subsections of each chromosome.

Before I embark on trying to do this, I was hoping to see an example of this just to find out if its possible.

CircosPlot of a 2-node graph plots both nodes over each other

The CircosPlot does something weird when made with just two nodes. Both nodes are plotted over each other.

x = nx.Graph()
x.add_node(1)
x.add_node(2)
nxv.CircosPlot(x, node_labels=True).draw()

image

The positioning is fine with 3 nodes. I'm not sure what the correct solution to this would be since a 'circular path' with just 2 nodes isn't really possible.

Value Error while trying to color the nodes in CircosPlot

  • nxviz version: 0.4.0
  • Python version:2.7
  • Operating System:Ubuntu 16.04 LTS
    *Networkx version: 2.1

Description

I am trying to colour the nodes based on an attribute 'type' in my nodes data.

What I Did

from nxviz.plots import CircosPlot as cp
c = cp(G,node_order='type',figsize = (10,10),node_color='type')
c.draw()
plt.show()

However there is no error when I use 'type' for node_order. 


NodeDataView({'RSC_2o1a': {'lat': u'28.8047', 'type': u'NRI', 'long': u'77.6823', 'afftype': u'R_C', 'label': 'RSC_2o1a'}, 'UNI_4w2u': {'lat': u'22.2994', 'type': u'SU', 'long': u'73.2081', 'afftype': u'UNI', 'label': 'UNI_4w2u'}  ### part of the node dictionary for my graph G showing the parameters

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-71-2063bccbaa5e> in <module>()
      7 print len(rem)
      8 G.remove_edges_from(edwt)
----> 9 c = cp(G,node_order='type',figsize = (10,10),node_color=str('type'))
     10 c.draw()
     11 plt.show()

/home/user1/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/nxviz/plots.pyc in __init__(self, graph, **kwargs)
    458 
    459         #
--> 460         super(CircosPlot, self).__init__(graph, **kwargs)
    461 
    462     def compute_group_label_positions(self):

/home/user1/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/nxviz/plots.pyc in __init__(self, graph, node_order, node_size, node_grouping, group_order, node_color, node_labels, edge_width, edge_color, data_types, nodeprops, edgeprops, node_label_color, group_label_position, group_label_color, **kwargs)
    131         if self.node_color:
    132             self.node_colors = []
--> 133             self.compute_node_colors()
    134         else:
    135             self.node_colors = ["blue"] * len(self.nodes)

/home/user1/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/nxviz/plots.pyc in compute_node_colors(self)
    237             data_reduced = list(unique_everseen(data))
    238 
--> 239         dtype = infer_data_type(data)
    240         n_grps = num_discrete_groups(data)
    241 

/home/user1/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/nxviz/utils.pyc in infer_data_type(data_container)
     72 
     73     else:
---> 74         raise ValueError("Not possible to tell what the data type is.")
     75 
     76 

ValueError: Not possible to tell what the data type is.

​

Docs not properly built

Trying to determine how to use this package, but the docs appear to be missing, well, just about everything. The usage page gives a single blurb that's not too helpful, and I think the API docs aren't being built properly.

There aren't many options for Circos plots in python, plotly is the only other option I know of, but it's quite involved and rather limited in some ways. This looks like a good alternative, but reading the docstrings and trying to piece together use cases is proving difficult.

CircosPlot node_label and group_labels overlap

Choosing to show both the node and group labels causes them to overlap. This is from the examples folder (slightly modified):

G = nx.barbell_graph(m1=10, m2=3)
for n, d in G.nodes(data=True):
    G.node[n]["class"] = choice(["a", "b", "c", "d", "e"])
c = CircosPlot(
    G,
    node_grouping="class",
    node_color="class",
    node_order="class",
    node_labels=True,
    group_label_position="middle"
)
c.draw()
plt.show()

before

MatrixPlot node_grouping issue

  • nxviz version: 0.6.0
  • Python version: 3.7.2
  • Operating System: Windows 10 Pro 64-bit

Description

Describe what you were trying to get done.
Tell us what happened, what went wrong, and what you expected to happen.

I'm doing the course on DataCamp regarding NetworkX Part 1, the last chapter with the case study on GitHub network data. I am also running this on my local machine as well and this is where I encounter the issue. I have managed to get to the Visualisation bit without any issues but when I try to replicate the MatrixPlot on my local machine the node_grouping

What I Did

# Import necessary modules
from nxviz import MatrixPlot
import matplotlib.pyplot as plt

# Calculate the largest connected component subgraph: largest_ccs
largest_ccs = sorted(nx.connected_component_subgraphs(G), key=lambda x: len(x))[-1]

# Create the customized MatrixPlot object: h
h = MatrixPlot(graph=largest_ccs, node_grouping='grouping')

# Draw the MatrixPlot to the screen
h.draw()
plt.show()

This results in a KeyError: 'grouping' on my local machine. Is there something I am doing wrong?

Contributing Guidelines -- conda environment setup

Hello!

Description

In step 3 of the contributing guidelines, there are instructions for setting up your environment using virtualenvwrapper. I noticed there's an environment.yml file as well -- is it equivalent to use that file to set up a conda environment?

What I Did

conda env create -f environment.yml

Scaling plots

Hi,

Maybe I am overseeing something, but I can not find out how to scale my network graphs to a different size than the standard size. How do I make it bigger?

polar histogram around Circos Plot

  • nxviz version: just downloaded
  • Python version: 3.3.3 downloaded with Anaconda
  • Operating System: Windows

Description

I would like to know whether it is possible to draw a polar histogram around a Circos Plot with nxviz. I found such a graph applied only to genomics, but I think it could be a neat way to visualize one more of the nodes' metadata in any field. Also a traditional histogram below an Arc Plot would work, I suppose.

I would very much appreciate any help or suggestion (relatively new to Python here, my only knowledge comes from DataCamp courses).

Node positions array/dict for post processing

I really like the visuals of the nxviz graphs over some of the networkx ones. However, in networkx I can easily access the node positions to add some additional annotations to the nodes, since the process requires me add their location explicitly. Could that be a thing for nxviz too?

Status update 5 January 2017

  • nxviz version: development
  • Python version: 3.5
  • Operating System: Mac OS X
  • Focus on Circos plots right now. Wrote a function that allows us to automatically compute plot radius from node radius and number of nodes on a graph.

group not alphabetically

Hi Eric,
recently I run into a problem regarding the grouping. By default the grouping is resorting the groups alphabetically. Wouldn't it be better to keep a certain oder or to have an option to control this order?
Thanks
Nora

nxviz doesn't work with networkx 2.4 due to a regression

  • nxviz version: 0.6.1
  • Python version: 3.7.4
  • Operating System: Linux

Description

The following example doesn't work with networkx 2.4 :

from random import choice

import matplotlib.pyplot as plt
import networkx as nx
from nxviz.plots import CircosPlot

G = nx.barbell_graph(m1=10, m2=3)
for n, d in G.nodes(data=True):
    G.nodes[n]["class"] = choice(["a", "b", "c", "d", "e"])
    
c = CircosPlot(
    G,
    node_color="class"
)
c.draw()

It returns the following exception:

AttributeError: 'Graph' object has no attribute 'node'

How to solve

I installed networkx 2.3 and it works. As you can see Graph.node is depreacted :
https://networkx.github.io/documentation/stable/release/release_2.4.html#deprecations

Specify edge_color and node_color?

  • nxviz version: 0.6.1
  • Python version: 3.7.3
  • Operating System: Windows 10

Description

I was wondering if there was any way to manually select the different colors when creating a plot and adding edge_color or node_color to a key/value pair.

In my case, I have 2 different types of edges named 'destination' and have set edge_color = 'destination' which works to color the two types differently, but would prefer a different set of colors than the default colors (in this case greenish/pinkish)

Do you know how to manually define the different colors (maybe even for specific values)?

Uniform types in set_nodecolors

Here is an excerpt the docstring provided for BasePlot.set_nodecolors:

"""
If `nodecolors` is a `string`, all nodes will carry that color.
If `nodecolors` is a `list` or `tuple`, then nodes will be coloured in
order by the list or tuple elements.
If `nodecolors` is a `dict`, then the keys have to be all present in
the nodelist.
By default, node color is blue.
"""

Then, the code is filled with asserts according to the mentioned rules.

This approach is fine, but I'm not a huge fan of overloading a function and then forking its behavior based on its arguments. I have some experience with Mathematica, where this practice is used to the extent that built-in functions change behavior not only on the type of their arguments but also on their shape. Debugging them is not a very fun exercise.


Here is what hypothetical calls to set_nodecolors would look like:

plot = BasePlot(nodes=range(6))

# string: all the same
plot.set_nodecolors('blue')

# iterable: must preserve order
plot.set_nodecolors(['blue', 'blue', 'blue', 'blue', 'black', 'blue'])

# dict: control over each value
plot.set_nodecolors({0: 'blue', 1: 'blue', 2: 'blue',
                     3: 'blue', 4: 'black', 5: 'blue'})

What I propose is to homogenize the calls and always using dicts:

nodes = range(6)
plot = BasePlot(nodes)

# dict: setting all nodes to the same value is still easy
plot.set_nodecolors({node: 'blue' for node in nodes})

# no iterables!
# user doesn't worry about correct ordering

# dict: control over each value
plot.set_nodecolors({0: 'blue', 1: 'blue', 2: 'blue',
                     3: 'blue', 4: 'black', 5: 'blue'})

The main benefits of this approach is that the code is much shorter and less error-prone, as there are far fewer type-checks and forks that need to be performed at each call (do we only check the type of the argument, or also the length? What about the validity of each color string?) Also, the user doesn't need to worry about the order of iterables being the same as the nodecolors object they are passing.

Right now, even if only one string is being passed, the method ultimately performs self.nodecolors = [nodecolors] * len(self.nodes), which means passing a dict of size equal to the nodelist even in the simplest case will not incur in more memory cost.

I know everything is yet in early stages, but I thought standardizing function signatures is an important design decision to be made from the start.

Cannot install nxviz on anaconda

Hi Eric. I´m having the same issue as @hansenzoe! . I´m trying to install nxviz with python 3.6 on jupyter notebook (Windows 10). This is a virtual environment (the root is python 2.7). Using "!pip install nxviz" on jupyter I get the following error:

ERROR: Cannot uninstall 'PyYAML'. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.

When I try with "! conda install nxviz" or "! conda install -c conda-forge nxviz" (from notebook or the anaconda prompt of the virtual environment) the instalation process never ends.

Do you any idea?

Thanks!

Originally posted by @PyMap in #361 (comment)

Update pip version

Hi,

I am on system where the only way that I can install nxviz using pip from a pypi mirror. The code on pypi doesn't have the group_label_position option for Circosplots. Is it possible to update the pypi code?

I have checked the pip install on other systems (not using the local pypi mirror) and the code is still different.

Imputing "null" values for missing keys?

This is a note left for myself or future contributors, and refers to issue #168.

The end-user of networkx might not necessarily have every key represented on every node. I being opinionated think this is a bad idea, but I also recognize that there may be use cases where this is necessary.

There are two routes for this:

  1. Document clearly that every node has to have the same set of attribute keys.
  2. Silently impute a None value for nodes that don't have an attribute key.

Conda package reference

@ericmjl
I'm guessing that in the docs, you meant to install from the conda-forge channel?

(sr) [me@blah users]$ conda install nxviz
Solving environment: failed

PackagesNotFoundError: The following packages are not available from current channels:

  • nxviz

Current channels:

To search for alternate channels that may provide the conda package you're
looking for, navigate to

https://anaconda.org

and use the search bar at the top of the page.

plotting into figure and axis

  • nxviz version: 0.5.0
  • Python version: 3.6.6
  • Operating System: LInux

Description

I would like to plot into figure and axis instead of having a new figure created automatically. Apparently it is not possible to specify those as parameter.

As workaround, I did:

fig, axi = plt.subplots(1, 1, num=1)
cp = nv.CircosPlot(G);
plt.close(); # remove the figure automatically created by nv
cp.figure=fig;
cp.ax=axi;
cp.draw();
plt.show();

This works more or less if only one subplot is made. For several subplots, and if colorbars are created (automatically), it does not work well.

TODO: Implement hiveplot

hiveplot remains the only major plot not yet re-implemented over from the original hiveplot repository. Latest changes are in the api-redesign branch.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.