python—networkx:各个布局的源代码

Source code for networkx.drawing.layout

方便学习与重新封装

Node positioning algorithms for graph drawing.
"""

copyright (C) 2004-2015 by

Aric Hagberg hagberg@lanl.gov

Dan Schult dschult@colgate.edu

Pieter Swart swart@lanl.gov

All rights reserved.

BSD license.

import collections
import networkx as nx
author = """Aric Hagberg (hagberg@lanl.gov)\nDan Schult(dschult@colgate.edu)"""
all = ['circular_layout','random_layout','shell_layout','spring_layout','spectral_layout','fruchterman_reingold_layout']

def process_params(G,center,dim):

Some boilerplate code.

import numpy as np

if not <a href="https://www.jb51.cc/tag/isinstance/" target="_blank" class="keywords">isinstance</a>(G,nx.Graph):
    empty_graph = nx.Graph()
    empty_graph.add_nodes_from(G)
    G = empty_graph

if center is None:
    center = np.zeros(dim)
else:
    center = np.asarray(center)

if len(center) != dim:
    msg = "length of center coordinates must match dimension of layout"
    raise ValueError(msg)

return G,center

[docs]def random_layout(G,dim=2,center=None):
"""Position nodes uniformly at random in the unit square.

For every node,a position is generated by choosing each of dim
coordinates unifo<a href="https://www.jb51.cc/tag/rml/" target="_blank" class="keywords">rml</a>y at random on the interval [0.0,1.0).

