国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Python > 正文

不同版本中Python matplotlib.pyplot.draw()界面繪制異常問題的解決

2020-02-16 10:18:13
字體:
來源:轉載
供稿:網友

前言

本文主要給大家介紹了關于不同版本中Python matplotlib.pyplot.draw()界面繪制異常的相關內容,分享出來供大家參考學習,下面話不多說了,來一起看看詳細的介紹吧。

在 Ubuntu系統上進行如下配置:

$ sudo apt-get update$ sudo apt-get upgrade$ sudo apt-get install python-dev$ sudo apt-get install python-pip$ sudo pip install --upgrade pip$ sudo pip install --upgrade urllib3$ sudo pip install numpy$ sudo pip install matplotlib

之后執行如下測試代碼:

import sysimport numpy as npimport matplotlib.pyplot as plt plt.ion()(fig, axis) = plt.subplots()bar_plot = axis.barh(0, 8,linewidth = 0)bar_plot.color= '#ffff00'for i in range(20): axis.set_xlim(xmax = max(i + 1, 10)) plt.draw() if sys.version_info < (3, 0): raw_input("Press Enter to continue...")else: input("Press Enter to continue...")

上面的測試代碼在 Ubuntu 14.04.5版本上是可以正常執行的,對應的 matplotlib的版本是 matplotlib 1.3.1,但是放到 Ubuntu 16.04.2系統上則是無法正常顯示的,對應的 matplotlib的版本是 matplotlib 1.5.1。

造成這個問題的原因在于 matplotlib.pyplot.draw() ,這個函數行為的改變,早期這個函數是同步更新界面的,后來的版本卻變成了空閑異步更新界面,只有當 matplotlib.pyplot.pause(interval)被調用的時候才會刷新界面。

所以只需要上面的代碼修改成如下即可在不同版本之間兼容:

import sysimport numpy as npimport matplotlib.pyplot as plt plt.ion()(fig, axis) = plt.subplots()bar_plot = axis.barh(0, 8,linewidth = 0)bar_plot.color= '#ffff00'for i in range(20): axis.set_xlim(xmax = max(i + 1, 10)) plt.draw() plt.pause(0.00001) if sys.version_info < (3, 0): raw_input("Press Enter to continue...")else: input("Press Enter to continue...")

注意:我們在 matplotlib.pyplot.draw()調用后面增加了 matplotlib.pyplot.pause(interval)的調用。

查看 matplotlib的版本使用如下代碼:

import matplotlib as mplprint mpl.__version__

總結

以上就是這篇文章的全部內容了,希望本文的內容對大家的學習或者工作能帶來一定的幫助,如果有疑問大家可以留言交流,謝謝大家對武林站長站的支持。

參考鏈接

real-time plotting in while loop with matplotlib matplotlib Troubleshooting How to know the version of installed pylab?
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 白玉县| 新密市| 库车县| 马山县| 常山县| 尖扎县| 西乌| 绥宁县| 桃源县| 宁城县| 九江市| 威海市| 乌鲁木齐县| 阿克| 万盛区| 尉犁县| 河津市| 芜湖市| 泰来县| 谷城县| 深圳市| 武威市| 年辖:市辖区| 天气| 西林县| 龙南县| 丰台区| 灵宝市| 和平区| 扎鲁特旗| 临武县| 儋州市| 江西省| 垫江县| 博客| 大同市| 体育| 祁门县| 高邮市| 墨江| 象州县|