Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
xs = np.array(xs)
fvals = np.array(fvals)
# remove nan or inf values in fvals and xs
xs, fvals = delete_nan_inf(fvals, xs)
if size is None:
# 0.5 inch height per parameter
size = (18.5, max(xs.shape[1], 1) / 2)
if ax is None:
ax = plt.subplots()[1]
fig = plt.gcf()
fig.set_size_inches(*size)
# assign colors
colors = assign_colors(vals=fvals, colors=colors,
balance_alpha=balance_alpha)
# parameter indices
parameters_ind = list(range(1, xs.shape[1] + 1))[::-1]
# plot parameters
ax.xaxis.set_major_locator(MaxNLocator(integer=True))
for j_x, x in reversed(list(enumerate(xs))):
if j_x == 0:
tmp_legend = legend_text
else:
tmp_legend = None
ax.plot(x, parameters_ind,
linestyle,
color=colors[j_x],
marker='o',
legend_text: str
Label for line plots
Returns
-------
ax: matplotlib.Axes
The plot axes.
"""
# parse input
fvals = np.array(fvals)
# get colors
color = assign_colors([1.], color)
# axes
if ax is None:
ax = plt.subplots()[1]
ax.set_xlabel('Parameter value')
ax.set_ylabel('Log-posterior ratio')
fig = plt.gcf()
fig.set_size_inches(*size)
# plot
if fvals.size != 0:
ax.xaxis.set_major_locator(MaxNLocator(integer=True))
ax.plot(fvals[0, :], fvals[1, :], color=color[0], label=legend_text)
if legend_text is not None:
ax.legend()
# check how many results were passed
single_result = False
legend_error = False
if isinstance(results, list):
if len(results) == 1:
single_result = True
else:
single_result = True
results = [results]
# handle results according to their number
if single_result:
# assign colors and create list for later handling
if colors is not None:
colors = assign_colors(results, colors)
colors = [colors]
# create list of legends for later handling
if not isinstance(legends, list):
legends = [legends]
else:
# if more than one result is passed, we use one color per result
colors = assign_colors_for_result_list(len(results), colors)
# check whether list of legends has the correct length
if legends is None:
# No legends were passed: create some custom legends
legends = []
for i_leg in range(len(results)):
legends.append('Result ' + str(i_leg))
else:
The plot axes.
"""
fvals = result.optimize_result.get_for_key('fval')
values = result.optimize_result.get_for_key(key)
values, fvals = delete_nan_inf(fvals, values)
if start_indices is not None:
start_indices = process_start_indices(start_indices, len(values))
values = values[start_indices]
fvals = fvals[start_indices]
n_starts = len(values)
# assign colors
colors = assign_colors(vals=fvals, colors=color,
balance_alpha=False)
# sort TODO: issue # 378
sorted_indices = sorted(range(n_starts), key=lambda j: fvals[j])
values = values[sorted_indices]
if plot_type == 'line':
# plot line
ax.plot(range(n_starts), values, color=[0.7, 0.7, 0.7, 0.6])
# plot points
for i, v in enumerate(values):
if i == 0:
tmp_legend = legend
else:
tmp_legend = None
val = np.array(val)
fvals.append(val[1, -1])
else:
# convert to a list of numpy arrays
vals = np.array(vals)
if vals.shape[0] != 2 or vals.ndim != 2:
raise ('If numpy array is passed directly to lowlevel routine of'
'optimizer_history, shape needs to be 2 x n.')
fvals = [vals[1, -1]]
vals = [vals]
n_fvals = len(fvals)
# assign colors
# note: this has to happen before sorting
# to get the same colors in different plots
colors = assign_colors(fvals, colors)
# sort
indices = sorted(range(n_fvals), key=lambda j: fvals[j])
# plot
ax.xaxis.set_major_locator(MaxNLocator(integer=True))
for j, val in enumerate(vals):
# collect and parse data
j_fval = indices[j]
color = colors[j_fval]
if j == 0:
tmp_legend = legend_text
else:
tmp_legend = None
# line plots