0
Follow
0
View

python visualizes too much data using the plotly database

wcong123456 注册会员
2023-02-27 22:34

How to smooth out this data graph. Like average every 10 numbers, or something to smooth the output a little bit. Let me draw it again. The current graph is too choppy

dj721111 注册会员
2023-02-27 22:33

It's really OK. The big God should answer quote ChatGPT. What does that mean. Is it gtp? How do you know the name of this function?

xuan_527 注册会员
2023-02-27 22:33
< div class = "md_content_show e397 data - v - 3967" = "" >

is Chatgpt give solution

dyfdyfdyf 注册会员
2023-02-27 22:33

This answer refers to ChatGPT
Refer to the code below

import os
import numpy as np
import pandas as pd
import sqlite3
import plotly.graph_objs as go
from plotly import tools
import datetime

import warnings
warnings.filterwarnings("ignore")

# 建立数据库连接
con = sqlite3.connect("220604_temp_dht11.db")
print("连接成功")

# 读取数据库表数据
cursor = con.cursor()
dataCopy = cursor.execute("select * from t1 order by id desc")

# 将数据存入Pandas DataFrame中
df = pd.DataFrame([[ij for ij in i] for i in dataCopy.fetchall()])
df.rename(columns={0: 'id', 1: 'tt', 2: 'hh', 4: 'sdate'}, inplace=True)

# 取每隔10个数据只取1个
df = df.iloc[::10, :]

# 创建Trace
trace0 = go.Scatter(x=df["sdate"], y=df["tt"], name="温度", mode='lines+markers')
trace1 = go.Scatter(x=df["sdate"], y=df["hh"], name="湿度", mode='lines+markers')

# 创建Data和Layout
data = [trace0, trace1]
layout = go.Layout(xaxis_title="年份", yaxis_title="温湿度")

# 创建Figure
fig = go.Figure(data, layout)

# 输出图形
output_path = "C:/bar.html"
fig.write_html(output_path)


About the Author

Question Info

Publish Time
2023-02-27 22:33
Update Time
2023-02-27 22:33

Related Question

如何根据列A和B是否满足熊猫/Python中的条件来更改一列中的值

使用python将TXT重新排列为CSV文件

hutool的导出显示行数设置

想从事python工作,需要把所有的知识都学了吗?

问问Python怎么输出成这样的式子

我如何使用python webbrowser模块在后台打开一个链接?

python数据挖掘

如何在python中使用mpi4py库连接收集的数据

机器学习IPython could not be loaded问题

在Python中对整个数据集使用Simplemma