【发布时间】:2020-02-28 05:27:13
【问题描述】:
在 Google Colab 中使用笔记本时,无论我是否导入库 pandas-profiling,我的 matplotlib 绘图都有不同的行为。
如果我不导入 pandas-profiling,这些图会默认显示为内联。但是,如果我导入库,这些图停止内联显示。
解决方法(可能的解决方案)
- 在导入之前更新 pandas-profiling 库可以解决问题。
- 添加
%matplotlib inline在导入pandas-profiling后可以解决问题。
复制
在 Google Colab 中运行此代码以重现该问题。在导入和不导入 pandas_profiling 的情况下对其进行测试。对于每个测试,您将需要终止会话(运行时->管理会话->终止)。仅仅重启运行时是不够的。
import matplotlib.pyplot as plt
# importing the pandas_profiling makes matplotlib
# to stop showing the plot inline
# import pandas_profiling
plt.plot([1, 2], [1, 2])
expected behavior默认是内联显示绘图,但是导入pandas-profiling后,绘图stop being displayed inline。
真正的问题
当我的 seaborn 绘图功能开始出现故障时,我偶然发现了这个问题。
例如,考虑以下代码。
import matplotlib.pyplot as plt
# import pandas_profiling
import seaborn as sns
def plot():
ax = sns.pointplot([1, 2], [1, 2])
print(len(ax.collections))
现在在两个不同的 jupyter 单元中调用 plot()。
- 没有 pandas-profiling:每个函数调用都会打印 1。
- 使用 pandas-profiling:每个函数调用都会在之前的输出中加 1。
【问题讨论】:
标签: matplotlib seaborn google-colaboratory pandas-profiling