[英]Plotly Dash : Time Series Scatter plot rendering
I'm following the dash wind streaming example to stream data from a MySQL database. 我正在遵循dash wind流示例,以从MySQL数据库流数据。 Data is added to the database every 5 seconds and queried respectively.
每5秒钟将数据添加到数据库并分别查询一次。 I used the Interval component to query and a hidden div to store.
我使用了Interval组件进行查询,并使用了一个隐藏的div进行存储。 I read the jsonified data in a callback function into a dataframe called df.
我将回调函数中的JSON化数据读入称为df的数据帧中。
I generate a trace using the following: 我使用以下方法生成跟踪:
trace_sensor_1 = Scatter(
x=df.loc[df['sensor_id'] == 1]['timestamp'],
y=df.loc[df['sensor_id'] == 1]['sensor_reading'],
mode='markers+lines',
name='Sensor 1',
However, the scatter plot that this generates (attached) jumps all over the place.
但是,由此生成的(散布的)散点图会在整个位置上跳跃。 Is this due to the mode I'm using?
这是由于我使用的模式吗? How do I modify the trace to render a proper looking time series scatter?
如何修改轨迹以呈现适当的时间序列散点图?
For plotly its important to sort your data by your x axis first. 对于绘图来说,首先按x轴对数据进行排序很重要。
In pandas you can sort like this: 在大熊猫中,您可以像这样进行排序:
df_sorted = df.sort_values(by=['timestamp'])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.