def tsplot(series, *args, **kwargs): """Plots the series to the current TimeSeries subplot. If the current plot is not a TimeSeriesPlot, a new TimeSeriesFigure is created.""" # allow callers to override the hold state by passing hold=True|False b = pylab.ishold() h = kwargs.pop('hold', None) if h is not None: pylab.hold(h) # Get the current figure, or create one figManager = _pylab_helpers.Gcf.get_active() if figManager is not None : fig = figManager.canvas.figure if not isinstance(fig, TimeSeriesFigure): fig = tsfigure(series=series) else: fig = tsfigure(series=series) # Get the current axe, or create one sub = fig._axstack() if sub is None: sub = fig.add_tsplot(111,series=series,**kwargs) try: ret = sub.tsplot(series, *args, **kwargs) pylab.draw_if_interactive() except: pylab.hold(b) raise pylab.hold(b) return ret
def tsplot(series, *args, **kwargs): """ Plots the series to the current :class:`TimeSeriesPlot`. If the current plot is not a :class:`TimeSeriesPlot`, a new :class:`TimeSeriesFigure` is created. Parameters ---------- series : TimeSeries The time series to plot %(mandatoryplotargs)s kwargs : var Optional arguments for the creation of the subplot. """ # allow callers to override the hold state by passing hold=True|False b = pylab.ishold() h = kwargs.pop("hold", None) if h is not None: pylab.hold(h) # Get the current figure, or create one figManager = _pylab_helpers.Gcf.get_active() if figManager is not None: fig = figManager.canvas.figure if not isinstance(fig, TimeSeriesFigure): fig = tsfigure(series=series) else: fig = tsfigure(series=series) # Get the current axe, or create one sub = fig._axstack() if sub is None: sub = fig.add_tsplot(111, series=series, **kwargs) try: ret = sub.tsplot(series, *args, **kwargs) pylab.draw_if_interactive() except: pylab.hold(b) raise pylab.hold(b) return ret
def tsplot(series, *args, **kwargs): """ Plots the series to the current :class:`TimeSeriesPlot`. If the current plot is not a :class:`TimeSeriesPlot`, a new :class:`TimeSeriesFigure` is created. Parameters ---------- series : TimeSeries The time series to plot %(mandatoryplotargs)s kwargs : var Optional arguments for the creation of the subplot. """ # allow callers to override the hold state by passing hold=True|False b = pylab.ishold() h = kwargs.pop('hold', None) if h is not None: pylab.hold(h) # Get the current figure, or create one figManager = _pylab_helpers.Gcf.get_active() if figManager is not None: fig = figManager.canvas.figure if not isinstance(fig, TimeSeriesFigure): fig = tsfigure(series=series) else: fig = tsfigure(series=series) # Get the current axe, or create one sub = fig._axstack() if sub is None: sub = fig.add_tsplot(111, series=series, **kwargs) try: ret = sub.tsplot(series, *args, **kwargs) pylab.draw_if_interactive() except: pylab.hold(b) raise pylab.hold(b) return ret
def draw(G, pos=None, ax=None, hold=None, **kwds): """Draw the graph G with Matplotlib (pylab). Draw the graph as a simple representation with no node labels or edge labels and using the full Matplotlib figure area and no axis labels by default. See draw_networkx() for more full-featured drawing that allows title, axis labels etc. Parameters ---------- G : graph A networkx graph pos : dictionary, optional A dictionary with nodes as keys and positions as values. If not specified a spring layout positioning will be computed. See networkx.layout for functions that compute node positions. ax : Matplotlib Axes object, optional Draw the graph in specified Matplotlib axes. hold: bool, optional Set the Matplotlib hold state. If True subsequent draw commands will be added to the current axes. **kwds: optional keywords See networkx.draw_networkx() for a description of optional keywords. Examples -------- >>> G=nx.dodecahedral_graph() >>> nx.draw(G) >>> nx.draw(G,pos=nx.spring_layout(G)) # use spring layout See Also -------- draw_networkx() draw_networkx_nodes() draw_networkx_edges() draw_networkx_labels() draw_networkx_edge_labels() Notes ----- This function has the same name as pylab.draw and pyplot.draw so beware when using >>> from networkx import * since you might overwrite the pylab.draw function. Good alternatives are: With pylab: >>> import pylab as P # >>> import networkx as nx >>> G=nx.dodecahedral_graph() >>> nx.draw(G) # networkx draw() >>> P.draw() # pylab draw() With pyplot >>> import matplotlib.pyplot as plt >>> import networkx as nx >>> G=nx.dodecahedral_graph() >>> nx.draw(G) # networkx draw() >>> plt.draw() # pyplot draw() Also see the NetworkX drawing examples at http://networkx.lanl.gov/gallery.html """ try: import matplotlib.pylab as pylab except ImportError: raise ImportError, "Matplotlib required for draw()" except RuntimeError: print "Matplotlib unable to open display" raise cf=pylab.gcf() cf.set_facecolor('w') if ax is None: if cf._axstack() is None: ax=cf.add_axes((0,0,1,1)) else: ax=cf.gca() # allow callers to override the hold state by passing hold=True|False b = pylab.ishold() h = kwds.pop('hold', None) if h is not None: pylab.hold(h) try: ax.set_axis_off() draw_networkx(G,pos=pos,ax=ax,**kwds) pylab.draw_if_interactive() except: pylab.hold(b) raise pylab.hold(b) return
def draw(G, pos=None, ax=None, hold=None, **kwds): """Draw the graph G with Matplotlib (pylab). Draw the graph as a simple representation with no node labels or edge labels and using the full Matplotlib figure area and no axis labels by default. See draw_networkx() for more full-featured drawing that allows title, axis labels etc. Parameters ---------- G : graph A networkx graph pos : dictionary, optional A dictionary with nodes as keys and positions as values. If not specified a spring layout positioning will be computed. See networkx.layout for functions that compute node positions. ax : Matplotlib Axes object, optional Draw the graph in specified Matplotlib axes. hold : bool, optional Set the Matplotlib hold state. If True subsequent draw commands will be added to the current axes. **kwds : optional keywords See networkx.draw_networkx() for a description of optional keywords. Examples -------- >>> G=nx.dodecahedral_graph() >>> nx.draw(G) >>> nx.draw(G,pos=nx.spring_layout(G)) # use spring layout See Also -------- draw_networkx() draw_networkx_nodes() draw_networkx_edges() draw_networkx_labels() draw_networkx_edge_labels() Notes ----- This function has the same name as pylab.draw and pyplot.draw so beware when using >>> from networkx import * since you might overwrite the pylab.draw function. Good alternatives are: With pylab: >>> import pylab as P # >>> import networkx as nx >>> G=nx.dodecahedral_graph() >>> nx.draw(G) # networkx draw() >>> P.draw() # pylab draw() With pyplot >>> import matplotlib.pyplot as plt >>> import networkx as nx >>> G=nx.dodecahedral_graph() >>> nx.draw(G) # networkx draw() >>> plt.draw() # pyplot draw() Also see the NetworkX drawing examples at http://networkx.lanl.gov/gallery.html """ try: import matplotlib.pylab as pylab except ImportError: raise ImportError("Matplotlib required for draw()") except RuntimeError: print("Matplotlib unable to open display") raise cf=pylab.gcf() cf.set_facecolor('w') if ax is None: if cf._axstack() is None: ax=cf.add_axes((0,0,1,1)) else: ax=cf.gca() # allow callers to override the hold state by passing hold=True|False b = pylab.ishold() h = kwds.pop('hold', None) if h is not None: pylab.hold(h) try: draw_networkx(G,pos=pos,ax=ax,**kwds) ax.set_axis_off() pylab.draw_if_interactive() except: pylab.hold(b) raise pylab.hold(b) return
def draw(G, pos=None, ax=None, hold=None, **kwds): """Draw the graph G with matplotlib (pylab). This is a pylab friendly function that will use the current pylab figure axes (e.g. subplot). pos is a dictionary keyed by vertex with a two-tuple of x-y positions as the value. See networkx.layout for functions that compute node positions. Usage: >>> from networkx import * >>> G=dodecahedral_graph() >>> draw(G) >>> pos=graphviz_layout(G) >>> draw(G,pos) >>> draw(G,pos=spring_layout(G)) Also see doc/examples/draw_* :Parameters: - `nodelist`: list of nodes to be drawn (default=G.nodes()) - `edgelist`: list of edges to be drawn (default=G.edges()) - `node_size`: scalar or array of the same length as nodelist (default=300) - `node_color`: single color string or numeric/numarray array of floats (default='r') - `node_shape`: node shape (default='o'), or 'so^>v<dph8' see pylab.scatter - `alpha`: transparency (default=1.0) - `cmap`: colormap for mapping intensities (default=None) - `vmin,vmax`: min and max for colormap scaling (default=None) - `width`: line width of edges (default =1.0) - `edge_color`: scalar or array (default='k') - `edge_cmap`: colormap for edge intensities (default=None) - `edge_vmin,edge_vmax`: min and max for colormap edge scaling (default=None) - `style`: edge linestyle (default='solid') (solid|dashed|dotted,dashdot) - `labels`: dictionary keyed by node of text labels (default=None) - `font_size`: size for text labels (default=12) - `font_color`: (default='k') - `font_weight`: (default='normal') - `font_family`: (default='sans-serif') - `ax`: matplotlib axes instance for more see pylab.scatter NB: this has the same name as pylab.draw so beware when using >>> from networkx import * since you will overwrite the pylab.draw function. A good alternative is to use >>> import pylab as P >>> import networkx as NX >>> G=NX.dodecahedral_graph() and then use >>> NX.draw(G) # networkx draw() and >>> P.draw() # pylab draw() """ try: import matplotlib.pylab as pylab except ImportError: raise ImportError, "Matplotlib required for draw()" except RuntimeError: pass # unable to open display if pos is None: pos=networkx.drawing.spring_layout(G) # default to spring layout cf=pylab.gcf() cf.set_facecolor('w') if ax is None: if cf._axstack() is None: ax=cf.add_axes((0,0,1,1)) else: ax=cf.gca() # allow callers to override the hold state by passing hold=True|False b = pylab.ishold() h = kwds.pop('hold', None) if h is not None: pylab.hold(h) try: draw_networkx(G,pos,ax=ax,**kwds) ax.set_axis_off() pylab.draw_if_interactive() except: pylab.hold(b) raise pylab.hold(b) return