import matplotlib.pyplot as pl
%matplot inline
def learning_curves(X_train, y_train, X_test, y_test):
""" Calculates the performance of several models with varying sizes of training data.
The learning and testing error rates for each model are then plotted. """
print ("Creating learning curve graphs for max_depths of 1, 3, 6, and 10. . .")
# Create the figure window
fig = pl.figure(figsize=(10,8))
# We will vary the training set size so that we have 50 different sizes
sizes = np.rint(np.linspace(1, len(X_train), 50)).astype(int) …Run Code Online (Sandbox Code Playgroud) 这与这个问题非常接近,但是我添加了一些特定于我的问题的细节:
使用AWS-EMR jupyter笔记本进行Matplotlib绘图
我想找到一种在Jupyter笔记本中使用matplotlib的方法。这是错误的代码片段,非常简单:
笔记本
import matplotlib
matplotlib.use("agg")
import matplotlib.pyplot as plt
plt.plot([1,2,3,4])
plt.show()
Run Code Online (Sandbox Code Playgroud)
我选择此代码段是因为仅此行在尝试使用TKinter时失败(该行未安装在AWS EMR集群中):
import matplotlib.pyplot as plt
Run Code Online (Sandbox Code Playgroud)
当我运行完整的笔记本代码片段时,结果是没有运行时错误,但什么也没有发生(未显示任何图形。)我对这可以起作用的一种方式的理解是添加以下两个代码片段之一:
pyspark魔术符号
%matplotlib inline
Run Code Online (Sandbox Code Playgroud)
结果
unknown magic command 'matplotlib'
UnknownMagic: unknown magic command 'matplotlib'
Run Code Online (Sandbox Code Playgroud)
IPython显式魔术调用
unknown magic command 'matplotlib'
UnknownMagic: unknown magic command 'matplotlib'
Run Code Online (Sandbox Code Playgroud)
结果
'NoneType' object has no attribute 'run_line_magic'
Traceback (most recent call last):
AttributeError: 'NoneType' object has no attribute 'run_line_magic'
Run Code Online (Sandbox Code Playgroud)
到我的笔记本,笔记本会调用一个火花魔术命令,该命令会内联matplotlib图(至少是我的解释。)我在使用引导操作后尝试了这两种方法:
EMR引导程序
from IPython import get_ipython
get_ipython().run_line_magic('matplotlib', 'inline')
Run Code Online (Sandbox Code Playgroud)
即使添加了这些,我仍然会得到一个错误,那就是matplotlib没有任何魔力。所以我的问题肯定是:
题
如何使matplotlib在AWS EMR Jupyter笔记本中工作?
(或者如何在AWS EMR Jupyter笔记本中查看图形并绘制图像?)