首页 > 编程知识 正文

matplotlib交互式可视化,proe绘图模块

时间:2023-05-05 09:43:23 阅读:17878 作者:474

当前有效的matplotlib版本是3.4.1。

在交互式模式matplotlib下使用交互式后端可以实现交互式绘制。

在交互模式下,新创建的图表会立即显示,在修改图表时(即执行新的绘制语句时)会立即重新绘制原始图表,而matplotlib.pyplot.show ()不会阻止显示。 shell可以输入新命令。

在非交互模式下,新创建或修改的图表不会立即显示,而是仅在运行matplotlib.pyplot.show ()时显示。 matplotlib.pyplot.show ) )将阻止显示。 此时shell无法输入新命令。

也就是说,交互模式的最大特点是每次运行绘制命令时都重新绘制图形。

小心! 交互模式不仅必须切换到支持交互模式的后端,而且必须在特定的REPL shell上运行。 官方网站明确表示支持IPython和python shell,不支持IDLE。 要在jupyter notebook或jupyter lab上支持交互式绘制模式,必须安装ipympl软件包(真名为jupyter-matplotlib )。

交互模式依赖函数交互绘制模式开关由运行时参数interactive控制,值类型为布尔值,默认值为False。

在matplotlib.pyplot模块中,可以使用isinteractive、ion和ioff等函数来管理交互式混合模式。

matplotlib.py plot.is interactive (:查询交互式绘图模式的状态。 matplotlib.pyplot.ion (:打开交互式绘制模式。 matplotlib.pyplot.ioff (:关闭交互式绘图。 安装matplotlib.py plot.install _ repl _ display hook (:matplotlib显示挂接,控制权转移到shell上后立即重新绘制形状,然后重新绘制IPython和传统pytlib matplotlib.py plot.uninstall _ repl _ display hook () :卸载matplotlib以显示挂接。 相关源代码matplotlib包defis _ interactive (: returnrcparams [ ' interactive ' ] def interactive ) b ) : rcparams [ ' definteractive ) 3360 rcparams (inte=b matplotlib.py plot模块defis interactive (: returnmatplotlib.is _ interactive ) 0 return _ ion context (class _ ioff context : def _ init _ (self ) : self.was interactive=is interactive unionstall _ __exit_ ) self,exc_type, exc _ trace back (3360 if self.was interactive : matplotlib.interactive (true ) install_repl_displayhook ) else 3360 ontext:def_init_(self ) : self.was interactive=is interactive install _ repl _ display hook (def _ enter _ 跟踪后退(3360 if not self.was interactive : matplotlib.interactive (false ) uninstall_repl_displayhook ) ) else333

导入matplotlib.pyplot模块。 使用matplotlib.pyplot.ion ()函数打开交互式绘制模式。 键入PLT.plot ([ 1,1 ] )绘制直线,并在执行命令后立即在弹出窗口中显示绘制结果。 可以通过在壳上键入plt.title('123 ' )继续绘制标题,而无需关闭窗口。 窗口中的图形将自动重新绘制以添加标题。 注意:关闭绘图窗口不会关闭交互式绘图模式。 关闭绘图窗口后,再次运行绘图命令与绘制新图元相同。 退出python shell时,交互式绘制模式将关闭。

从比较中可以看出,在交互式混合模式下运行混合命令时,图表将立即显示,而不运行show (),然后运行其他混合命令时图表将立即修改。 在非交互混合模式下,执行混合命令不会立即显示图表,并且在运行show ()之前不会显示图表。

在非交互混合模式下,只有在运行show函数后才会显示混合窗口,并且shell被阻止,因此无法输入新的混合命令。

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。