From 4af7a1c35bd340dca0647c152190083d875565eb Mon Sep 17 00:00:00 2001 From: Guillermo Aguilar Date: Fri, 20 Sep 2024 12:58:20 +0200 Subject: [PATCH] fixes model fit plot and aesthestic for it and psyc. function plot --- psignifit/psigniplot.py | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/psignifit/psigniplot.py b/psignifit/psigniplot.py index 0c0049a..38e1869 100644 --- a/psignifit/psigniplot.py +++ b/psignifit/psigniplot.py @@ -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() @@ -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 @@ -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): @@ -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 @@ -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() @@ -188,7 +188,7 @@ 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) @@ -196,6 +196,7 @@ def plot_marginal(result: Result, 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 @@ -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]) @@ -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')