-
Notifications
You must be signed in to change notification settings - Fork 52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[MRG] Make all plots with time end at tstop #683
Changes from 4 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -78,9 +78,9 @@ def plt_show(show=True, fig=None, **kwargs): | |
(fig or plt).show(**kwargs) | ||
|
||
|
||
def plot_laminar_lfp(times, data, contact_labels, tmin=None, tmax=None, | ||
ax=None, decim=None, color='cividis', | ||
voltage_offset=50, voltage_scalebar=200, show=True): | ||
def plot_laminar_lfp(times, data, contact_labels, ax=None, decim=None, | ||
color='cividis', voltage_offset=50, voltage_scalebar=200, | ||
show=True): | ||
"""Plot laminar extracellular electrode array voltage time series. | ||
|
||
Parameters | ||
|
@@ -89,10 +89,6 @@ def plot_laminar_lfp(times, data, contact_labels, tmin=None, tmax=None, | |
Sampling times (in ms). | ||
data : Two-dimensional Numpy array | ||
The extracellular voltages as an (n_contacts, n_times) array. | ||
tmin : float | None | ||
Start time of plot in milliseconds. If None, plot entire simulation. | ||
tmax : float | None | ||
End time of plot in milliseconds. If None, plot entire simulation. | ||
ax : instance of matplotlib figure | None | ||
The matplotlib axis | ||
decim : int | list of int | None (default) | ||
|
@@ -168,11 +164,11 @@ def plot_laminar_lfp(times, data, contact_labels, tmin=None, tmax=None, | |
trace_offsets = np.arange(n_offsets)[:, np.newaxis] * voltage_offset | ||
|
||
for contact_no, trace in enumerate(np.atleast_2d(data)): | ||
plot_data, plot_times = _get_plot_data_trange(times, trace, tmin, tmax) | ||
plot_data = trace | ||
plot_times = times | ||
|
||
if decim is not None: | ||
plot_data, plot_times = _decimate_plot_data(decim, plot_data, | ||
plot_times) | ||
plot_data, plot_times = _decimate_plot_data(decim, trace, times) | ||
|
||
if isinstance(color, np.ndarray): | ||
col = color[contact_no] | ||
|
@@ -182,6 +178,7 @@ def plot_laminar_lfp(times, data, contact_labels, tmin=None, tmax=None, | |
col = color | ||
ax.plot(plot_times, plot_data + trace_offsets[contact_no], | ||
label=f'C{contact_no}', color=col) | ||
ax.set_xlim(right=times[-1]) | ||
|
||
if voltage_offset is not None: | ||
ax.set_ylim(-voltage_offset, n_offsets * voltage_offset) | ||
|
@@ -220,18 +217,14 @@ def plot_laminar_lfp(times, data, contact_labels, tmin=None, tmax=None, | |
return ax.get_figure() | ||
|
||
|
||
def plot_dipole(dpl, tmin=None, tmax=None, ax=None, layer='agg', decim=None, | ||
def plot_dipole(dpl, ax=None, layer='agg', decim=None, | ||
color='k', label="average", average=False, show=True): | ||
"""Simple layer-specific plot function. | ||
|
||
Parameters | ||
---------- | ||
dpl : instance of Dipole | list of Dipole instances | ||
The Dipole object. | ||
tmin : float or None | ||
Start time of plot in milliseconds. If None, plot entire simulation. | ||
tmax : float or None | ||
End time of plot in milliseconds. If None, plot entire simulation. | ||
ax : instance of matplotlib figure | None | ||
The matplotlib axis | ||
layer : str | ||
|
@@ -288,19 +281,19 @@ def plot_dipole(dpl, tmin=None, tmax=None, ax=None, layer='agg', decim=None, | |
if layer in dpl_trial.data.keys(): | ||
|
||
# extract scaled data and times | ||
data, times = _get_plot_data_trange(dpl_trial.times, | ||
dpl_trial.data[layer], | ||
tmin, tmax) | ||
data = dpl_trial.data[layer] | ||
times = dpl_trial.times | ||
if decim is not None: | ||
data, times = _decimate_plot_data(decim, data, times) | ||
data, times = _decimate_plot_data( | ||
decim, dpl_trial.data[layer], dpl_trial.times) | ||
tianqi-cheng marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if idx == len(dpl) - 1 and average: | ||
# the average dpl | ||
ax.plot(times, data, color=color, label=label, lw=1.5) | ||
else: | ||
alpha = 0.5 if average else 1. | ||
ax.plot(times, data, color=_lighten_color(color, 0.5), | ||
alpha=alpha, lw=1.) | ||
|
||
ax.set_xlim(right=dpl_trial.times[-1]) | ||
if average: | ||
ax.legend() | ||
|
||
|
@@ -477,12 +470,14 @@ def plot_spikes_hist(cell_response, trial_idx=None, ax=None, spike_types=None, | |
|
||
ax.set_ylabel("Counts") | ||
ax.legend() | ||
ax.set_xlim(right=cell_response.times[-1]) | ||
|
||
plt_show(show) | ||
return ax.get_figure() | ||
|
||
|
||
def plot_spikes_raster(cell_response, trial_idx=None, ax=None, show=True): | ||
def plot_spikes_raster(cell_response, trial_idx=None, | ||
ax=None, show=True): | ||
"""Plot the aggregate spiking activity according to cell type. | ||
|
||
Parameters | ||
|
@@ -538,6 +533,9 @@ def plot_spikes_raster(cell_response, trial_idx=None, ax=None, show=True): | |
cell_type_times, cell_type_ypos = [], [] | ||
for gid in cell_type_gids: | ||
gid_time = spike_times[spike_gids == gid] | ||
_, gid_time = _get_plot_data_trange( | ||
gid_time, gid_time, cell_response.times[0], | ||
cell_response.times[-1]) | ||
tianqi-cheng marked this conversation as resolved.
Show resolved
Hide resolved
|
||
cell_type_times.append(gid_time) | ||
cell_type_ypos.append(ypos) | ||
ypos = ypos - 1 | ||
|
@@ -552,7 +550,7 @@ def plot_spikes_raster(cell_response, trial_idx=None, ax=None, show=True): | |
ax.set_facecolor('k') | ||
ax.set_xlabel('Time (ms)') | ||
ax.get_yaxis().set_visible(False) | ||
ax.set_xlim(left=0) | ||
ax.set_xlim(left=0, right=cell_response.times[-1]) | ||
|
||
plt_show(show) | ||
return ax.get_figure() | ||
|
@@ -1179,8 +1177,8 @@ def _onclick(event): | |
return ax.get_figure() | ||
|
||
|
||
def plot_laminar_csd(times, data, contact_labels, ax=None, colorbar=True, | ||
show=True): | ||
def plot_laminar_csd(times, data, contact_labels, | ||
ax=None, colorbar=True, show=True): | ||
"""Plot laminar current source density (CSD) estimation from LFP array. | ||
|
||
Parameters | ||
|
@@ -1207,7 +1205,9 @@ def plot_laminar_csd(times, data, contact_labels, ax=None, colorbar=True, | |
import matplotlib.pyplot as plt | ||
if ax is None: | ||
_, ax = plt.subplots(1, 1, constrained_layout=True) | ||
|
||
times, data = _get_plot_data_trange(times, data, times[0], times[-1]) | ||
_, contact_labels = _get_plot_data_trange( | ||
times, contact_labels, times[0], times[-1]) | ||
im = ax.pcolormesh(times, contact_labels, np.array(data), | ||
cmap="jet_r", shading='auto') | ||
ax.set_title("CSD") | ||
|
@@ -1218,6 +1218,7 @@ def plot_laminar_csd(times, data, contact_labels, ax=None, colorbar=True, | |
|
||
ax.set_xlabel('Time (ms)') | ||
ax.set_ylabel('Electrode depth') | ||
ax.set_xlim(right=times[-1]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a nitpick, but I'd recommend defining There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi Ryan, it seems that there is no decim in this function. Do you want me to do this for other functions which contain decim? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah you're right. I didn't realize that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Re: adding the decimate feature to |
||
plt.tight_layout() | ||
plt_show(show) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is technically a backwards incompatible change. If some user has
tmin
andtmax
in their script, it will stop working now. The correct fix is to add a deprecation cycle. But if we want to assume that it's unlikely many users have this in their scripts, we should mark it as a "Bugfix" inwhats_new.rst
...There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought one reason to have
tmin
was for burn in period @rythorpe may have an opinion ...but it's true we can probably just set
plt.xlim((tmin, tmax))
to achieve the sameThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See my comment in the previous PR here. I don't think we need
tmin
at the plotting level, however, it would be useful at thesimulate_dipole
level for a burn-in period. That's a very different feature though and should probably be implemented in a separate PR.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that we should do a deprecation cycle for these input arguments though.