工具

您所在的位置:网站首页 中国国家队历届10号球衣是谁 工具

工具

2023-09-23 04:00| 来源: 网络整理| 查看: 265

说明

默认情况下,在pycharm中用matplotlib绘制的图形在窗口内,是静态的: 在这里插入图片描述

弹出窗口设置

绘制动态图,需先进行相关设置:File–>Settings–>Tools–>Python Scientific–>Show plots in tool window(取消打勾): 在这里插入图片描述 在这里插入图片描述

代码

利用plt.ion() 开启一个画图的窗口,用于实时更新图表;利用plt.pause(0.5) 设置暂停时间,太快的话图表无法正常显示;利用plt.show()显示图片,防止闪退 示例如下:

# encoding: utf-8 # @author:Jackson # @file:1.py # @time:2021/2/24 22:21 import numpy as np import matplotlib.pyplot as plt from scipy.special import jn from IPython.display import display, clear_output import time x = np.linspace(0,5) f, ax = plt.subplots() ax.set_title("Bessel functions") plt.ion() # 开启一个画图的窗口,用于实时更新图表 for n in range(1,10): time.sleep(1) ax.plot(x, jn(x,n)) clear_output(wait=True) display(f) plt.pause(0.5) # 设置暂停时间,太快的话图表无法正常显示 # plt.ioff() # 关闭画图的窗口 plt.show() # 显示图片,防止闪退 # close the figure at the end, so we don't get a duplicate # of the last plot plt.close()

在这里插入图片描述



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3