pandas Python 熊猫:pd.options.display.mpl_style = 'default' 导致图形崩溃

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24870647/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 22:16:39  来源:igfitidea点击:

Python pandas : pd.options.display.mpl_style = 'default' causes graph crash

pythonmatplotlibpandas

提问by Maxi

Everything is in the title. My graph is displayed properly when I do not set this option at the beginning of my python script, otherwise it opens the window for the graph but closes it straightback and end the run.

一切都在标题中。当我没有在 python 脚本的开头设置此选项时,我的图形会正确显示,否则它会打开图形窗口,但会直接关闭它并结束运行。

I am using pandas 0.14.0 and matplotlib 1.3.0.

我正在使用Pandas 0.14.0 和 matplotlib 1.3.0。

Anyone already saw this ? You can see my code below if needed.

有人已经看过了吗?如果需要,您可以在下面查看我的代码。

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

#pd.options.display.mpl_style = 'default'

df = pd.DataFrame(np.random.randn(1000, 4), index=pd.date_range('1/1/2000',periods=1000), columns=list('ABCD'))
df = df.cumsum()
df.plot(legend=False)

plt.show()

回答by rmalhotra

Use the following:

使用以下内容:

plt.show(block=True)

plt.show(block=True)

回答by johnml1135

I was experiencing a similar error with Matplotlib v1.4. The solution I found is to use

我在使用 Matplotlib v1.4 时遇到了类似的错误。我找到的解决方案是使用

matplotlib.style.use('ggplot')

rather than

而不是

pd.options.display.mpl_style = 'default'

See - https://pandas-docs.github.io/pandas-docs-travis/visualization.html

见 - https://pandas-docs.github.io/pandas-docs-travis/visualization.html