国产探花免费观看_亚洲丰满少妇自慰呻吟_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?
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 藁城市| 怀来县| 淮滨县| 眉山市| 财经| 扬中市| 黑山县| 得荣县| 图片| 雷州市| 刚察县| 景泰县| 肥东县| 开远市| 阳新县| 琼结县| 湘西| 桑日县| 安庆市| 宁陕县| 宣汉县| 青田县| 青海省| 滦平县| 邹城市| 石阡县| 开原市| 周宁县| 简阳市| 丹巴县| 涪陵区| 南昌县| 衡阳市| 灵台县| 洛南县| 昌图县| 五大连池市| 大连市| 崇义县| 灌南县| 嘉善县|