[英]rather than directly plotting ,need to plot smooth line chart 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,
'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)
我得到的图表:
我为所有三台机器创建了一个折线图。 但是折线图看起来很乱。 需要做平滑处理。 我尝试使用 gaussian_filter1d。 但这对我不起作用。
我认为表示数据的最佳方式是使用直方图。 我不太了解 ploty 离线模块,但您可以(轻松)使用 matplotlib 做到这一点。
这是来自 matplotlib https://matplotlib.org/3.1.1/api/_as_gen/matplotlib.pyplot.hist.ZFC35FDC70D5FC69D269883A822C7A53的一些文档
和一个例子: https://matplotlib.org/3.1.1/gallery/statistics/hist.html
以及 1 个图表的多个数据集的示例https://matplotlib.org/3.1.1/gallery/statistics/histogram_multihist.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.