Skip to content

Commit

Permalink
fix: labels work properly in plots
Browse files Browse the repository at this point in the history
  • Loading branch information
fhchl committed Feb 27, 2019
1 parent 74a24c6 commit b1a5771
Showing 1 changed file with 26 additions and 6 deletions.
32 changes: 26 additions & 6 deletions response.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,9 @@ def plot_magnitude(
if dblim is not None:
ax.set_ylim(dblim)

if label is not None:
ax.legend()

return fig

def plot_phase(
Expand Down Expand Up @@ -421,7 +424,7 @@ def plot_phase(
np.unwrap(np.angle(freq_plotready)) if unwrap else np.angle(freq_plotready)
)

ax.semilogx(self.freqs, phase, **plot_kw)
ax.semilogx(self.freqs, phase, label=label, **plot_kw)
ax.set_xlabel("Frequency [Hz]")
ax.set_ylabel("Phase [rad]")
ax.set_title("Phase response")
Expand All @@ -433,10 +436,20 @@ def plot_phase(
if ylim:
ax.set_ylim(ylim)

if label is not None:
ax.legend()

return fig

def plot_time(
self, use_ax=None, slce=None, tlim=None, ylim=None, plot_kw={}, **fig_kw
self,
use_ax=None,
slce=None,
tlim=None,
ylim=None,
label=None,
plot_kw={},
**fig_kw,
):
"""Plot time response."""
if use_ax is None:
Expand All @@ -458,16 +471,20 @@ def plot_time(
(self.nt, -1)
)

ax.plot(self.times, time_plotready, **plot_kw)
ax.plot(self.times, time_plotready, label=label, **plot_kw)
ax.set_xlabel("Time [s]")
ax.set_ylabel("")
ax.set_title("Time response")
ax.grid(True)

if tlim:
ax.set_xlim(tlim)
if ylim:
ax.set_ylim(ylim)

if label is not None:
ax.legend()

return fig

def plot_group_delay(
Expand Down Expand Up @@ -505,17 +522,22 @@ def plot_group_delay(
# TODO: use scipy.signal.group_delay here as below has problem at larger delays
grpd = -np.gradient(np.unwrap(np.angle(freq_plotready)), df, axis=0)

ax.semilogx(self.freqs, grpd, **plot_kw)
ax.semilogx(self.freqs, grpd, label=label, **plot_kw)
ax.set_xlabel("Frequency [Hz]")
ax.set_ylabel("Delay [s]")
ax.set_title("Group Delay")
ax.grid(True)

if flim is None:
flim = (10, self.fs / 2)
ax.set_xlim(flim)

if ylim:
ax.set_ylim(ylim)

if label is not None:
ax.legend()

return fig

def plot_power_in_bands(
Expand Down Expand Up @@ -669,8 +691,6 @@ def timecrop(self, start, end):
else:
_, i_end = find_nearest(self.times, end)

print(i_start, i_end)

h = self.in_time[..., i_start:i_end]

new_response = self.from_time(self.fs, h)
Expand Down

0 comments on commit b1a5771

Please sign in to comment.