我们从Python开源项目中,提取了以下2个代码示例,用于说明如何使用plotly.plotly.Stream()。
def create_plots(): # We make a plot for every room plotly_logger.info('max points per graph: %s', ploty_max_points_per_graph) for zone in zones: plotly_logger.info('Creating graph for: %s' % zone) stream_id = zones[zone] stream = Stream( token=stream_id, maxpoints=ploty_max_points_per_graph ) trace1 = Scatter( x=[], y=[], mode='lines+markers', line=Line( shape='spline' ), stream=stream ) data = Data([trace1]) layout = Layout(title=zone) fig = Figure(data=data, layout=layout) py.plot(fig, filename=zone, fileopt='extend') # if called directly then this is what will execute # It will create the initial plot.ly reports if need be.
def write(timestamp, temperatures): if invalidConfig: if plotly_debugEnabled: plotly_logger.debug('Invalid config, aborting write') return [] debug_message = 'Writing to ' + plugin_name if not plotly_writeEnabled: debug_message += ' [SIMULATED]' plotly_logger.debug(debug_message) debug_text = '%s: ' % timestamp if plotly_writeEnabled: # Stream tokens from plotly tls.set_credentials_file(stream_ids=stream_ids_array) try: if plotly_writeEnabled: py.sign_in(plotly_username, plotly_api_key) for temperature in temperatures: debug_text += "%s (%s A" % (temperature.zone, temperature.actual) if temperature.target is not None: debug_text += ", %s T" % temperature.target debug_text += ') ' if plotly_writeEnabled: if temperature.zone in zones: stream_id = zones[temperature.zone] s = py.Stream(stream_id) s.open() ts = timestamp.strftime('%Y-%m-%d %H:%M:%S') s.write(dict(x=ts, y=temperature.actual)) s.close() else: plotly_logger.debug("Zone %s does not have a stream id, ignoring") except Exception, e: plotly_logger.error("Plot.ly API error - aborting write\n%s", e) if plotly_debugEnabled: plotly_logger.debug(debug_text)