Skip to main content

Mediaviz

Mediaviz is a network visualization library created for my project Automating Network Visualization and community detection of Media Sources Network from Mediacloud data done with Berkman Klein Center of Internet And Society at Harvard University while participating at Google Summer Of Code 2018 under the guidance of mentor Hal Roberts.

Mediacloud is an open source, open data platform for researchers that provides data and statistics for quantitative analysis. Mediaviz has been originally developed to automate the network visualization of the media source networks for different topics such as network neutrality, ebola and more.

However, beyond the mediacloud usage, Mediaviz is also a general purpose network visualization library provides functionalities for force based layout such as force atlas 2, automatic scaling to prevent node overlap, Gephi like features for network filtering, coloring, node resizing, prevention of label overlap and community visualization.

Mediaviz uses force atlas 2 layout as default and scales the layout automatically for graphs with 100-1000 nodes that has a power law linking structure. Having sensible defaults, Mediaviz can be used for general graph visualization as well as publishable graphs with many customization parameters including using the drawing function with any other network layout function in networkx or beyond.

Examples and demo visualizations are provided in the usage section.

Documentation

Complete Documentation is available at https://mediaviz.readthedocs.io/en/latest/

Installation

To install the package from pip :

pip install mediaviz

To build from source , download the repository and go to the Mediaviz top level directory. Then use

python setup.py install 

or

pip install .

Dependencies

Blog Posts

Usage

Draw a Network with Force Atlas 2 Layout With Default Parameters

import networkx as nx
from mediaviz.draw import draw_forceatlas2_network

path= 'graphname.gexf'
G = nx.erdos_renyi_graph(200,0.7)

draw_forceatlas2_network(G,node_color='purple', node_size=10, edge_color='gray',filename="random.png")

Drawing Network with Force Atlas 2 Layout with customization

Here we parse color codes from .gexf visual attributes.

import networkx as nx
from mediaviz.draw import draw_forceatlas2_network
from mediaviz.viz_parser import parse_colors, parse_size

# 1000 node graph from mediacloud on network neutrality topic
path = "network_neutrality.gexf" 
G = nx.read_gexf(path)
node_colors = list(parse_colors(path,hex=True).values())
draw_forceatlas2_network(G,
     num_labels = 30, # num_labels indicates to only label top 30 largest nodes by node_size
     fa2l_scaling_ratio=40,fa2l_iterations=100, # parameters for the force atlas 2 layout
     node_color = node_colors, 
     with_labels=True, label_field="label",
     filter_by="inlink_count", top=200, # filter to get top 200 nodes sorted by inlink_count
     size_field = "inlink_count",min_size=0.1,max_size=200, # resize by inlink_count
     adjust_labels=True, # adjusts labels to prevent label overlap
     node_opacity=0.8, edge_opacity=0.01, 
     font_size=6, # size of label font_size 
     filename= "network_neutrality.png", title="network_neutrality",
     edge_color_by_source=True)

Drawing Network With Community Detection and Coloring By Community Partitions

import community
import networkx as nx
from mediaviz.community_utils import get_community_graph, get_community_colormap
from mediaviz.draw import draw_forceatlas2_network

G = nx.florentine_families_graph() 
# get the community partitions and set partition as an attribute for the nodes 
G, partitions = get_community_graph(G) 
# colormaps are automatically assigned for each partition as randomly genererated hex colors
colormap = get_community_colormap(partitions)
# use the draw function as usual with forceatlas2 layout as default
draw_forceatlas2_network(
        G,
        color_by="partition", colormap=colormap,
        node_size = 10,
        with_labels=True, 
        edge_color_by_source=True, node_opacity = 1, edge_opacity = 1,
        font_size=10, filename = "community.png",
        figsize=(10, 10));

Only Using Draw Function for Customized Visualization With Other Layout Algorithms

import networkx as nx
from mediaviz.draw import draw_forceatlas2_network
G = nx.karate_club_graph()
pos = nx.spring_layout(G)
draw_forceatlas2_network(G,
                         pos = pos,
                         node_size=10,
                         color_by="club",
                         colormap={"Officer":"r","Mr. Hi":"b"},
                         node_opacity=1,edge_opacity=1, filename="karate_club.png",
                         edge_color="lightgray")

Contribution and Further Improvement

If you want to contribute please send a pull request with listing the changes you have made and the reasoning clearly stated. Integrating the drawing function with matplotlib better and trying out different heuristics for automated scaling would be a priority.

License

This project is licensed under the MIT License - see the License.txt file for details.

Metadata

Release files for mediaviz 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mediaviz 0.1.2
File Size Uploaded
mediaviz-0.1.2.tar.gz 12.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for mediaviz 0.1.2
File Interpreter ABI Platform
mediaviz-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 27.3 kB

Release files / mediaviz-0.1.2.tar.gz

Download URL mediaviz-0.1.2.tar.gz
Size 12.7 kB
Tags Source
SHA-256 checksum
How to use checksums
3c34a21648bafc7550fbc448644dc90da8aec6d8b786167c29cf7207ac469703
BLAKE2b-256 checksum
How to use checksums
1de173faec80caa9f8026ae048ddd0f5ca1ed7c6877e90104bfa786605cea080
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.11.0 pkginfo/1.4.2 requests/2.18.4 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.23.4 CPython/3.6.5

Release files / mediaviz-0.1.2-py3-none-any.whl

Download URL mediaviz-0.1.2-py3-none-any.whl
Size 14.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ea75098f34e676ea89628ed6cf38b540cc0ba5210ec0957ca75132bda36a1baf
BLAKE2b-256 checksum
How to use checksums
5b81f47f08c100aeee149eba3efee306b750c5530b4e41e4dd7904783e4fe0c2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.11.0 pkginfo/1.4.2 requests/2.18.4 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.23.4 CPython/3.6.5

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files

0.1.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page