Convert a matplotlib figure to vega dictionary if notebook=True, then return an object which will display in a notebook otherwise, return an HTML string.
(fig, notebook=False)
| 125 | |
| 126 | |
| 127 | def fig_to_vega(fig, notebook=False): |
| 128 | """Convert a matplotlib figure to vega dictionary |
| 129 | |
| 130 | if notebook=True, then return an object which will display in a notebook |
| 131 | otherwise, return an HTML string. |
| 132 | """ |
| 133 | renderer = VegaRenderer() |
| 134 | Exporter(renderer).run(fig) |
| 135 | vega_html = VegaHTML(renderer) |
| 136 | if notebook: |
| 137 | return vega_html |
| 138 | else: |
| 139 | return vega_html.html() |
| 140 | |
| 141 | |
| 142 | VEGA_TEMPLATE = """ |
nothing calls this directly
no test coverage detected