matlab对python的“保留”替代方案

2024-09-28 18:55:59 发布

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

我有一些名为group的数据集,我想将它们绘制在一个空的图形上。我的意思是当计算机读取新的数据集时,我的程序会将其添加到图形中

for groups in seconds_list:
    group = f[(groups)][:]

    i_data = group['real']
    q_data = group['imag']

    i_data = np.array(i_data, dtype=float64)
    q_data = np.array(q_data, dtype=float64)    

    # 10.log(10.(I^2+Q^2)+1) then rotate array w/ np.rot90()
    power_ch1 = np.rot90(np.array(np.log10(((np.add(np.square(np.abs(i_data[:, ::2])) , np.square(np.abs(q_data[:, ::2]))))*10)+1)*10 , dtype=float64))
    
    print("Group: ", groups)

    fig, ax = plt.subplots()
    ax.set_xlim(0, 475*200)
    ax.set_ylim(0, 3000)

    tx, ty = my_list[i]
    ax.imshow(power_ch1, cmap='viridis', interpolation='nearest', aspect='auto', extent = (tx, tx+200, ty, ty+2700))
    i +=1
    plt.tight_layout()
    plt.show()

我正在使用这个代码,但我不能保存旧的绘图。我想在旧数据集旁边添加新数据集。我怎么做?我在matlab中使用hold on,但是我找不到python的替代品


Tags: 数据图形datanpgrouppltaxarray
1条回答
网友
1楼 · 发布于 2024-09-28 18:55:59

可以使用matlab样式而不是object样式(通过执行fig, ax = plt.subplots()来使用),如下例所示:

import matplotlib.pyplot as plt

x = np.linspace(1., 10., 100)
y1 = np.log(x)
plt.plot(x, y1, color='r', marker='*', label='log(x)')

y2 = np.sin(x)
plt.plot(x, y2, color='b', marker='^', label='sin(x)')

plt.legend()
plt.xlabel('x')
plt.ylabel('y(x)')
plt.show()

输出

enter image description here

您可以找到有关matplotlibin this great book绘图功能的更多信息

干杯

相关问题 更多 >