Hello list,
I was trying to create some interactive SVGs with matplotlib and I faced the following issues. Some maybe bugs, some other just missing functionality. I'm just summarising my experience so that you are aware of the issues.
First of all I used git-head from a couple of monts ago with python-3.2, and I'm quite happy that it worked. My target was to make the dots in a plot(x,y,"-o") graph clickable. Here are the issues I faced:
* I didn't find a way to set an "id" attribute for each marker. Googling
聽聽聽revealed that I should probably call set_gid() but I had no success. So
聽聽聽I stored the whole XML file into memory and searched for the <use> tags
聽聽聽inside <g id="line2d_1">. The ideal would have been for each <use> to
聽聽聽have a specific id, or at least the <g> containing the <use>s.
* pylab.savefig(f, format="svg") never worked whenever f was sys.stdout or
聽聽聽io.StringIO. It seems that it err'ed on every file that didn't support
聽聽聽open(). My workaround was to write to a tempfile and read back. Maybe
聽聽聽support for this can be added together with support for already opened
聽聽聽files, so that the with-statement works? I /think/ errors were like
聽聽聽the following:
File "~/dist/src/matplotlib-git/matplotlib/build/lib.linux-i686-3.2/matplotlib/backends/backend_svg.py", line 1101, in print_svg
聽聽聽聽聽return self._print_svg(filename, svgwriter, fh_to_close, **kwargs) UnboundLocalError: local variable 'svgwriter' referenced before assignment
* I couldn't use pylab.ticklabel_format() with SVG engine (I was trying to
聽聽聽apply an offset to the xticks labels), error message was the following,
聽聽聽it's quite probable I don't understand how this works:
File "~/dist/src/matplotlib-git/matplotlib/build/lib.linux-i686-3.2/matplotlib/axes.py", line 2191, in ticklabel_format
聽聽聽聽聽"This method only works with the ScalarFormatter.")
* I wanted some onmouseover() bubble annotation over specific markers but I
聽聽聽gave up on this. Ideally I'd want to refer to the markers with a specific
聽聽聽ID, give them different color style, and be able to add specific <title> or
聽聽聽<text> elements where I want and manipulate them via javascript.
聽聽聽Since I understand this is too much to ask from matplotlib I'd very much
聽聽聽like the possibility to get the XML tree in some form *before* writing
聽聽聽anything to disk. Does the SVG backend use the python xml.etree.ElementTree
聽聽聽module? If only I could get the whole ElementTree, I would manipulate it as
聽聽聽I'd like before writing to disk. What would you suggest to achieve the
聽聽聽result I need?
I also had some difficulties with the website. For example when investigating various plotting utilities and checking their SVG output, I couldn't find anywhere the example from [1] rendered as SVG. The gallery is huge, but it is barely searchable (no text anywhere) so I still might have missed it. Secondly I'd appreciate a table of contents on top of the API pages, e.g. at http://matplotlib.sourceforge.net/api/pyplot_api.html
[1] http://matplotlib.sourceforge.net/examples/user_interfaces/svg_histogram.html
Finally, using more and more matplotlib I realised that some things are more complex than necessary. I'm talking specifically for when subplots or twin axes are involved. Then it is hard to keep a common legend (you have to keep track of the labels yourself). It is also hard to cycle the colors among the different axes (you have to keep track of the colors yourself). To have a common ylabel among the vertical subplots I just set the ylabel for the middle subplot, which seems like a hack. And also suptitle() seems weaker than title() (not bold, smaller font). Finally labels of yticks many times overlap each other at the border of adjascent subplots, so I have to manually compensate using set_major_locate() for sparser yticks.
Even though some things needed time-consuming hacks, matplotlib worked fine. Thanks for your work on this fantastic library! And if you are curious you can see my automatic generated graphs (temporarily) at:
http://teras-ics.mooo.com:8003
thanks,
Dimitris
P.S. I sent this email (slightly changed) again a couple of months ago, but it got stuck in moderation. Thus I send it again now after subscribing, sorry if you get it twice.