nui*_*uin 18 python warnings matplotlib pandas
matplotlib
每次我都会收到警告import pandas
:
/usr/local/lib/python2.7/site-packages/matplotlib/__init__.py:872: UserWarning: axes.color_cycle is deprecated and replaced with axes.prop_cycle; please use the latter.
warnings.warn(self.msg_depr % (key, alt_key))
Run Code Online (Sandbox Code Playgroud)
抑制它的最佳方法是什么?所有套餐都是最新的.
Conf:OSX与brew Python 2.7.10(默认,2015年7月13日,12:05:58),pandas == 0.17.0和matplotlib == 1.5.0
And*_*reL 26
您可以取消所有警告:
import warnings
warnings.filterwarnings("ignore")
import pandas
Run Code Online (Sandbox Code Playgroud)
您可以按照AndreL的建议抑制警告消息,也可以解决此特定问题并停止一劳永逸地收到警告消息.如果您想要后者,请执行以下操作.
打开matplotlibrc
文件并搜索axes.color_cycle
.如果您收到警告消息,则表示您的matplotlibrc
文件应显示如下内容:
axes.color_cycle : b, g, r, c, m, y, k # color cycle for plot lines
Run Code Online (Sandbox Code Playgroud)
你应该用这个代替那一行:
axes.prop_cycle : cycler('color', ['b', 'g', 'r', 'c', 'm', 'y', 'k'])
Run Code Online (Sandbox Code Playgroud)
警告信息应该消失了.
您还可以隐藏特定警告,而不是隐藏所有内容。例如,如果我们只想隐藏matplotlib
警告:
warnings.filterwarnings( "ignore", module = "matplotlib\..*" )
Run Code Online (Sandbox Code Playgroud)
过滤器可以自定义为发出警告的文件的确切消息和行号,假设它只是一个让您烦恼的警告而不是matplotlib
整个警告。有关更多详细信息,请参阅https://docs.python.org/3/library/warnings.html。
归档时间: |
|
查看次数: |
15585 次 |
最近记录: |