小编Ved*_*aha的帖子

plt.subplots() 和 plt.figure() 的区别

在 python matplotlib 中,有两个约定用于绘制绘图:

 1. 

plt.figure(1,figsize=(400,8))
Run Code Online (Sandbox Code Playgroud)

 2. 

fig,ax = plt.subplots()
fig.set_size_inches(400,8)
Run Code Online (Sandbox Code Playgroud)

两者都有不同的方式来做同样的事情。例如定义轴标签。

哪个更好用?一个比另一个有什么优势?或者使用 matplotlib 绘制图形的“良好实践”是什么?

matplotlib python-2.7

9
推荐指数
1
解决办法
3819
查看次数

求树直径的线性算法

我有以下代码来查找树的直径:

ALGORITHM: TREE_DIAMETER (T)

maxlength ? 0
for s ? 0 to s < |V[T]|
      do temp ? BSF(T, S)
            if maxlength < temp
                   maxlength ? temp
                   increment s by 1
return maxlength
Run Code Online (Sandbox Code Playgroud)

但是这种算法不能在线性时间内运行.尽可能保留上述代码的细节(例如:使用BSF),是否可以将其优化为线性时间?您可以使用伪代码.

algorithm tree

4
推荐指数
2
解决办法
4799
查看次数

标签 统计

algorithm ×1

matplotlib ×1

python-2.7 ×1

tree ×1