绘制两个不同长度的不同数组 [英] Plotting two different arrays of different lengths
本文介绍了绘制两个不同长度的不同数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两个数组.一个是长度为(1000,)的原始信号,另一个是长度为(100,)的平滑信号.我想直观地表示平滑信号如何表示原始信号.由于这些数组的长度不同,因此我无法在另一个数组上绘制它们.在matplotlib中有办法吗?
I have two arrays. One is the raw signal of length (1000, ) and the other one is the smooth signal of length (100,). I want to visually represent how the smooth signal represents the raw signal. Since these arrays are of different length, I am not able to plot them one over the other. Is there a way to do so in matplotlib?
谢谢!
推荐答案
and then plot raw versus x1, and smooth versus x2:
plt.plot(x1, raw)
plt.plot(x2, smooth)
np.linspace(0,1,N)
返回长度为 N
的数组,其值从 0 到 1(含)等距.
np.linspace(0, 1, N)
returns an array of length N
with equally spaced values from 0 to 1 (inclusive).
import numpy as np
import matplotlib.pyplot as plt
np.random.seed(2015)
raw = (np.random.random(1000) - 0.5).cumsum()
smooth = raw.reshape(-1,10).mean(axis=1)
x1 = np.linspace(0, 1, 1000)
x2 = np.linspace(0, 1, 100)
plt.plot(x1, raw)
plt.plot(x2, smooth)
plt.show()
收益
这篇关于绘制两个不同长度的不同数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文