NumPy (http://scipy.org) is <a href="https://www.jb51.cc/tag/required/" target="_blank" class="keywords">required</a> for this function.

P<a href="https://www.jb51.cc/tag/ara/" target="_blank" class="keywords">ara</a>meters
----------
G : NetworkX graph or list of nodes
   A position will be assigned to every node in G.

dim : int
   Dimension of layout.

center : array-like or None
   Coordinate pair around which to center the layout.

Returns
-------
pos : dict
   A dictionary of positions keyed by node

Examples
--------
>>> G = nx.lollipop_graph(4,3)
>>> pos = nx.random_layout(G)

"""
import numpy as np

G,center = process_p<a href="https://www.jb51.cc/tag/ara/" target="_blank" class="keywords">ara</a>ms(G,dim)
shape = (len(G),dim)
pos = np.random.random(shape) + center
pos = pos.astype(np.float32)
pos = dict(zip(G,pos))

return pos

[docs]def circular_layout(G,scale=1,center=None):

dim=2 only

"""Position nodes on a circle.

P<a href="https://www.jb51.cc/tag/ara/" target="_blank" class="keywords">ara</a>meters
----------
G : NetworkX graph or list of nodes

dim : int
   Dimension of layout,currently only dim=2 is supported

scale : float
    Scale factor for positions

center : array-like or None
   Coordinate pair around which to center the layout.

Returns
-------
dict :
   A dictionary of positions keyed by node

Examples
--------
>>> G=nx.path_graph(4)
>>> pos=nx.cir<a href="https://www.jb51.cc/tag/cula/" target="_blank" class="keywords">cula</a>r_layout(G)

Notes
------
This algorithm currently only works in two dimensions and does not
try to minimize edge crossings.

"""
import numpy as np

G,dim)

if len(G) == 0:
    pos = {}
elif len(G) == 1:
    pos = {G.nodes()[0]: center}
else:
    # <a href="https://www.jb51.cc/tag/dis/" target="_blank" class="keywords">dis</a>card the extra angle since it matches 0 <a href="https://www.jb51.cc/tag/radians/" target="_blank" class="keywords">radians</a>.
    theta = np.linspace(0,1,len(G) + 1)[:-1] * 2 * np.pi
    theta = theta.astype(np.float32)
    pos = np.column_stack([np.cos(theta),np.sin(theta)])
    pos = _rescale_layout(pos,scale=scale) + center
    pos = dict(zip(G,pos))

return pos

[docs]def shell_layout(G,nlist=None,center=None):
"""Position nodes in concentric circles.

P<a href="https://www.jb51.cc/tag/ara/" target="_blank" class="keywords">ara</a>meters
----------
G : NetworkX graph or list of nodes

nlist : list of lists
   List of node lists for each shell.

dim : int
   Dimension of layout,currently only dim=2 is supported

scale : float
    Scale factor for positions

center : array-like or None
   Coordinate pair around which to center the layout.

Returns
-------
dict :
   A dictionary of positions keyed by node

Examples
--------
>>> G = nx.path_graph(4)
>>> shells = [[0],[1,2,3]]
>>> pos = nx.shell_layout(G,shells)

Notes
------
This algorithm currently only works in two dimensions and does not
try to minimize edge crossings.

"""
import numpy as np

G,dim)

if len(G) == 0:
    return {}
elif len(G) == 1:
    return {G.nodes()[0]: center}


if nlist is None:
    # draw the whole graph in one shell
    nlist = [list(G.nodes())]

if len(nlist[0]) == 1:
    # single node at center
    radius = 0.0
else:
    # else start at r=1
    radius = 1.0

npos={}
for nodes in nlist:
    # <a href="https://www.jb51.cc/tag/dis/" target="_blank" class="keywords">dis</a>card the extra angle since it matches 0 <a href="https://www.jb51.cc/tag/radians/" target="_blank" class="keywords">radians</a>.
    theta = np.linspace(0,len(nodes) + 1)[:-1] * 2 * np.pi
    theta = theta.astype(np.float32)
    pos = np.column_stack([np.cos(theta),scale=scale * radius / len(nlist)) + center
    npos.update(zip(nodes,pos))
    radius += 1.0

return npos

def fruchterman_reingold_layout(G,k=None,pos=None,fixed=None,iterations=50,weight='weight',scale=1.0,center=None):
"""Position nodes using Fruchterman-Reingold force-directed algorithm.

P<a href="https://www.jb51.cc/tag/ara/" target="_blank" class="keywords">ara</a>meters
----------
G : NetworkX graph or list of nodes

dim : int
   Dimension of layout

k : float (default=None)
   Optimal <a href="https://www.jb51.cc/tag/dis/" target="_blank" class="keywords">dis</a>tance between nodes.  If None the <a href="https://www.jb51.cc/tag/dis/" target="_blank" class="keywords">dis</a>tance is set to
   1/sqrt(n) where n is the number of nodes.  Increase this value
   to move nodes farther apart.


pos : dict or None  optional (default=None)
   Initial positions for nodes as a dictionary with node as keys
   and values as a list or tuple.  If None,then use random initial
   positions.

fixed : list or None  optional (default=None)
  Nodes to keep fixed at initial position.

i<a href="https://www.jb51.cc/tag/tera/" target="_blank" class="keywords">tera</a>tions : int  optional (default=50)
   Number of i<a href="https://www.jb51.cc/tag/tera/" target="_blank" class="keywords">tera</a>tions of spring-force relaxation

weight : string or None   optional (default='weight')
    The edge attribute that holds the numerical value used for
    the edge weight.  If None,then all edge weights are 1.

scale : float (default=1.0)
    Scale factor for positions. The nodes are positioned
    in a <a href="https://www.jb51.cc/tag/Box/" target="_blank" class="keywords">Box</a> of size [0,scale] x [0,scale].

center : array-like or None
   Coordinate pair around which to center the layout.


Returns
-------
dict :
   A dictionary of positions keyed by node

Examples
--------
>>> G=nx.path_graph(4)
>>> pos=nx.spring_layout(G)

# The same using longer function name
>>> pos=nx.fruchterman_reingold_layout(G)
"""
import numpy as np

G,dim)

if fixed is not None:
    nfixed = dict(zip(G,range(len(G))))
    fixed = np.asarray([nfixed[v] for v in fixed])

if pos is not None:
    # Deter<a href="https://www.jb51.cc/tag/mine/" target="_blank" class="keywords">mine</a> size of existing domain to adjust initial positions
    dom_size = max(flatten(pos.values()))
    shape = (len(G),dim)
    pos_arr = np.random.random(shape) * dom_size + center
    for i,n in enumerate(G):
        if n in pos:
            pos_arr[i] = np.asarray(pos[n])
else:
    pos_arr=None

if len(G) == 0:
    return {}
if len(G) == 1:
    return {G.nodes()[0]: center}

try:
    # Sparse matrix
    if len(G) < 500:  # sparse solver for large graphs
        raise ValueError
    A = nx.to_scipy_sparse_matrix(G,weight=weight,dtype='f')
    if k is None and fixed is not None:
       # We must adjust k by domain size for layouts that are not near 1x1
       nnodes,_ = A.shape
       k = dom_size / np.sqrt(nnodes)
    pos = _sparse_fruchterman_reingold(A,dim,k,pos_arr,fixed,i<a href="https://www.jb51.cc/tag/tera/" target="_blank" class="keywords">tera</a>tions)
except:
    A = nx.to_numpy_matrix(G,weight=weight)
    if k is None and fixed is not None:
       # We must adjust k by domain size for layouts that are not near 1x1
       nnodes,_ = A.shape
       k = dom_size / np.sqrt(nnodes)
    pos = _fruchterman_reingold(A,i<a href="https://www.jb51.cc/tag/tera/" target="_blank" class="keywords">tera</a>tions)
if fixed is None:
    pos = _rescale_layout(pos,scale=scale) + center
pos = dict(zip(G,pos))
return pos

spring_layout=fruchterman_reingold_layout

def _fruchterman_reingold(A,iterations=50):

Position nodes in adjacency matrix A using Fruchterman-Reingold

# Entry point for NetworkX graph is fruchterman_reingold_layout()
try:
    import numpy as np
except ImportError:
    raise ImportError("_fruchterman_reingold() requires numpy: http://scipy.org/ ")

try:
    nnodes,_=A.shape
except AttributeError:
    raise nx.NetworkXError(
        "fruchterman_reingold() takes an adjacency matrix as input")

A=np.asarray(A) # make sure we have an array instead of a matrix

if pos==None:
    # random initial positions
    pos=np.asarray(np.random.random((nnodes,dim)),dtype=A.dtype)
else:
    # make sure positions are of same type as matrix
    pos=pos.astype(A.dtype)

# optimal <a href="https://www.jb51.cc/tag/dis/" target="_blank" class="keywords">dis</a>tance between nodes
if k is None:
    k=np.sqrt(1.0/nnodes)
# the initial "temperature"  is about .1 of domain area (=1x1)
# this is the largest step allowed in the dynamics.
# We need to cal<a href="https://www.jb51.cc/tag/cula/" target="_blank" class="keywords">cula</a>te this in case our fixed positions force our domain
# to be much bigger than 1x1
t = max(max(pos.T[0]) - min(pos.T[0]),max(pos.T[1]) - min(pos.T[1]))*0.1
# simple cooling scheme.
# linearly step down by dt on each i<a href="https://www.jb51.cc/tag/tera/" target="_blank" class="keywords">tera</a>tion so last i<a href="https://www.jb51.cc/tag/tera/" target="_blank" class="keywords">tera</a>tion is size dt.
dt=t/float(i<a href="https://www.jb51.cc/tag/tera/" target="_blank" class="keywords">tera</a>tions+1)
delta = np.zeros((pos.shape[0],pos.shape[0],pos.shape[1]),dtype=A.dtype)
# the inscrutable (but fast) version
# this is still O(V^2)
# <a href="https://www.jb51.cc/tag/Could/" target="_blank" class="keywords">Could</a> use multilevel methods to speed this up significantly
for i<a href="https://www.jb51.cc/tag/tera/" target="_blank" class="keywords">tera</a>tion in range(i<a href="https://www.jb51.cc/tag/tera/" target="_blank" class="keywords">tera</a>tions):
    # matrix of difference between points
    for i in range(pos.shape[1]):
        delta[:,:,i]= pos[:,i,None]-pos[:,i]
    # <a href="https://www.jb51.cc/tag/dis/" target="_blank" class="keywords">dis</a>tance between points
    <a href="https://www.jb51.cc/tag/dis/" target="_blank" class="keywords">dis</a>tance=np.sqrt((delta**2).sum(axis=-1))
    # enforce minimum <a href="https://www.jb51.cc/tag/dis/" target="_blank" class="keywords">dis</a>tance of 0.01
    <a href="https://www.jb51.cc/tag/dis/" target="_blank" class="keywords">dis</a>tance=np.where(<a href="https://www.jb51.cc/tag/dis/" target="_blank" class="keywords">dis</a>tance<0.01,0.01,<a href="https://www.jb51.cc/tag/dis/" target="_blank" class="keywords">dis</a>tance)
    # <a href="https://www.jb51.cc/tag/dis/" target="_blank" class="keywords">dis</a>placement "force"
    <a href="https://www.jb51.cc/tag/dis/" target="_blank" class="keywords">dis</a>placement=np.transpose(np.transpose(delta)*\
                              (k*k/<a href="https://www.jb51.cc/tag/dis/" target="_blank" class="keywords">dis</a>tance**2-A*<a href="https://www.jb51.cc/tag/dis/" target="_blank" class="keywords">dis</a>tance/k))\
                              .sum(axis=1)
    # update positions
    length=np.sqrt((<a href="https://www.jb51.cc/tag/dis/" target="_blank" class="keywords">dis</a>placement**2).sum(axis=1))
    length=np.where(length<0.01,0.1,length)
    delta_pos=np.transpose(np.transpose(<a href="https://www.jb51.cc/tag/dis/" target="_blank" class="keywords">dis</a>placement)*t/length)
    if fixed is not None:
        # don't change positions of fixed nodes
        delta_pos[fixed]=0.0
    pos+=delta_pos
    # cool temperature
    t-=dt
return pos

def _sparse_fruchterman_reingold(A,iterations=50):

Position nodes in adjacency matrix A using Fruchterman-Reingold

# Entry point for NetworkX graph is fruchterman_reingold_layout()
# Sparse version
try:
    import numpy as np
except ImportError:
    raise ImportError("_sparse_fruchterman_reingold() requires numpy: http://scipy.org/ ")
try:
    nnodes,_=A.shape
except AttributeError:
    raise nx.NetworkXError(
        "fruchterman_reingold() takes an adjacency matrix as input")
try:
    from scipy.sparse import spdiags,coo_matrix
except ImportError:
    raise ImportError("_sparse_fruchterman_reingold() scipy numpy: http://scipy.org/ ")
# make sure we have a LIst of Lists representation
try:
    A=A.tolil()
except:
    A=(coo_matrix(A)).tolil()

if pos==None:
    # random initial positions
    pos=np.asarray(np.random.random((nnodes,dtype=A.dtype)
else:
    # make sure positions are of same type as matrix
    pos=pos.astype(A.dtype)

# no fixed nodes
if fixed==None:
    fixed=[]

# optimal <a href="https://www.jb51.cc/tag/dis/" target="_blank" class="keywords">dis</a>tance between nodes
if k is None:
    k=np.sqrt(1.0/nnodes)
# the initial "temperature"  is about .1 of domain area (=1x1)
# this is the largest step allowed in the dynamics.
t=0.1
# simple cooling scheme.
# linearly step down by dt on each i<a href="https://www.jb51.cc/tag/tera/" target="_blank" class="keywords">tera</a>tion so last i<a href="https://www.jb51.cc/tag/tera/" target="_blank" class="keywords">tera</a>tion is size dt.
dt=t/float(i<a href="https://www.jb51.cc/tag/tera/" target="_blank" class="keywords">tera</a>tions+1)

<a href="https://www.jb51.cc/tag/dis/" target="_blank" class="keywords">dis</a>placement=np.zeros((dim,nnodes))
for i<a href="https://www.jb51.cc/tag/tera/" target="_blank" class="keywords">tera</a>tion in range(i<a href="https://www.jb51.cc/tag/tera/" target="_blank" class="keywords">tera</a>tions):
    <a href="https://www.jb51.cc/tag/dis/" target="_blank" class="keywords">dis</a>placement*=0
    # loop over rows
    for i in range(A.shape[0]):
        if i in fixed:
            continue
        # difference between this row's node position and all others
        delta=(pos[i]-pos).T
        # <a href="https://www.jb51.cc/tag/dis/" target="_blank" class="keywords">dis</a>tance between points
        <a href="https://www.jb51.cc/tag/dis/" target="_blank" class="keywords">dis</a>tance=np.sqrt((delta**2).sum(axis=0))
        # enforce minimum <a href="https://www.jb51.cc/tag/dis/" target="_blank" class="keywords">dis</a>tance of 0.01
        <a href="https://www.jb51.cc/tag/dis/" target="_blank" class="keywords">dis</a>tance=np.where(<a href="https://www.jb51.cc/tag/dis/" target="_blank" class="keywords">dis</a>tance<0.01,<a href="https://www.jb51.cc/tag/dis/" target="_blank" class="keywords">dis</a>tance)
        # the adjacency matrix row
        Ai=np.asarray(A.getrowview(i).toarray())
        # <a href="https://www.jb51.cc/tag/dis/" target="_blank" class="keywords">dis</a>placement "force"
        <a href="https://www.jb51.cc/tag/dis/" target="_blank" class="keywords">dis</a>placement[:,i]+=\
            (delta*(k*k/<a href="https://www.jb51.cc/tag/dis/" target="_blank" class="keywords">dis</a>tance**2-Ai*<a href="https://www.jb51.cc/tag/dis/" target="_blank" class="keywords">dis</a>tance/k)).sum(axis=1)
    # update positions
    length=np.sqrt((<a href="https://www.jb51.cc/tag/dis/" target="_blank" class="keywords">dis</a>placement**2).sum(axis=0))
    length=np.where(length<0.01,length)
    pos+=(displacement*t/length).T
    # cool temperature
    t-=dt
return pos

[docs]def spectral_layout(G,center=None):
"""Position nodes using the eigenvectors of the graph Laplacian.

Parameters
----------
G : NetworkX graph or list of nodes

dim : int
   Dimension of layout

weight : string or None   optional (default='weight')
    The edge attribute that holds the numerical value used for
    the edge weight.  If None,then all edge weights are 1.

scale : float
    Scale factor for positions

center : array-like or None
   Coordinate pair around which to center the layout.

Returns
-------
dict :
   A dictionary of positions keyed by node

Examples
--------
>>> G=nx.path_graph(4)
>>> pos=nx.spectral_layout(G)

Notes
-----
Directed graphs will be considered as undirected graphs when
positioning the nodes.

For larger graphs (>500 nodes) this will use the SciPy sparse
eigenvalue solver (ARPACK).
"""
# handle some special cases that break the eigensolvers
import numpy as np

G,dim)

if len(G) <= 2:
    if len(G) == 0:
        pos = np.array([])
    elif len(G) == 1:
        pos = np.array([center])
    else:
        pos = np.array([np.zeros(dim),np.array(center)*2.0])
    return dict(zip(G,pos))
try:
    # Sparse matrix
    if len(G)< 500:  # dense solver is faster for small graphs
        raise ValueError
    A = nx.to_scipy_sparse_matrix(G,dtype='d')
    # Symmetrize directed graphs
    if G.is_directed():
        A = A + np.transpose(A)
    pos = _sparse_spectral(A,dim)
except (ImportError,ValueError):
    # Dense matrix
    A = nx.to_numpy_matrix(G,weight=weight)
    # Symmetrize directed graphs
    if G.is_directed():
        A = A + np.transpose(A)
    pos = _spectral(A,dim)

pos = _rescale_layout(pos,scale) + center
pos = dict(zip(G,pos))
return pos

def _spectral(A,dim=2):

Input adjacency matrix A

# Uses dense eigenvalue solver from numpy
try:
    import numpy as np
except ImportError:
    raise ImportError("spectral_layout() requires numpy: http://scipy.org/ ")
try:
    nnodes,_=A.shape
except AttributeError:
    raise nx.NetworkXError(\
        "spectral() takes an adjacency matrix as input")

# form Laplacian matrix
# make sure we have an array instead of a matrix
A=np.asarray(A)
I=np.identity(nnodes,dtype=A.dtype)
D=I*np.sum(A,axis=1) # diagonal of <a href="https://www.jb51.cc/tag/degrees/" target="_blank" class="keywords">degrees</a>
L=D-A

eigenvalues,eigenvectors=np.linalg.eig(L)
# sort and keep smallest nonzero
index=np.argsort(eigenvalues)[1:dim+1] # 0 index is zero eigenvalue
return np.real(eigenvectors[:,index])

def _sparse_spectral(A,dim=2):

Input adjacency matrix A

# Uses sparse eigenvalue solver from scipy
# <a href="https://www.jb51.cc/tag/Could/" target="_blank" class="keywords">Could</a> use multilevel methods here,see Koren "On spectral graph drawing"
try:
    import numpy as np
    from scipy.sparse import spdiags
except ImportError:
    raise ImportError("_sparse_spectral() requires scipy &amp; numpy: http://scipy.org/ ")
try:
    from scipy.sparse.linalg.eigen import eigsh
except ImportError:
    # scipy <0.9.0 names eigsh differently
    from scipy.sparse.linalg import eigen_symmetric as eigsh
try:
    nnodes,_=A.shape
except AttributeError:
    raise nx.NetworkXError(\
        "sparse_spectral() takes an adjacency matrix as input")

# form Laplacian matrix
data=np.asarray(A.sum(axis=1).T)
D=spdiags(data,nnodes,nnodes)
L=D-A

k=dim+1
# number of <a href="https://www.jb51.cc/tag/lanczos/" target="_blank" class="keywords">lanczos</a> vectors for ARPACK solver.What is the right scaling?
ncv=max(2*k+1,int(np.sqrt(nnodes)))
# return smallest k eigenvalues and eigenvectors
eigenvalues,eigenvectors=eigsh(L,which='SM',ncv=ncv)
index=np.argsort(eigenvalues)[1:k] # 0 index is zero eigenvalue
return np.real(eigenvectors[:,index])

def _rescale_layout(pos,scale=1):

rescale to (-scale,scale) in all axes

# shift origin to (0,0)
lim=0 # max coordinate for all axes
for i in range(pos.shape[1]):
    pos[:,i]-=pos[:,i].mean()
    lim=max(pos[:,i].max(),lim)
# rescale to (-scale,scale) in all directions,preserves aspect
for i in range(pos.shape[1]):
    pos[:,i]*=scale/lim
return pos

fixture for nose tests

def setup_module(module):
from nose import SkipTest
try:
import numpy
except:
raise SkipTest("NumPy not available")
try:
import scipy
except:
raise SkipTest("SciPy not available")

def flatten(l):
try:
bs = basestring
except NameError:

Py3k

    bs = str
for el in l:
    if <a href="https://www.jb51.cc/tag/isinstance/" target="_blank" class="keywords">isinstance</a>(el,collections.I<a href="https://www.jb51.cc/tag/tera/" target="_blank" class="keywords">tera</a>ble) and not <a href="https://www.jb51.cc/tag/isinstance/" target="_blank" class="keywords">isinstance</a>(el,bs):
        for sub in flatten(el):
            yield sub
    else:
        yield el</code></pre><a href="https://networkx.github.io/documentation/latest/_modules/networkx/drawing/layout.html" rel="<a href="https://www.jb51.cc/tag/nofollow/" target="_blank" class="keywords">nofollow</a>"&gt;官网</a><br /><br />

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


我最近重新拾起了计算机视觉,借助Python的opencv还有face_recognition库写了个简单的图像识别demo,额外定制了一些内容,原本想打包成exe然后发给朋友,不过在这当中遇到了许多小问题,都解决了,记录一下踩过的坑。 1、Pyinstaller打包过程当中出现warning,跟d
说到Pooling,相信学习过CNN的朋友们都不会感到陌生。Pooling在中文当中的意思是“池化”,在神经网络当中非常常见,通常用的比较多的一种是Max Pooling,具体操作如下图: 结合图像理解,相信你也会大概明白其中的本意。不过Pooling并不是只可以选取2x2的窗口大小,即便是3x3,
记得大一学Python的时候,有一个题目是判断一个数是否是复数。当时觉得比较复杂不好写,就琢磨了一个偷懒的好办法,用异常处理的手段便可以大大程度帮助你简短代码(偷懒)。以下是判断整数和复数的两段小代码: 相信看到这里,你也有所顿悟,能拓展出更多有意思的方法~
文章目录 3 直方图Histogramplot1. 基本直方图的绘制 Basic histogram2. 数据分布与密度信息显示 Control rug and density on seaborn histogram3. 带箱形图的直方图 Histogram with a boxplot on t
文章目录 5 小提琴图Violinplot1. 基础小提琴图绘制 Basic violinplot2. 小提琴图样式自定义 Custom seaborn violinplot3. 小提琴图颜色自定义 Control color of seaborn violinplot4. 分组小提琴图 Group
文章目录 4 核密度图Densityplot1. 基础核密度图绘制 Basic density plot2. 核密度图的区间控制 Control bandwidth of density plot3. 多个变量的核密度图绘制 Density plot of several variables4. 边
首先 import tensorflow as tf tf.argmax(tenso,n)函数会返回tensor中参数指定的维度中的最大值的索引或者向量。当tensor为矩阵返回向量,tensor为向量返回索引号。其中n表示具体参数的维度。 以实际例子为说明: import tensorflow a
seaborn学习笔记章节 seaborn是一个基于matplotlib的Python数据可视化库。seaborn是matplotlib的高级封装,可以绘制有吸引力且信息丰富的统计图形。相对于matplotlib,seaborn语法更简洁,两者关系类似于numpy和pandas之间的关系,seabo
Python ConfigParser教程显示了如何使用ConfigParser在Python中使用配置文件。 文章目录 1 介绍1.1 Python ConfigParser读取文件1.2 Python ConfigParser中的节1.3 Python ConfigParser从字符串中读取数据
1. 处理Excel 电子表格笔记(第12章)(代码下载) 本文主要介绍openpyxl 的2.5.12版处理excel电子表格,原书是2.1.4 版,OpenPyXL 团队会经常发布新版本。不过不用担心,新版本应该在相当长的时间内向后兼容。如果你有新版本,想看看它提供了什么新功能,可以查看Open
1. 发送电子邮件和短信笔记(第16章)(代码下载) 1.1 发送电子邮件 简单邮件传输协议(SMTP)是用于发送电子邮件的协议。SMTP 规定电子邮件应该如何格式化、加密、在邮件服务器之间传递,以及在你点击发送后,计算机要处理的所有其他细节。。但是,你并不需要知道这些技术细节,因为Python 的
文章目录 12 绘图实例(4) Drawing example(4)1. Scatterplot with varying point sizes and hues(relplot)2. Scatterplot with categorical variables(swarmplot)3. Scat
文章目录 10 绘图实例(2) Drawing example(2)1. Grouped violinplots with split violins(violinplot)2. Annotated heatmaps(heatmap)3. Hexbin plot with marginal dist
文章目录 9 绘图实例(1) Drawing example(1)1. Anscombe’s quartet(lmplot)2. Color palette choices(barplot)3. Different cubehelix palettes(kdeplot)4. Distribution
Python装饰器教程展示了如何在Python中使用装饰器基本功能。 文章目录 1 使用教程1.1 Python装饰器简单示例1.2 带@符号的Python装饰器1.3 用参数修饰函数1.4 Python装饰器修改数据1.5 Python多层装饰器1.6 Python装饰器计时示例 2 参考 1 使
1. 用GUI 自动化控制键盘和鼠标第18章 (代码下载) pyautogui模块可以向Windows、OS X 和Linux 发送虚拟按键和鼠标点击。根据使用的操作系统,在安装pyautogui之前,可能需要安装一些其他模块。 Windows: 不需要安装其他模块。OS X: sudo pip3
文章目录 生成文件目录结构多图合并找出文件夹中相似图像 生成文件目录结构 生成文件夹或文件的目录结构,并保存结果。可选是否滤除目录,特定文件以及可以设定最大查找文件结构深度。效果如下: root:[z:/] |--a.py |--image | |--cat1.jpg | |--cat2.jpg |
文章目录 VENN DIAGRAM(维恩图)1. 具有2个分组的基本的维恩图 Venn diagram with 2 groups2. 具有3个组的基本维恩图 Venn diagram with 3 groups3. 自定义维恩图 Custom Venn diagram4. 精致的维恩图 Elabo
mxnet60分钟入门Gluon教程代码下载,适合做过深度学习的人使用。入门教程地址: https://beta.mxnet.io/guide/getting-started/crash-course/index.html mxnet安装方法:pip install mxnet 1 在mxnet中使
文章目录 1 安装2 快速入门2.1 基本用法2.2 输出图像格式2.3 图像style设置2.4 属性2.5 子图和聚类 3 实例4 如何进一步使用python graphviz Graphviz是一款能够自动排版的流程图绘图软件。python graphviz则是graphviz的python实