如何用python平滑图形

2024-09-29 19:29:15 发布

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

我正在努力使这个情节平顺。但是我做不到。尝试使用splrep进行插值,但不起作用。任何帮助都将不胜感激。该图是使用电流、电压和工作小时的数据框列绘制的。 image

image

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()

这给了这个输出


Tags: plotfigoperatingpltcurrentaxintdf2
1条回答
网友
1楼 · 发布于 2024-09-29 19:29:15

由于您没有提供原始数据,我尝试使用

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');

产生

original

第一个子批次的问题是,某些时间包含多个值,包括“零值”和非零值。这可以更容易地看作是散点图

plt.scatter(x, y);
plt.xlabel('Operating hours')
plt.title('Current Fluctuations');
plt.savefig('scatter.png')

scatter

这个可视化问题指向了底层数据的一个问题

一种选择是丢弃零数据,只保留非零数据点

相关问题 更多 >

    热门问题