你已经派生过 gprMax
镜像自地址
https://gitee.com/sunhf/gprMax.git
已同步 2025-08-04 11:36:52 +08:00
Corrected overlapping text in plots
这个提交包含在:
@@ -21,7 +21,6 @@ import logging
|
||||
from pathlib import Path
|
||||
|
||||
import h5py
|
||||
import matplotlib.gridspec as gridspec
|
||||
import matplotlib.pyplot as plt
|
||||
import numpy as np
|
||||
|
||||
@@ -240,232 +239,204 @@ def mpl_plot(
|
||||
|
||||
# Figure 1
|
||||
# Plot incident voltage
|
||||
fig1, ax = plt.subplots(
|
||||
fig1, axs = plt.subplots(
|
||||
num="Transmitter transmission line parameters",
|
||||
figsize=(20, 12),
|
||||
nrows=4,
|
||||
ncols=2,
|
||||
facecolor="w",
|
||||
edgecolor="w",
|
||||
)
|
||||
gs1 = gridspec.GridSpec(4, 2, hspace=0.7)
|
||||
ax = plt.subplot(gs1[0, 0])
|
||||
ax.plot(time, Vinc, "r", lw=2, label="Vinc")
|
||||
ax.set_title("Incident voltage")
|
||||
ax.set_xlabel("Time [s]")
|
||||
ax.set_ylabel("Voltage [V]")
|
||||
ax.set_xlim([0, np.amax(time)])
|
||||
ax.grid(which="both", axis="both", linestyle="-.")
|
||||
plt.subplots_adjust(hspace=0.75)
|
||||
axs[0, 0].plot(time, Vinc, "r", lw=2, label="Vinc")
|
||||
axs[0, 0].set_title("Incident voltage")
|
||||
axs[0, 0].set_xlabel("Time [s]")
|
||||
axs[0, 0].set_ylabel("Voltage [V]")
|
||||
axs[0, 0].set_xlim([0, np.amax(time)])
|
||||
axs[0, 0].grid(which="both", axis="both", linestyle="-.")
|
||||
|
||||
# Plot frequency spectra of incident voltage
|
||||
ax = plt.subplot(gs1[0, 1])
|
||||
markerline, stemlines, baseline = ax.stem(freqs[pltrange], Vincp[pltrange], "-.")
|
||||
markerline, stemlines, baseline = axs[0, 1].stem(freqs[pltrange], Vincp[pltrange], "-.")
|
||||
plt.setp(baseline, "linewidth", 0)
|
||||
plt.setp(stemlines, "color", "r")
|
||||
plt.setp(markerline, "markerfacecolor", "r", "markeredgecolor", "r")
|
||||
ax.plot(freqs[pltrange], Vincp[pltrange], "r", lw=2)
|
||||
ax.set_title("Incident voltage")
|
||||
ax.set_xlabel("Frequency [Hz]")
|
||||
ax.set_ylabel("Power [dB]")
|
||||
ax.grid(which="both", axis="both", linestyle="-.")
|
||||
axs[0, 1].plot(freqs[pltrange], Vincp[pltrange], "r", lw=2)
|
||||
axs[0, 1].set_title("Incident voltage")
|
||||
axs[0, 1].set_xlabel("Frequency [Hz]")
|
||||
axs[0, 1].set_ylabel("Power [dB]")
|
||||
axs[0, 1].grid(which="both", axis="both", linestyle="-.")
|
||||
|
||||
# Plot incident current
|
||||
ax = plt.subplot(gs1[1, 0])
|
||||
ax.plot(time, Iinc, "b", lw=2, label="Vinc")
|
||||
ax.set_title("Incident current")
|
||||
ax.set_xlabel("Time [s]")
|
||||
ax.set_ylabel("Current [A]")
|
||||
ax.set_xlim([0, np.amax(time)])
|
||||
ax.grid(which="both", axis="both", linestyle="-.")
|
||||
axs[1, 0].plot(time, Iinc, "b", lw=2, label="Vinc")
|
||||
axs[1, 0].set_title("Incident current")
|
||||
axs[1, 0].set_xlabel("Time [s]")
|
||||
axs[1, 0].set_ylabel("Current [A]")
|
||||
axs[1, 0].set_xlim([0, np.amax(time)])
|
||||
axs[1, 0].grid(which="both", axis="both", linestyle="-.")
|
||||
|
||||
# Plot frequency spectra of incident current
|
||||
ax = plt.subplot(gs1[1, 1])
|
||||
markerline, stemlines, baseline = ax.stem(freqs[pltrange], Iincp[pltrange], "-.")
|
||||
markerline, stemlines, baseline = axs[1, 1].stem(freqs[pltrange], Iincp[pltrange], "-.")
|
||||
plt.setp(baseline, "linewidth", 0)
|
||||
plt.setp(stemlines, "color", "b")
|
||||
plt.setp(markerline, "markerfacecolor", "b", "markeredgecolor", "b")
|
||||
ax.plot(freqs[pltrange], Iincp[pltrange], "b", lw=2)
|
||||
ax.set_title("Incident current")
|
||||
ax.set_xlabel("Frequency [Hz]")
|
||||
ax.set_ylabel("Power [dB]")
|
||||
ax.grid(which="both", axis="both", linestyle="-.")
|
||||
axs[1, 1].plot(freqs[pltrange], Iincp[pltrange], "b", lw=2)
|
||||
axs[1, 1].set_title("Incident current")
|
||||
axs[1, 1].set_xlabel("Frequency [Hz]")
|
||||
axs[1, 1].set_ylabel("Power [dB]")
|
||||
axs[1, 1].grid(which="both", axis="both", linestyle="-.")
|
||||
|
||||
# Plot total voltage
|
||||
ax = plt.subplot(gs1[2, 0])
|
||||
ax.plot(time, Vtotal, "r", lw=2, label="Vinc")
|
||||
ax.set_title("Total (incident + reflected) voltage")
|
||||
ax.set_xlabel("Time [s]")
|
||||
ax.set_ylabel("Voltage [V]")
|
||||
ax.set_xlim([0, np.amax(time)])
|
||||
ax.grid(which="both", axis="both", linestyle="-.")
|
||||
axs[2, 0].plot(time, Vtotal, "r", lw=2, label="Vinc")
|
||||
axs[2, 0].set_title("Total (incident + reflected) voltage")
|
||||
axs[2, 0].set_xlabel("Time [s]")
|
||||
axs[2, 0].set_ylabel("Voltage [V]")
|
||||
axs[2, 0].set_xlim([0, np.amax(time)])
|
||||
axs[2, 0].grid(which="both", axis="both", linestyle="-.")
|
||||
|
||||
# Plot frequency spectra of total voltage
|
||||
ax = plt.subplot(gs1[2, 1])
|
||||
markerline, stemlines, baseline = ax.stem(freqs[pltrange], Vtotalp[pltrange], "-.")
|
||||
markerline, stemlines, baseline = axs[2, 1].stem(freqs[pltrange], Vtotalp[pltrange], "-.")
|
||||
plt.setp(baseline, "linewidth", 0)
|
||||
plt.setp(stemlines, "color", "r")
|
||||
plt.setp(markerline, "markerfacecolor", "r", "markeredgecolor", "r")
|
||||
ax.plot(freqs[pltrange], Vtotalp[pltrange], "r", lw=2)
|
||||
ax.set_title("Total (incident + reflected) voltage")
|
||||
ax.set_xlabel("Frequency [Hz]")
|
||||
ax.set_ylabel("Power [dB]")
|
||||
ax.grid(which="both", axis="both", linestyle="-.")
|
||||
axs[2, 1].plot(freqs[pltrange], Vtotalp[pltrange], "r", lw=2)
|
||||
axs[2, 1].set_title("Total (incident + reflected) voltage")
|
||||
axs[2, 1].set_xlabel("Frequency [Hz]")
|
||||
axs[2, 1].set_ylabel("Power [dB]")
|
||||
axs[2, 1].grid(which="both", axis="both", linestyle="-.")
|
||||
|
||||
# Plot total current
|
||||
ax = plt.subplot(gs1[3, 0])
|
||||
ax.plot(time, Itotal, "b", lw=2, label="Vinc")
|
||||
ax.set_title("Total (incident + reflected) current")
|
||||
ax.set_xlabel("Time [s]")
|
||||
ax.set_ylabel("Current [A]")
|
||||
ax.set_xlim([0, np.amax(time)])
|
||||
ax.grid(which="both", axis="both", linestyle="-.")
|
||||
axs[3, 0].plot(time, Itotal, "b", lw=2, label="Vinc")
|
||||
axs[3, 0].set_title("Total (incident + reflected) current")
|
||||
axs[3, 0].set_xlabel("Time [s]")
|
||||
axs[3, 0].set_ylabel("Current [A]")
|
||||
axs[3, 0].set_xlim([0, np.amax(time)])
|
||||
axs[3, 0].grid(which="both", axis="both", linestyle="-.")
|
||||
|
||||
# Plot frequency spectra of total current
|
||||
ax = plt.subplot(gs1[3, 1])
|
||||
markerline, stemlines, baseline = ax.stem(freqs[pltrange], Itotalp[pltrange], "-.")
|
||||
markerline, stemlines, baseline = axs[3, 1].stem(freqs[pltrange], Itotalp[pltrange], "-.")
|
||||
plt.setp(baseline, "linewidth", 0)
|
||||
plt.setp(stemlines, "color", "b")
|
||||
plt.setp(markerline, "markerfacecolor", "b", "markeredgecolor", "b")
|
||||
ax.plot(freqs[pltrange], Itotalp[pltrange], "b", lw=2)
|
||||
ax.set_title("Total (incident + reflected) current")
|
||||
ax.set_xlabel("Frequency [Hz]")
|
||||
ax.set_ylabel("Power [dB]")
|
||||
ax.grid(which="both", axis="both", linestyle="-.")
|
||||
axs[3, 1].plot(freqs[pltrange], Itotalp[pltrange], "b", lw=2)
|
||||
axs[3, 1].set_title("Total (incident + reflected) current")
|
||||
axs[3, 1].set_xlabel("Frequency [Hz]")
|
||||
axs[3, 1].set_ylabel("Power [dB]")
|
||||
axs[3, 1].grid(which="both", axis="both", linestyle="-.")
|
||||
|
||||
# Plot reflected (reflected) voltage
|
||||
# ax = plt.subplot(gs1[4, 0])
|
||||
# ax.plot(time, Vref, 'r', lw=2, label='Vref')
|
||||
# ax.set_title('Reflected voltage')
|
||||
# ax.set_xlabel('Time [s]')
|
||||
# ax.set_ylabel('Voltage [V]')
|
||||
# ax.set_xlim([0, np.amax(time)])
|
||||
# ax.grid(which='both', axis='both', linestyle='-.')
|
||||
# axs[4, 0].plot(time, Vref, 'r', lw=2, label='Vref')
|
||||
# axs[4, 0].set_title('Reflected voltage')
|
||||
# axs[4, 0].set_xlabel('Time [s]')
|
||||
# axs[4, 0].set_ylabel('Voltage [V]')
|
||||
# axs[4, 0].set_xlim([0, np.amax(time)])
|
||||
# axs[4, 0].grid(which='both', axis='both', linestyle='-.')
|
||||
|
||||
# Plot frequency spectra of reflected voltage
|
||||
# ax = plt.subplot(gs1[4, 1])
|
||||
# markerline, stemlines, baseline = ax.stem(freqs[pltrange], Vrefp[pltrange],
|
||||
# '-.')
|
||||
# markerline, stemlines, baseline = axs[4, 1].stem(freqs[pltrange], Vrefp[pltrange], '-.')
|
||||
# plt.setp(baseline, 'linewidth', 0)
|
||||
# plt.setp(stemlines, 'color', 'r')
|
||||
# plt.setp(markerline, 'markerfacecolor', 'r', 'markeredgecolor', 'r')
|
||||
# ax.plot(freqs[pltrange], Vrefp[pltrange], 'r', lw=2)
|
||||
# ax.set_title('Reflected voltage')
|
||||
# ax.set_xlabel('Frequency [Hz]')
|
||||
# ax.set_ylabel('Power [dB]')
|
||||
# ax.grid(which='both', axis='both', linestyle='-.')
|
||||
# axs[4, 1].plot(freqs[pltrange], Vrefp[pltrange], 'r', lw=2)
|
||||
# axs[4, 1].set_title('Reflected voltage')
|
||||
# axs[4, 1].set_xlabel('Frequency [Hz]')
|
||||
# axs[4, 1].set_ylabel('Power [dB]')
|
||||
# axs[4, 1].grid(which='both', axis='both', linestyle='-.')
|
||||
|
||||
# Plot reflected (reflected) current
|
||||
# ax = plt.subplot(gs1[5, 0])
|
||||
# ax.plot(time, Iref, 'b', lw=2, label='Iref')
|
||||
# ax.set_title('Reflected current')
|
||||
# ax.set_xlabel('Time [s]')
|
||||
# ax.set_ylabel('Current [A]')
|
||||
# ax.set_xlim([0, np.amax(time)])
|
||||
# ax.grid(which='both', axis='both', linestyle='-.')
|
||||
# axs[5, 0].plot(time, Iref, 'b', lw=2, label='Iref')
|
||||
# axs[5, 0].set_title('Reflected current')
|
||||
# axs[5, 0].set_xlabel('Time [s]')
|
||||
# axs[5, 0].set_ylabel('Current [A]')
|
||||
# axs[5, 0].set_xlim([0, np.amax(time)])
|
||||
# axs[5, 0].grid(which='both', axis='both', linestyle='-.')
|
||||
|
||||
# Plot frequency spectra of reflected current
|
||||
# ax = plt.subplot(gs1[5, 1])
|
||||
# markerline, stemlines, baseline = ax.stem(freqs[pltrange], Irefp[pltrange],
|
||||
# '-.')
|
||||
# markerline, stemlines, baseline = axs[5, 1].stem(freqs[pltrange], Irefp[pltrange], '-.')
|
||||
# plt.setp(baseline, 'linewidth', 0)
|
||||
# plt.setp(stemlines, 'color', 'b')
|
||||
# plt.setp(markerline, 'markerfacecolor', 'b', 'markeredgecolor', 'b')
|
||||
# ax.plot(freqs[pltrange], Irefp[pltrange], 'b', lw=2)
|
||||
# ax.set_title('Reflected current')
|
||||
# ax.set_xlabel('Frequency [Hz]')
|
||||
# ax.set_ylabel('Power [dB]')
|
||||
# ax.grid(which='both', axis='both', linestyle='-.')
|
||||
# axs[5, 1].plot(freqs[pltrange], Irefp[pltrange], 'b', lw=2)
|
||||
# axs[5, 1].set_title('Reflected current')
|
||||
# axs[5, 1].set_xlabel('Frequency [Hz]')
|
||||
# axs[5, 1].set_ylabel('Power [dB]')
|
||||
# axs[5, 1].grid(which='both', axis='both', linestyle='-.')
|
||||
|
||||
# Figure 2
|
||||
# Plot frequency spectra of s11
|
||||
fig2, ax = plt.subplots(
|
||||
num="Antenna parameters", figsize=(20, 12), facecolor="w", edgecolor="w"
|
||||
fig2, axs = plt.subplots(num="Antenna parameters",
|
||||
figsize=(20, 12),
|
||||
nrows=2,
|
||||
ncols=2,
|
||||
facecolor="w",
|
||||
edgecolor="w"
|
||||
)
|
||||
gs2 = gridspec.GridSpec(2, 2, hspace=0.3)
|
||||
ax = plt.subplot(gs2[0, 0])
|
||||
markerline, stemlines, baseline = ax.stem(freqs[pltrange], s11[pltrange], "-.")
|
||||
plt.subplots_adjust(hspace=0.75)
|
||||
markerline, stemlines, baseline = axs[0, 0].stem(freqs[pltrange], s11[pltrange], "-.")
|
||||
plt.setp(baseline, "linewidth", 0)
|
||||
plt.setp(stemlines, "color", "g")
|
||||
plt.setp(markerline, "markerfacecolor", "g", "markeredgecolor", "g")
|
||||
ax.plot(freqs[pltrange], s11[pltrange], "g", lw=2)
|
||||
ax.set_title("s11")
|
||||
ax.set_xlabel("Frequency [Hz]")
|
||||
ax.set_ylabel("Power [dB]")
|
||||
# ax.set_xlim([0, 5e9])
|
||||
# ax.set_ylim([-25, 0])
|
||||
ax.grid(which="both", axis="both", linestyle="-.")
|
||||
axs[0, 0].plot(freqs[pltrange], s11[pltrange], "g", lw=2)
|
||||
axs[0, 0].set_title("s11")
|
||||
axs[0, 0].set_xlabel("Frequency [Hz]")
|
||||
axs[0, 0].set_ylabel("Power [dB]")
|
||||
axs[0, 0].grid(which="both", axis="both", linestyle="-.")
|
||||
|
||||
# Plot frequency spectra of s21
|
||||
if s21 is not None:
|
||||
ax = plt.subplot(gs2[0, 1])
|
||||
markerline, stemlines, baseline = ax.stem(freqs[pltrange], s21[pltrange], "-.")
|
||||
markerline, stemlines, baseline = axs[0, 1].stem(freqs[pltrange], s21[pltrange], "-.")
|
||||
plt.setp(baseline, "linewidth", 0)
|
||||
plt.setp(stemlines, "color", "g")
|
||||
plt.setp(markerline, "markerfacecolor", "g", "markeredgecolor", "g")
|
||||
ax.plot(freqs[pltrange], s21[pltrange], "g", lw=2)
|
||||
ax.set_title("s21")
|
||||
ax.set_xlabel("Frequency [Hz]")
|
||||
ax.set_ylabel("Power [dB]")
|
||||
# ax.set_xlim([0.88e9, 1.02e9])
|
||||
# ax.set_ylim([-25, 50])
|
||||
ax.grid(which="both", axis="both", linestyle="-.")
|
||||
axs[0, 1].plot(freqs[pltrange], s21[pltrange], "g", lw=2)
|
||||
axs[0, 1].set_title("s21")
|
||||
axs[0, 1].set_xlabel("Frequency [Hz]")
|
||||
axs[0, 1].set_ylabel("Power [dB]")
|
||||
axs[0, 1].grid(which="both", axis="both", linestyle="-.")
|
||||
|
||||
# Plot input resistance (real part of impedance)
|
||||
ax = plt.subplot(gs2[1, 0])
|
||||
markerline, stemlines, baseline = ax.stem(freqs[pltrange], zin[pltrange].real, "-.")
|
||||
markerline, stemlines, baseline = axs[1, 0].stem(freqs[pltrange], zin[pltrange].real, "-.")
|
||||
plt.setp(baseline, "linewidth", 0)
|
||||
plt.setp(stemlines, "color", "g")
|
||||
plt.setp(markerline, "markerfacecolor", "g", "markeredgecolor", "g")
|
||||
ax.plot(freqs[pltrange], zin[pltrange].real, "g", lw=2)
|
||||
ax.set_title("Input impedance (resistive)")
|
||||
ax.set_xlabel("Frequency [Hz]")
|
||||
ax.set_ylabel("Resistance [Ohms]")
|
||||
# ax.set_xlim([0.88e9, 1.02e9])
|
||||
ax.set_ylim(bottom=0)
|
||||
# ax.set_ylim([0, 300])
|
||||
ax.grid(which="both", axis="both", linestyle="-.")
|
||||
axs[1, 0].plot(freqs[pltrange], zin[pltrange].real, "g", lw=2)
|
||||
axs[1, 0].set_title("Input impedance (resistive)")
|
||||
axs[1, 0].set_xlabel("Frequency [Hz]")
|
||||
axs[1, 0].set_ylabel("Resistance [Ohms]")
|
||||
axs[1, 0].set_ylim(bottom=0)
|
||||
axs[1, 0].grid(which="both", axis="both", linestyle="-.")
|
||||
|
||||
# Plot input reactance (imaginery part of impedance)
|
||||
ax = plt.subplot(gs2[1, 1])
|
||||
markerline, stemlines, baseline = ax.stem(freqs[pltrange], zin[pltrange].imag, "-.")
|
||||
markerline, stemlines, baseline = axs[1, 1].stem(freqs[pltrange], zin[pltrange].imag, "-.")
|
||||
plt.setp(baseline, "linewidth", 0)
|
||||
plt.setp(stemlines, "color", "g")
|
||||
plt.setp(markerline, "markerfacecolor", "g", "markeredgecolor", "g")
|
||||
ax.plot(freqs[pltrange], zin[pltrange].imag, "g", lw=2)
|
||||
ax.set_title("Input impedance (reactive)")
|
||||
ax.set_xlabel("Frequency [Hz]")
|
||||
ax.set_ylabel("Reactance [Ohms]")
|
||||
# ax.set_xlim([0.88e9, 1.02e9])
|
||||
# ax.set_ylim([-300, 300])
|
||||
ax.grid(which="both", axis="both", linestyle="-.")
|
||||
axs[1, 1].plot(freqs[pltrange], zin[pltrange].imag, "g", lw=2)
|
||||
axs[1, 1].set_title("Input impedance (reactive)")
|
||||
axs[1, 1].set_xlabel("Frequency [Hz]")
|
||||
axs[1, 1].set_ylabel("Reactance [Ohms]")
|
||||
axs[1, 1].grid(which="both", axis="both", linestyle="-.")
|
||||
|
||||
# Plot input admittance (magnitude)
|
||||
# ax = plt.subplot(gs2[2, 0])
|
||||
# markerline, stemlines, baseline = ax.stem(freqs[pltrange], np.abs(yin[pltrange]),
|
||||
# '-.')
|
||||
# markerline, stemlines, baseline = axs[2, 0].stem(freqs[pltrange], np.abs(yin[pltrange]), '-.')
|
||||
# plt.setp(baseline, 'linewidth', 0)
|
||||
# plt.setp(stemlines, 'color', 'g')
|
||||
# plt.setp(markerline, 'markerfacecolor', 'g', 'markeredgecolor', 'g')
|
||||
# ax.plot(freqs[pltrange], np.abs(yin[pltrange]), 'g', lw=2)
|
||||
# ax.set_title('Input admittance (magnitude)')
|
||||
# ax.set_xlabel('Frequency [Hz]')
|
||||
# ax.set_ylabel('Admittance [Siemens]')
|
||||
# ax.set_xlim([0.88e9, 1.02e9])
|
||||
# ax.set_ylim([0, 0.035])
|
||||
# ax.grid(which='both', axis='both', linestyle='-.')
|
||||
# axs[2, 0].plot(freqs[pltrange], np.abs(yin[pltrange]), 'g', lw=2)
|
||||
# axs[2, 0].set_title('Input admittance (magnitude)')
|
||||
# axs[2, 0].set_xlabel('Frequency [Hz]')
|
||||
# axs[2, 0].set_ylabel('Admittance [Siemens]')
|
||||
# axs[2, 0].grid(which='both', axis='both', linestyle='-.')
|
||||
|
||||
# Plot input admittance (phase)
|
||||
# ax = plt.subplot(gs2[2, 1])
|
||||
# markerline, stemlines, baseline = ax.stem(freqs[pltrange], np.angle(yin[pltrange], deg=True),
|
||||
# '-.')
|
||||
# markerline, stemlines, baseline = axs[2, 1].stem(freqs[pltrange], np.angle(yin[pltrange], deg=True), '-.')
|
||||
# plt.setp(baseline, 'linewidth', 0)
|
||||
# plt.setp(stemlines, 'color', 'g')
|
||||
# plt.setp(markerline, 'markerfacecolor', 'g', 'markeredgecolor', 'g')
|
||||
# ax.plot(freqs[pltrange], np.angle(yin[pltrange], deg=True), 'g', lw=2)
|
||||
# ax.set_title('Input admittance (phase)')
|
||||
# ax.set_xlabel('Frequency [Hz]')
|
||||
# ax.set_ylabel('Phase [degrees]')
|
||||
# ax.set_xlim([0.88e9, 1.02e9])
|
||||
# ax.set_ylim([-40, 100])
|
||||
# ax.grid(which='both', axis='both', linestyle='-.')
|
||||
# axs[2, 1].plot(freqs[pltrange], np.angle(yin[pltrange], deg=True), 'g', lw=2)
|
||||
# axs[2, 1].set_title('Input admittance (phase)')
|
||||
# axs[2, 1].set_xlabel('Frequency [Hz]')
|
||||
# axs[2, 1].set_ylabel('Phase [degrees]')
|
||||
# axs[2, 1].grid(which='both', axis='both', linestyle='-.')
|
||||
|
||||
if save:
|
||||
filepath = Path(filename)
|
||||
|
在新工单中引用
屏蔽一个用户