Hi there, this is my first post here, and i would like to introduce an function to a parallel coordinates plot.
`def _Paralel_plot(
dataframe:Dat...
For further actions, you may consider blocking this person and/or reporting abuse
def _Paralel_plot(
dataframe:DataFrame,
cols:list[str],
axes_names:list|None=None,
cmap_style:str|None=None,
alpha:float|None=None,
figsize:tuple|None=None,
invert_axes:list[int]=None,
savePath:str|None=None,) -> Figure|None:
'''
Dataframe: pandas dataframe
cols: dataframe cols to plot
axes_names: change the cols names
cmap_style: cmap style from matplolib cmaps. Default = None, viridis
alpha: line opacity. Default = 0.8
figsize: figure size. Default = (10,4)
invert_axes: list with axes_ids (as type integer) to invert. Default = None (coming soon)
BASE CODE CREDITS:
JohanC (user:12046409) encontrado em stackoverflow.com/questions/823063...
INTRODUCE:
categorical axes
cmap colors and cbar
'''
data = dataframe[cols].copy()
convert categoricals to numerics and save the encoder
encoders = {}
for name in cols:
JohanC starts here
ys = data[cols].values
n_rown, n_cols = ys.shape
Ajust the axes
scaler = MinMaxScaler(feature_range=(0,1))
zs = scaler.fit_transform(ys)
create figura and host axes
fig, host = plt.subplots(figsize=figsize or (10, 4))
cbar its always the last one column
cbar_col = zs[:, -1]
norm = mcolors.Normalize(vmin = cbar_col.min(), vmax = cbar_col.max())
cmap = get_cmap(cmap_style or 'viridis')
cbar:Colorbar = plt.colorbar(ScalarMappable(norm, cmap), ax=host, pad=0)
axes creation
axes = [host] + [host.twinx() for i in range(n_cols - 2)] + [cbar.ax]
for i, ax in enumerate(axes):
define yticks
old_yticks:list[np.ndarray] = [x.get_yticks() for x in axes]
new_yticklabels = scaler.inverse_transform(np.array(old_yticks).T)
for i, ax in enumerate(axes):
define xticks
host.set_xlim(0, n_cols - 1)
host.set_xticks(range(n_cols), axes_names or cols)
host.tick_params(axis='x', which='major', pad=7)
host.spines['right'].set_visible(False)
host.xaxis.tick_top()
generation of smoothed lines (see johanC)
for row in range(n_rown):
plt.tight_layout()