我们从Python开源项目中,提取了以下2个代码示例,用于说明如何使用plotly.graph_objs()。
def generate_chart(self, _): try: import plotly import plotly.graph_objs as go data = [[0, 0, 0], [0, 0, 0]] ok, viol = self.results.get_ok_viol() x = ["OK (%d)" % ok, "Tampering (%d)" % viol] for ret in self.results: i = 1 if ret.is_tampering() else 0 data[i][0] += ret.is_aligned() data[i][1] += ret.is_disaligned() data[i][2] += ret.is_single() final_data = [go.Bar(x=x, y=[x[0] for x in data], name="Aligned"), go.Bar(x=x, y=[x[1] for x in data], name="Disaligned"), go.Bar(x=x, y=[x[2] for x in data], name="Single")] fig = go.Figure(data=final_data, layout=go.Layout(barmode='group', title='Call stack tampering labels')) plotly.offline.plot(fig, output_type='file', include_plotlyjs=True, auto_open=True) except ImportError: self.log("ERROR", "Plotly module not available")
def make_plotly_fig(self, code: str) -> str: global plotly if plotly is None: import plotly loc: Dict[str, Any] = {} self.plotly_globals.update({'plot': self.plotly_plotter.plot, 'go': plotly.graph_objs, 'plotly': plotly}) gl = self.plotly_globals exec(code, gl, loc) self.js_top['plotly'] = ("<script src='https://cdn.plot.ly/plotly-" "latest.min.js'></script>") return self.plotly_plotter.get_data()