plt.show()仅打印图形,而在stdout

时间:2020-06-18 11:17:39

标签: python matplotlib printing

我正在运行以下python脚本:

import matplotlib.pyplot as plt
%matplotlib inline

list_1=[(0.0002727508544921875, 30.272794723510742), (0.0006632804870605469, 30.036267280578613)]
print("hello world!")
def visualize_runtimes(results, title):
    start, stop = np.array(results).T
    print("start: ", start)
    print("stop:", stop)
    plt.barh(range(len(start)),stop-start,left=start)
    plt.grid(axis='x')
    plt.ylabel("Tasks")
    plt.xlabel("Seconds")
    plt.title(title)
    plt.show()
    return stop[-1]-start[0]

visualize_runtimes(list_1, "Mutli")

但是,仅打印绘图,而省略任何其他print()函数。发生这种情况的原因是什么?

我的输出

enter image description here

我想要的输出,以在标准输出中显示所有print()函数+ plt.show(),无论打印位于函数内部还是外部。

"hello world"
"start: [0.00027275 0.00066328]"
"stop: [30.27279472 30.03626728]"
plot

1 个答案:

答案 0 :(得分:0)

我不确定您的确切目标是什么,但是如果您要查找的是您可能想在函数中放入“ Hello world语句”?