小编chr*_*-sc的帖子

如何收集结构任务输出并打印多个主机的摘要?

在结构中,我有一个任务收集每个主机的东西(小例子).

from fabric.api import task, run, hide
env.hosts['h1', 'h2', 'h3']

@task
def info():
    with hide('everything'):
        info = run("who | tail -n 1")
        print("On host {0} last user was {1}".format(env.host_string, info))
Run Code Online (Sandbox Code Playgroud)

运行

fab info
Run Code Online (Sandbox Code Playgroud)

会给出类似的东西

[h1] Executing task 'info'
On host h1 last user was userXX  pts/29       2015-07-29 15:57 (:0)
[h2] Executing task 'info'
On host h2 last user was userXX  pts/29       2015-07-29 16:57 (:0)
[h3] Executing task 'info'
On host h3 last user was userXX  pts/29       2015-07-29 17:57 (:0)
Run Code Online (Sandbox Code Playgroud)

虽然这适用于3或5个主机,但是很难查看20个或更多主机(或更复杂的输出).我想要做的是累积每个主机的所有输出,并在每个主机上执行任务后最终使用它来创建摘要/概述. …

python fabric

5
推荐指数
1
解决办法
1452
查看次数

在 matplotlib 中放大插图而不重新绘制数据

我正在处理一些 matplotlib 图,需要放大插图。这是可能的zoomed_inset_axesaxes_grid1工具包。请参阅此处的示例:

import matplotlib.pyplot as plt

from mpl_toolkits.axes_grid1.inset_locator import zoomed_inset_axes
from mpl_toolkits.axes_grid1.inset_locator import mark_inset

import numpy as np

def get_demo_image():
    from matplotlib.cbook import get_sample_data
    import numpy as np
    f = get_sample_data("axes_grid/bivariate_normal.npy", asfileobj=False)
    z = np.load(f)
    # z is a numpy array of 15x15
    return z, (-3,4,-4,3)

fig, ax = plt.subplots(figsize=[5,4])

# prepare the demo image
Z, extent = get_demo_image()
Z2 = np.zeros([150, 150], dtype="d")
ny, nx = Z.shape
Z2[30:30+ny, 30:30+nx] = Z

# …
Run Code Online (Sandbox Code Playgroud)

python plot matplotlib

5
推荐指数
1
解决办法
4910
查看次数

标签 统计

python ×2

fabric ×1

matplotlib ×1

plot ×1