jupyter无法显示内嵌图形

时间:2016-09-22 09:07:19

标签: matplotlib jupyter-notebook

我在我的rhel6系统上通过pip和python34安装了jupyter(通过scl)。我可以运行笔记本电脑,但是,我无法使任何魔法工作,我也无法绘制任何东西(即没有图形)。

示例笔记本:

import seaborn as sns
import matplotlib
print("%s"%(matplotlib.matplotlib_fname(),))
print("%s"%(matplotlib.get_backend(),))
import matplotlib.pyplot as plt

/opt/pyspark/lib/python3.4/site-packages/matplotlib/mpl-data/matplotlibrc
TkAgg

试图策划一些事情:

import numpy as np
import pandas as pd
import random

df = pd.DataFrame()
df['x'] = random.sample(range(1, 100), 25)
df['y'] = random.sample(range(1, 100), 25)
(df.head())

sns.lmplot('x','y', data=df, fit_reg=False)

Name: org.apache.toree.interpreter.broker.BrokerException
Message: Traceback (most recent call last):
  File "/tmp/kernel-PySpark-fc7b8287-6d11-43eb-9569-be81655a0bcf/pyspark_runner.py", line 134, in <module>
    eval(compiled_code)
  File "<string>", line 1, in <module>
  File "/opt/pyspark/lib/python3.4/site-packages/seaborn/linearmodels.py", line 548, in lmplot
    legend_out=legend_out)
  File "/opt/pyspark/lib/python3.4/site-packages/seaborn/axisgrid.py", line 307, in __init__
    fig, axes = plt.subplots(nrow, ncol, **kwargs)
  File "/opt/pyspark/lib/python3.4/site-packages/matplotlib/pyplot.py", line 1185, in subplots
    fig = figure(**fig_kw)
  File "/opt/pyspark/lib/python3.4/site-packages/matplotlib/pyplot.py", line 535, in figure
    **kwargs)
  File "/opt/pyspark/lib/python3.4/site-packages/matplotlib/backends/backend_tkagg.py", line 84, in new_figure_manager
    return new_figure_manager_given_figure(num, figure)
  File "/opt/pyspark/lib/python3.4/site-packages/matplotlib/backends/backend_tkagg.py", line 92, in new_figure_manager_given_figure
    window = Tk.Tk()
  File "/opt/rh/rh-python34/root/usr/lib64/python3.4/tkinter/__init__.py", line 1851, in __init__
    self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
_tkinter.TclError: no display name and no $DISPLAY environment variable

StackTrace: org.apache.toree.interpreter.broker.BrokerState$$anonfun$markFailure$1.apply(BrokerState.scala:140)
org.apache.toree.interpreter.broker.BrokerState$$anonfun$markFailure$1.apply(BrokerState.scala:140)
scala.Option.foreach(Option.scala:236)
org.apache.toree.interpreter.broker.BrokerState.markFailure(BrokerState.scala:139)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:606)
py4j.reflection.MethodInvoker.invoke(MethodInvoker.java:231)
py4j.reflection.ReflectionEngine.invoke(ReflectionEngine.java:381)
py4j.Gateway.invoke(Gateway.java:259)
py4j.commands.AbstractCommand.invokeMethod(AbstractCommand.java:133)
py4j.commands.CallCommand.execute(CallCommand.java:79)
py4j.GatewayConnection.run(GatewayConnection.java:209)
java.lang.Thread.run(Thread.java:745)

注意我从我的mac进入linux框中,使用本地端口转发来查看jupyter笔记本。

试图运行魔法:

%matplotlib inline

Name: Error parsing magics!
Message: Magics [matplotlib] do not exist!
StackTrace: 

yum installs列表:

- rh-python34
- python-virtualenv
- python-setuptools
- python-pip
- rh-python34-python-tkinter

pip安装列表:

- pandas
- matplotlib
- scipy
- numpy
- seaborn
- jupyter

0 个答案:

没有答案