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

问题描述

我有 3 个 df 的 3 台机器(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,'line': {'color': 'blue','dash': line[0]}})


t.append({'x': df3['Day-Shift'],'y': b3,'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

我为所有三台机器创建了一个折线图。但是折线图看起来很乱。需要做平滑处理。我试过gaussian_filter1d。但它对我不起作用。

解决方法

我认为表示数据的最佳方式是使用直方图。我不太了解 ploty 离线模块,但您可以(轻松)使用 matplotlib 来完成。

这是来自 matplotlib 的一些文档 https://matplotlib.org/3.1.1/api/_as_gen/matplotlib.pyplot.hist.html

和一个例子: https://matplotlib.org/3.1.1/gallery/statistics/hist.html

以及 1 个图表的多个数据集的示例 https://matplotlib.org/3.1.1/gallery/statistics/histogram_multihist.html

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...