(plot_file, plot_name, figs)
| 22 | |
| 23 | |
| 24 | def save_plot_file(plot_file, plot_name, figs): |
| 25 | warn_msg = "To draw plots you should install plotly." |
| 26 | try: |
| 27 | from plotly.offline import plot as plotly_plot |
| 28 | except ImportError as e: |
| 29 | warnings.warn(warn_msg) |
| 30 | raise ImportError(str(e)) |
| 31 | |
| 32 | def write_plot_file(plot_file_stream): |
| 33 | plot_file_stream.write('\n'.join(( |
| 34 | '<html>', |
| 35 | '<head>', |
| 36 | '<meta charset="utf-8" />', |
| 37 | '<script src="https://cdn.plot.ly/plotly-latest.min.js"></script>', |
| 38 | '<title>{}</title>'.format(plot_name), |
| 39 | '</head>', |
| 40 | '<body>' |
| 41 | ))) |
| 42 | for fig in figs: |
| 43 | graph_div = plotly_plot( |
| 44 | fig, |
| 45 | output_type='div', |
| 46 | show_link=False, |
| 47 | include_plotlyjs=False |
| 48 | ) |
| 49 | plot_file_stream.write('\n{}\n'.format(graph_div)) |
| 50 | plot_file_stream.write('</body>\n</html>') |
| 51 | |
| 52 | if isinstance(plot_file, str): |
| 53 | with open(fspath(plot_file), 'w') as plot_file_stream: |
| 54 | write_plot_file(plot_file_stream) |
| 55 | else: |
| 56 | write_plot_file(plot_file) |
| 57 | |
| 58 | |
| 59 | class OfflineMetricVisualizer(object): |
no test coverage detected