【发布时间】:2019-03-22 13:36:41
【问题描述】:
我想从一个类中调用一个函数,我想在其中绘制多个图形。 没有抛出错误,但我没有收到情节,但只有:
#############################################
Histograms of the continuous data:
#############################################
<Figure size 640x480 with 1 Axes>
<Figure size 640x480 with 1 Axes>
<Figure size 640x480 with 1 Axes>
<Figure size 640x480 with 1 Axes>
<Figure size 640x480 with 1 Axes>
<Figure size 640x480 with 1 Axes>
<Figure size 640x480 with 1 Axes>
<Figure size 640x480 with 1 Axes>
<Figure size 640x480 with 1 Axes>
<Figure size 640x480 with 1 Axes>
<Figure size 640x480 with 1 Axes>
<Figure size 640x480 with 1 Axes>
我使用的代码是:
class Pipeline:
import matplotlib.pyplot as plt
global plt
from matplotlib import style
style.use('ggplot')
def __init__(self,goal):
self.goal = goal
def examine(self,dataset):
# Check for categorical and continous data
continuous = []
categorical = []
for n,i in enumerate(dataset.columns):
if isinstance(dataset[i][1],str):
categorical.append(dataset.columns[n])
else:
continuous.append(dataset.columns[n])
continuous_data = dataset[continuous]
categorical_data = dataset[categorical]
#Plot the histograms of the continuous data
print('#############################################')
print('Histograms of the continuous data:')
print('#############################################')
for col in continuous_data.columns:
fig = plt.figure()
ax = continuous_data[col].hist()
ax.set_title(col)
plt.show()
pipe = Pipeline('C')
pipe.examine(data)
我想知道,因为如果我第二次运行相同的代码,它会按照建议的方式绘制数字。 感谢任何帮助!
【问题讨论】:
-
这是在 Jupyter 中,因为它看起来像 %matplotlib inline 丢失了吗?
-
是的,它在 Jupyter 中
-
ok 在顶部添加“%matplotlib inline”并再次运行
-
这就是解决方案。请将其发布为答案
-
好的。 @2Obe。作为解决方案添加
标签: python python-3.x pandas matplotlib jupyter-notebook