gizeh icon indicating copy to clipboard operation
gizeh copied to clipboard

surface.ipython_display() fails in python 3

Open ghost opened this issue 8 years ago • 1 comments

The following snippet produces no output in jupyter with python3.

import gizeh as gz
W, H = 500, 300
r, gray, t = 25., .3, 1.

surface = gz.Surface(W,H, bg_color=(1, 1, 1)) # white background
gradient = gz.ColorGradient(type="radial", stops_colors=[(0,(gray, gray, gray)), (1, (1, 1, 1))],
                            xy1=[0, 0], xy2=[0, 0], xy3=[0, r])
rf = gz.circle(r=r, xy=(W/2., H/2.), fill=gradient)
#rect = gz.rectangle(lx=.3*H, ly=.02*H, xy=(W*t/duration, H/2.), fill=(0,1,0), angle=np.pi/2)

rf.draw(surface)
surface.ipython_display()

The problem is in Surface._repr_png_(). Python 3 doesn't have the cStringIO module, so the line data = StringIO() fails (silently). If I instead use the io module as suggested here, the snippet above generates an error from cairo.

ghost avatar Apr 26 '17 23:04 ghost

I found that extension for jupyter https://github.com/fomightez/cairo-jupyter

Is there a way to access the underlying cairo surface/context of a gizeh surface?

EDIT: Yes, with _cairo_surface. And it seems to work alright :)

YPares avatar Jun 08 '18 13:06 YPares