Skip to content

Commit

Permalink
fixes model fit plot and aesthestic for it and psyc. function plot
Browse files Browse the repository at this point in the history
  • Loading branch information
guillermoaguilar committed Sep 20, 2024
1 parent 85323cf commit 4af7a1c
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions psignifit/psigniplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def plot_psychometric_function(result: Result, # noqa: C901, this function is t
extrapolate_stimulus: float = 0.2,
x_label='Stimulus Level',
y_label='Proportion Correct'):
""" Plot oted psychometric function with the data.
""" Plot psychometric function fit together with the data.
"""
if ax is None:
ax = plt.gca()
Expand Down Expand Up @@ -74,8 +74,8 @@ def plot_psychometric_function(result: Result, # noqa: C901, this function is t

# AXIS SETTINGS
plt.axis('tight')
plt.xlabel(x_label)
plt.ylabel(y_label)
plt.xlabel(x_label, fontsize=14)
plt.ylabel(y_label, fontsize=14)
plt.ylim([ymin, 1])
return ax

Expand All @@ -89,7 +89,7 @@ def plot_stimulus_residuals(result: Result, ax: matplotlib.axes.Axes = None) ->
def plot_block_residuals(result: Result, ax: matplotlib.axes.Axes = None) -> matplotlib.axes.Axes:
if ax is None:
ax = plt.gca()
return _plot_residuals(range(result.data.shape[0]), 'Block Number', result, ax)
return _plot_residuals(result.data[:, 0], 'Block Number', result, ax)


def _plot_residuals(x_values: np.ndarray, x_label: str, result: Result, ax: matplotlib.axes.Axes = None):
Expand All @@ -114,8 +114,8 @@ def _plot_residuals(x_values: np.ndarray, x_label: str, result: Result, ax: matp
linefit = np.polyfit(x_values, deviance, 3)
ax.plot(x, np.polyval(linefit, x), 'k:', clip_on=False)

ax.xlabel(x_label, fontsize=14)
ax.ylabel('Deviance', fontsize=14)
ax.set_xlabel(x_label, fontsize=14)
ax.set_ylabel('Deviance', fontsize=14)
return ax


Expand Down Expand Up @@ -167,7 +167,7 @@ def plot_marginal(result: Result,
Args:
result: should be a result struct from the main psignifit routine
dim: The parameter to plot. 1=threshold, 2=width, 3=lambda, 4=gamma, 5=sigma
dim: The parameter to plot. 'threshold', 'width', 'lambda', 'gamma', 'eta'
"""
if ax is None:
ax = plt.gca()
Expand All @@ -188,14 +188,15 @@ def plot_marginal(result: Result,
ax.fill_between(ci_x, np.zeros_like(ci_x), np.interp(ci_x, x, marginal), color=line_color, alpha=0.5)

param_value = result.parameter_estimate[parameter]
ax.plot([param_value] * 2, [0, np.interp(param_value, x, marginal)], color=line_color)
ax.plot([param_value] * 2, [0, np.interp(param_value, x, marginal)], color='#000000')

if plot_prior:
ax.plot(x, result.prior_values[parameter], ls='--', color=prior_color, clip_on=False)

ax.plot(x, marginal, lw=line_width, c=line_color, clip_on=False)
ax.set_xlabel(x_label)
ax.set_ylabel(y_label)
ax.spines[['top', 'right']].set_visible(False)

return ax

Expand Down Expand Up @@ -242,7 +243,7 @@ def plot_prior(result: Result,
prior_x[-cumprior[cumprior >= .75].size], max(prior_x)]
plt.subplot(2, 3, i + 1)
plt.plot(params[param], priors[param], lw=line_width, c=line_color)
plt.scatter(x_percentiles, np.interp(x_percentiles, prior_x, priors[param]), ms=marker_size, c=colors)
plt.scatter(x_percentiles, np.interp(x_percentiles, prior_x, priors[param]), s=marker_size, c=colors)
plt.xlabel('Stimulus Level')
plt.ylabel('Density')
plt.title(titles[param])
Expand All @@ -252,7 +253,7 @@ def plot_prior(result: Result,
this_sigmoid_params = dict(sigmoid_params)
this_sigmoid_params[param] = param_value
plt.plot(sigmoid_x, sigmoid(sigmoid_x, **this_sigmoid_params), line_width=line_width, color=color)
plt.plot(data[:, 0], np.zeros(data[:, 0].shape), 'k.', ms=marker_size * .75)
plt.plot(data[:, 0], np.zeros(data[:, 0].shape), 'k.', s=marker_size * .75)
plt.xlabel('Stimulus Level')
plt.ylabel('Percent Correct')

Expand Down

0 comments on commit 4af7a1c

Please sign in to comment.