简体   繁体   English

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

[英]rather than directly plotting ,need to plot smooth line chart python

i have a 3 df's fro 3 machines(Machine1/Machine2/Machine3).Each df with 3 columns.我有 3 个 df 来自 3 台机器(Machine1/Machine2/Machine3)。每个 df 有 3 列。 Day-shift and production.白班和生产。 sample df:样本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

my code:我的代码:

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)

Chart I got:我得到的图表:

在此处输入图像描述

I created one line chart for all three machines.我为所有三台机器创建了一个折线图。 But the line chart looks messy.但是折线图看起来很乱。 Need to do smoothing.需要做平滑处理。 I tried with gaussian_filter1d.我尝试使用 gaussian_filter1d。 But It does not work for me.但这对我不起作用。

I think the best way of representing your data is with a histogram.我认为表示数据的最佳方式是使用直方图。 I don't know much of ploty ofline module but you can do it (easily) with matplotlib.我不太了解 ploty 离线模块,但您可以(轻松)使用 matplotlib 做到这一点。

Here is some documentation from matplotlib https://matplotlib.org/3.1.1/api/_as_gen/matplotlib.pyplot.hist.html这是来自 matplotlib https://matplotlib.org/3.1.1/api/_as_gen/matplotlib.pyplot.hist.ZFC35FDC70D5FC69D269883A822C7A53的一些文档

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

and an example with multiply datasets for 1 chart https://matplotlib.org/3.1.1/gallery/statistics/histogram_multihist.html以及 1 个图表的多个数据集的示例https://matplotlib.org/3.1.1/gallery/statistics/histogram_multihist.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM