python - 如何用python平滑图形
问题描述
我正在努力使这个情节变得平滑。但我无法做到。尝试使用 splrep 进行插值,但它不起作用。任何帮助将不胜感激。该图是使用电流、电压和工作时间的数据框列绘制的。
df2=data[:2000]
plt.subplot(2,1,1)
plt.plot(df2['Op_Hours_Fcpm'],df2['Current'],'r')
plt.xlabel('Operating hours')
plt.title('Current Fluctuations')
plt.subplot(2,1,2)
plt.plot(df2['Op_Hours_Fcpm'],df2['Voltage'],'y')
plt.xlabel('Operating hours')
plt.title('Voltage Fluctuations')
plt.tight_layout()
plt.show()
我也尝试过另一种方式:
fig, ax = plt.subplots()
ax.plot(x_int, current_int, lw = 5, alpha = 0.30, label = 'current')
ax.plot(x_int, voltage_int, lw = 5, alpha = 0.30, label = 'voltage')
ax.set_xlabel('ripples')
ax.set_ylabel('hrs')
# Set the correct xticks
ax.set_xticks(x_map)
ax.set_xticklabels(x)
fig.legend(bbox_to_anchor=(0.7, 0.3), loc='upper left', ncol=1)
fig.show()
这给出了这个输出
解决方案
由于您没有提供原始数据,我尝试使用从图像中重新创建一些点
import pandas
print(pandas.__version__)
import matplotlib.pyplot as plt
x = [0.5, 0.5, 1, 1, 2, 2, 2 , 3]
y = [0, 600, 0, 600, 0, 1000, 600, 0]
plt.plot(x,y,'r');
plt.xlabel('Operating hours')
plt.title('Current Fluctuations');
plt.savefig('original.png');
产生
第一个子图的问题是某些时间包含多个值,包括“零”和非零值。这可以更容易地视为散点图
plt.scatter(x, y);
plt.xlabel('Operating hours')
plt.title('Current Fluctuations');
plt.savefig('scatter.png')
这个可视化问题指出了基础数据的问题。
一种选择是丢弃零数据并仅保留非零数据点。
推荐阅读
- node.js - 使用 Json 数据渲染 HTML 页面
- ansible - Ansible:删除标准输出中不需要的字符
- laravel - Laravel 路由不能通过 GET 工作,而相同的路由通过 VIEW 工作
- javascript - React - componentWillReceiveProps 条件不会呈现组件中的数据
- python - 如何在循环中启动来自不同类的对象?
- php - Eloquent 模型上的自定义过滤
- javascript - 通过 PHP 流式传输时,Safari 中的音频持续时间总是返回无穷大
- html - 并排不同尺寸的图像?
- javascript - 我的代码有什么问题?我没有收到错误消息;我没有得到任何回应
- django - 如何限制表单 Django 2.2 中的字段?