SVG Histogram
Demonstrate how to create an interactive histogram, in which bars are hidden or shown by clicking on legend markers.
The interactivity is encoded in ecmascript (javascript) and inserted in the SVG code in a post-processing step. To render the image, open it in a web browser. SVG is supported in most web browsers used by Linux and macOS users. Windows IE9 supports SVG, but earlier versions do not.
Notes
The matplotlib backend lets us assign ids to each object. This is the mechanism used here to relate matplotlib objects created in python and the corresponding SVG constructs that are parsed in the second step. While flexible, ids are cumbersome to use for large collection of objects. Two mechanisms could be used to simplify things:
systematic grouping of objects into SVG <g> tags,
assigning classes to each SVG object according to its origin.
For example, instead of modifying the properties of each individual bar,
the bars from the hist function could either be grouped in
a PatchCollection, or be assigned a class="hist_##" attribute.
CSS could also be used more extensively to replace repetitive markup throughout the generated SVG.
Author: davidhuardgmailcom