QtConsole xhtml/Svg export broken ? #1087

Closed
Carreau opened this Issue Dec 1, 2011 · 6 comments

Projects

None yet

2 participants

@Carreau
Member
Carreau commented Dec 1, 2011

When trying to document #735 with a better error mesage I came across the fact that I can't export to xhtml/svg with qt console:

%config InlineBackend.figure_format='svg'
plot(sin(range(10)))

Then file, save as, XHTML/SVG, etc... i've gaot a pop up window,

Error exporting HTML to /Users/bussonniermatthias/eraseme/ipython.xhtml
'ascii' codec can't encode character u'\u2212' in position 15793: ordinal not in range(128)

Export as Png works ok, export as svg when ploting on Png (error Can't find image) works ok
Do I do smth wrong ?

@fperez
Member
fperez commented Dec 1, 2011

Can't confirm right now, but if true, this would be a major blocker. Will mark as such so we don't miss it until I or someone else can triage better.

@Carreau
Member
Carreau commented Dec 1, 2011

tracking down...
It depends on the graph I plot . Since at least HEAD~200 :
exporting plot(range(10)) works , plot(sin(range(10)) doesn't, cos doesn't, x*2 does, sin(range(5)), doesn't sin(range(4)) does ...

@Carreau Carreau added a commit to Carreau/ipython that referenced this issue Dec 4, 2011
@Carreau Carreau qtconsole export xhtml/utf8
	using utf-8 to save the qtconsole export as xhtml/svg, to avoid crash on some
	kinds of plots, mainly when converting svg to str, or when writing the file

	closes #1087
3b6bc65
@Carreau
Member
Carreau commented Dec 4, 2011

this seem to be more deep that what I expected....

On (my) debian it even fail as rendering plot(sin(range(10)) when qtconsole is configured with svg
note that plot(range(10)) works

%config InlineBackend.figure_format='svg'

plot(sin(range(10)))
Out[2]: [<matplotlib.lines.Line2D at 0x9d993cc>]Disabling failed post-execution function: <function flush_figures at 0x9d80224>
ERROR: An unexpected error occurred while tokenizing input
The following traceback may be corrupted or invalid
The error message is: ('EOF in multi-line statement', (556, 0))
ERROR: An unexpected error occurred while tokenizing input
The following traceback may be corrupted or invalid
The error message is: ('EOF in multi-line statement', (556, 0))
ERROR: An unexpected error occurred while tokenizing input
The following traceback may be corrupted or invalid
The error message is: ('EOF in multi-line statement', (556, 0))
ERROR: An unexpected error occurred while tokenizing input
The following traceback may be corrupted or invalid
The error message is: ('EOF in multi-line statement', (556, 0))
ERROR: An unexpected error occurred while tokenizing input
The following traceback may be corrupted or invalid
The error message is: ('EOF in multi-line statement', (2, 0))
---------------------------------------------------------------------------
UnicodeEncodeError                        Traceback (most recent call last)
/home/carreau/ipython/IPython/zmq/pylab/backend_inline.pyc in flush_figures()
    147     if InlineBackend.instance().close_figures:
    148         # ignore the tracking, just draw and close all figures

--> 149         return show(True)
    150 
    151     try:

/home/carreau/ipython/IPython/zmq/pylab/backend_inline.pyc in show(close)
    100     try:
    101         for figure_manager in Gcf.get_all_fig_managers():
--> 102             send_figure(figure_manager.canvas.figure)
    103     finally:
    104         show._to_draw = []

/home/carreau/ipython/IPython/zmq/pylab/backend_inline.pyc in send_figure(fig)
    168         return
    169     fmt = InlineBackend.instance().figure_format
--> 170     data = print_figure(fig, fmt)
    171     mimetypes = { 'png' : 'image/png', 'svg' : 'image/svg+xml' }
    172     mime = mimetypes[fmt]

/home/carreau/ipython/IPython/core/pylabtools.pyc in print_figure(fig, fmt)
    102     try:
    103         bytes_io = BytesIO()
--> 104         fig.canvas.print_figure(bytes_io, format=fmt, bbox_inches='tight')
    105         data = bytes_io.getvalue()
    106     finally:

/usr/lib/pymodules/python2.6/matplotlib/backend_bases.pyc in print_figure(self, filename, dpi, facecolor, edgecolor, orientation, format, **kwargs)
   1453                     orientation=orientation,
   1454                     dryrun=True,
-> 1455                     **kwargs)
   1456                 renderer = self.figure._cachedRenderer
   1457                 bbox_inches = self.figure.get_tightbbox(renderer)

/usr/lib/pymodules/python2.6/matplotlib/backend_bases.pyc in print_svg(self, *args, **kwargs)
   1353         from backends.backend_svg import FigureCanvasSVG # lazy import
   1354         svg = self.switch_backends(FigureCanvasSVG)
-> 1355         return svg.print_svg(*args, **kwargs)
   1356 
   1357     def print_svgz(self, *args, **kwargs):

/usr/lib/pymodules/python2.6/matplotlib/backends/backend_svg.pyc in print_svg(self, filename, *args, **kwargs)
    625         else:
    626             raise ValueError("filename must be a path or a file-like object")
--> 627         return self._print_svg(filename, svgwriter, fh_to_close, **kwargs)
    628 
    629     def print_svgz(self, filename, *args, **kwargs):

/usr/lib/pymodules/python2.6/matplotlib/backends/backend_svg.pyc in _print_svg(self, filename, svgwriter, fh_to_close, **kwargs)
    660                 bbox_inches_restore=_bbox_inches_restore)
    661 
--> 662         self.figure.draw(renderer)
    663         renderer.finalize()
    664         if fh_to_close is not None:

/usr/lib/pymodules/python2.6/matplotlib/artist.pyc in draw_wrapper(artist, renderer, *args, **kwargs)
     44     def draw_wrapper(artist, renderer, *args, **kwargs):
     45         before(artist, renderer)
---> 46         draw(artist, renderer, *args, **kwargs)
     47         after(artist, renderer)
     48 

/usr/lib/pymodules/python2.6/matplotlib/figure.pyc in draw(self, renderer)
    771 
    772         # render the axes

--> 773         for a in self.axes: a.draw(renderer)
    774 
    775         # render the figure text


/usr/lib/pymodules/python2.6/matplotlib/artist.pyc in draw_wrapper(artist, renderer, *args, **kwargs)
     44     def draw_wrapper(artist, renderer, *args, **kwargs):
     45         before(artist, renderer)
---> 46         draw(artist, renderer, *args, **kwargs)
     47         after(artist, renderer)
     48 

/usr/lib/pymodules/python2.6/matplotlib/axes.pyc in draw(self, renderer, inframe)
   1733 
   1734         for zorder, i, a in dsu:
-> 1735             a.draw(renderer)
   1736 
   1737         renderer.close_group('axes')

/usr/lib/pymodules/python2.6/matplotlib/artist.pyc in draw_wrapper(artist, renderer, *args, **kwargs)
     44     def draw_wrapper(artist, renderer, *args, **kwargs):
     45         before(artist, renderer)
---> 46         draw(artist, renderer, *args, **kwargs)
     47         after(artist, renderer)
     48 

/usr/lib/pymodules/python2.6/matplotlib/axis.pyc in draw(self, renderer, *args, **kwargs)
    740             tick.set_label1(label)
    741             tick.set_label2(label)
--> 742             tick.draw(renderer)
    743             if tick.label1On and tick.label1.get_visible():
    744                 extent = tick.label1.get_window_extent(renderer)

/usr/lib/pymodules/python2.6/matplotlib/artist.pyc in draw_wrapper(artist, renderer, *args, **kwargs)
     44     def draw_wrapper(artist, renderer, *args, **kwargs):
     45         before(artist, renderer)
---> 46         draw(artist, renderer, *args, **kwargs)
     47         after(artist, renderer)
     48 

/usr/lib/pymodules/python2.6/matplotlib/axis.pyc in draw(self, renderer)
    194 
    195         if self.label1On:
--> 196             self.label1.draw(renderer)
    197         if self.label2On:
    198             self.label2.draw(renderer)

/usr/lib/pymodules/python2.6/matplotlib/text.pyc in draw(self, renderer)
    566             renderer.draw_text(gc, x, y, clean_line,
    567                                self._fontproperties, angle,
--> 568                                ismath=ismath)
    569 
    570         gc.restore()

/usr/lib/pymodules/python2.6/matplotlib/backends/backend_svg.pyc in draw_text(self, gc, x, y, s, prop, angle, ismath)
    439 <text style="%(style)s" x="%(x)f" y="%(y)f" %(transform)s>%(thetext)s</text>
    440 """ % locals()
--> 441         write(svg)
    442 
    443     def _add_char_def(self, prop, char):

/usr/lib/python2.6/codecs.pyc in write(self, data)
    810     def write(self, data):
    811 
--> 812         data, bytesdecoded = self.decode(data, self.errors)
    813         return self.writer.write(data)
    814 

/usr/lib/python2.6/encodings/utf_8.pyc in decode(input, errors)
     14 
     15 def decode(input, errors='strict'):
---> 16     return codecs.utf_8_decode(input, errors, True)
     17 
     18 class IncrementalEncoder(codecs.IncrementalEncoder):

UnicodeEncodeError: 'ascii' codec can't encode character u'\u2212' in position 145: ordinal not in range(128)
@Carreau
Member
Carreau commented Dec 5, 2011

I give up... I don't see where it can came from.
Am I the only one to get this behaviour ?

@fperez
Member
fperez commented Dec 6, 2011

Weird, @Carreau: I can't reproduce it at all. I tried multiple plots including complex ones and several examples from the matplotlib gallery that produce fairly elaborate figures, and it works without fail for me. Saving to xhtml/svg always works, and I can read the resulting file with firefox fine too (it loses the syntax highlighting, but that's a known limitation whose origin we don't quite understand).

From reading the traceback, I'm going to guess this could be a bug in matplotlib itself. I'm running with matplotlib 1.0.1 right now on ubuntu 11.10 (the official system matplotlib, not a hand-built one) and don't see the problem at all.

I'm afraid that unless you can find a way to reproduce this reliably that we can see, we won't be able to make any further progress here.

@Carreau
Member
Carreau commented Dec 6, 2011

ok, I'll try to test it on other computer... I close and will reopen if I get some new info...

@Carreau Carreau closed this Dec 6, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment