Skip to content

Instantly share code, notes, and snippets.

@yuta-imai
Last active October 31, 2017 08:43
Show Gist options
  • Save yuta-imai/452f31d840e9cb181af0c8e9d3750843 to your computer and use it in GitHub Desktop.
Save yuta-imai/452f31d840e9cb181af0c8e9d3750843 to your computer and use it in GitHub Desktop.
Using matplotlib example on top of Apache Zeppelin
%pyspark
import matplotlib
import matplotlib.pyplot as plt
import numpy as np
import StringIO
matplotlib.use('Agg')
plt.rcdefaults()
def show(p):
img = StringIO.StringIO()
p.savefig(img, format='svg')
img.seek(0)
print "%html <div style='width:600px'>" + img.buf + "</div>"
x = np.linspace(-1,1,100)
y = x * 2
plt.plot(x,y)
show(plt)
@r14152
Copy link

r14152 commented Oct 31, 2017

Running this code I get this error :
Traceback (most recent call last):
File "/tmp/zeppelin_pyspark-5728297460444875606.py", line 367, in
raise Exception(traceback.format_exc())
Exception: Traceback (most recent call last):
File "/tmp/zeppelin_pyspark-5728297460444875606.py", line 355, in
exec(code, _zcUserQueryNameSpace)
File "", line 14, in
File "/usr/lib/python2.7/dist-packages/matplotlib/pyplot.py", line 3147, in plot
ax = gca()
File "/usr/lib/python2.7/dist-packages/matplotlib/pyplot.py", line 928, in gca
return gcf().gca(**kwargs)
File "/usr/lib/python2.7/dist-packages/matplotlib/pyplot.py", line 578, in gcf
return figure()
File "/usr/lib/python2.7/dist-packages/matplotlib/pyplot.py", line 527, in figure
**kwargs)
File "/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.py", line 84, in new_figure_manager
return new_figure_manager_given_figure(num, figure)
File "/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.py", line 92, in new_figure_manager_given_figure
window = Tk.Tk()
File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 1818, in init
self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
TclError: no display name and no $DISPLAY environment variable

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment