From fda9ced002baa6b04227ebf44d02ea60462c3909 Mon Sep 17 00:00:00 2001 From: Kuan Butts Date: Mon, 4 Jun 2018 16:35:08 -0700 Subject: [PATCH] Adjust the way plot method uses MPL (#75) * Add a description * default agg use for mpl * use agg adjust * use agg trigger adjust * udpate tests --- peartree/__version__.py | 2 +- peartree/paths.py | 8 ++++++++ peartree/plot.py | 14 ++++++-------- tests/test_plot.py | 2 +- 4 files changed, 16 insertions(+), 10 deletions(-) diff --git a/peartree/__version__.py b/peartree/__version__.py index f0ede3d..a987347 100644 --- a/peartree/__version__.py +++ b/peartree/__version__.py @@ -1 +1 @@ -__version__ = '0.4.1' +__version__ = '0.4.2' diff --git a/peartree/paths.py b/peartree/paths.py index e60c152..f8506c1 100644 --- a/peartree/paths.py +++ b/peartree/paths.py @@ -168,6 +168,14 @@ def load_synthetic_network_as_graph( connection_threshold: float=50.0, walk_speed_kmph: float=4.5, impute_walk_transfers: bool=True): + """ + Convert a formatter transit FeatureCollection into a directed network graph. + + Utilizing a correctly formatted transit FeatureCollection, generate a + directed networ graph (or add to an existing one), based off of features + included in the reference_geojson parameter. + """ + # Generate a random name for name if it is None if not name: diff --git a/peartree/plot.py b/peartree/plot.py index 3570cfd..93d8173 100644 --- a/peartree/plot.py +++ b/peartree/plot.py @@ -1,18 +1,16 @@ import os -import matplotlib import networkx as nx import osmnx as ox -# Check if the display has already been set and, if not... -cmd = 'python -c "import matplotlib.pyplot as plt;plt.figure()"' -check = os.system(cmd) -if check != 0: - # Force matplotlib to not use any Xwindows backend - matplotlib.use('Agg') +def generate_plot(G: nx.MultiDiGraph, use_agg=False): + # Load matplotlib only when plot requested + import matplotlib # noqa + if use_agg: + # Force matplotlib to not use any Xwindows backend + matplotlib.use('Agg') -def generate_plot(G: nx.MultiDiGraph): # TODO: Build out custom plotting configurations but, # in the meantime, use OSMnx's plotting configurations # since they work well for the current use case and I diff --git a/tests/test_plot.py b/tests/test_plot.py index c212ae6..e2fca4c 100644 --- a/tests/test_plot.py +++ b/tests/test_plot.py @@ -17,4 +17,4 @@ def test_feed_to_graph_plot(): G = load_feed_as_graph(feed, start, end) - fig, ax = generate_plot(G) + fig, ax = generate_plot(G, use_agg=True)