Skip to content
Snippets Groups Projects

Resolve "Add plots"

Merged Leo Bouscarrat requested to merge 5-add-plots-2 into wip_clean_scripts
5 files
+ 37
14
Compare changes
  • Side-by-side
  • Inline
Files
5
import matplotlib.pyplot as plt
import numpy as np
from sklearn.neighbors.kde import KernelDensity
import pandas as pd
class Plotter(object):
@staticmethod
def weight_density(weights, X, file_path):
X_plot = [np.exp(elem) for elem in weights]
fig, ax = plt.subplots()
def weight_density(all_experiment_weights, file_path):
'''
Function that creates the figure with the density of the weights
:param all_experiment_weights: The weights for the different experiments
:param file path: str, path where the figure will be saved
'''
for kernel in ['gaussian', 'tophat', 'epanechnikov']:
kde = KernelDensity(kernel=kernel, bandwidth=0.5).fit(X_plot)
log_dens = kde.score_samples(X_plot)
ax.plot(X_plot, np.exp(log_dens), '-',
label="kernel = '{0}'".format(kernel))
all_experiment_weights = np.array(list(all_experiment_weights.values()))
n = len(all_experiment_weights)
colors = Plotter.get_colors_from_cmap(n)
ax.legend(loc='upper left')
ax.plot(X[:, 0], -0.005 - 0.01 * np.random.random(X.shape[0]), '+k')
fig, ax = plt.subplots()
for i in range(n):
for weights in all_experiment_weights[i]:
pd.Series([weight for weight in weights if weight != 0]).plot.kde(
figsize=(15, 10), ax=ax, color=colors[i])
ax.set_xlim(-4, 9)
ax.set_ylim(-0.02, 0.4)
ax.set_title('Density weights of the OMP')
fig.savefig(file_path, dpi=fig.dpi)
plt.close(fig)
Loading