linux命令行运行matplotlib,在Windows、Linux、Spyder、lin命令下生成matplotlib交互式图形的可移植方法...

以下是一种可行的方法,但并不适用于所有环境:import matplotlib.pyplot as plt

import sys

import matplotlib

def plt_show_interactive():

"""Show plot windows, with interaction if possible; prompt to continue."""

in_ipython = ('get_ipython' in globals())

inline_backend = ('inline' in matplotlib.get_backend())

in_linux = (sys.platform == 'linux')

if inline_backend:

plt.show()

elif not in_linux and in_ipython:

print("Press Ctrl-C to continue.")

try:

while True:

plt.pause(0.5)

except KeyboardInterrupt:

print("Continuing.")

elif in_linux and not in_ipython:

# Command line: plots are interactive during wait for input.

plt.show(block=False)

input("Press ENTER to continue.")

elif in_linux and in_ipython:

# Loop with plt.pause(1) causes repeated focus stealing.

plt.pause(1)

print("Sorry, plots are not interactive until program has finished.")

elif not in_linux and not in_ipython:

# Ctrl-C is handled differently here.

plt.pause(1)

input("Sorry, not interactive. Press ENTER to continue.")

def prompt_if_not_ipython(verb="end"):

"""Ask user to press ENTER if not we're not inside IPython."""

if ('get_ipython' not in globals()):

input("Press ENTER to %s." % verb)

fig, ax = plt.subplots(1, 1, tight_layout=True)

ax.plot([0,1,2],[0,3,2])

plt_show_interactive()

prompt_if_not_ipython()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值