而不是直接绘图,需要绘制平滑的折线图

2024-06-25 23:31:25 发布

您现在位置:Python中文网/ 问答频道 /正文

我有3台机器的3个df(Machine1/Machine2/Machine3)。每个df有3列。白班和生产。 样本df:

   Day-Shift    Production Quality
    Day 11-01    20         A
    Night 11-01  45         A
    Day 11-02    65         A
    Night 11-02  12         B  
    Day 11-03    97         B

我的代码:

import numpy as np
import pandas as pd
from plotly.offline import iplot

import plotly.graph_objects as go


# Machine1: Create numpy arrays of values for the given quality.
b1 = np.where(df1['Quality'] == 'A', df1['Production'], None)

# Machine2: Same as above.
b2 = np.where(df2['Quality'] == 'A', df2['Production'], None)

# Machine3: Same as above.
b3 = np.where(df3['Quality'] == 'A', df3['Production'], None)


# Setup.
t = []
line = ['solid']
Quality = ['A']


t.append({'x': df1['Day-Shift'], 
              'y': b1, 
              'name': f'Machine1',
              'line': {'color': 'red', 
                       'dash': line[0]}})


t.append({'x': df2['Day-Shift'], 
              'y': b2,
              'name': f'Machine1',
              'line': {'color': 'blue', 
                       'dash': line[0]}})


t.append({'x': df3['Day-Shift'], 
              'y': b3,
              'name': f'Machine1',
              'line': {'color': 'yellow', 
                       'dash': line[0]}})
    

# Plot the graph.


layout = go.Layout(

    title='Production meterage of Machine1/Machine2/Machine3 for Quality A',
        template='plotly_dark',
        xaxis=dict(
            autorange=True
        ),
        yaxis=dict(
            autorange=True
        )
    )
fig = go.Figure(data=t, layout=layout)
iplot(fig)

我得到的图表:

enter image description here

我为所有三台机器创建了一个折线图。但是折线图看起来很混乱。需要做平滑处理。我试过用高斯滤波器1d。但这对我不起作用


Tags: importgodfshiftasnplineplotly