.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "_examples/utils/plot_scale_colormap.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note Click :ref:`here ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr__examples_utils_plot_scale_colormap.py: Show colormap for various scalings ---------------------------------- The dummy piece of code included below demonstrates visually that the transformation using the MinMaxScaler or StandardScaler does not affect the colormap. These transformations compute a 'mapping' but do not alter the values and/or their distribution. See the formulas below: .. math:: MinMaxScaler (x_{scaled}) = x_{std} * (x_{max} - x_{min}) + x_{min} .. math:: where x_{std} = (x - x_{min}) / (x_{max} - x_{min}) .. math:: StandardScaler (x_{scaled}) = (x - x_{mean}) / x_{std} .. GENERATED FROM PYTHON SOURCE LINES 26-90 .. rst-class:: sphx-glr-horizontal * .. image-sg:: /_examples/utils/images/sphx_glr_plot_scale_colormap_001.png :alt: original, MinMax, StdScaler, log :srcset: /_examples/utils/images/sphx_glr_plot_scale_colormap_001.png :class: sphx-glr-multi-img * .. image-sg:: /_examples/utils/images/sphx_glr_plot_scale_colormap_002.png :alt: original, MinMax, StdScaler :srcset: /_examples/utils/images/sphx_glr_plot_scale_colormap_002.png :class: sphx-glr-multi-img .. code-block:: default :lineno-start: 27 # Library import numpy as np import seaborn as sns import matplotlib as mpl import matplotlib.pyplot as plt from sklearn.preprocessing import MinMaxScaler from sklearn.preprocessing import StandardScaler # See https://matplotlib.org/devdocs/users/explain/customizing.html mpl.rcParams['axes.titlesize'] = 8 mpl.rcParams['axes.labelsize'] = 8 mpl.rcParams['xtick.labelsize'] = 8 mpl.rcParams['ytick.labelsize'] = 8 # Create data linear = np.linspace(0, 10, 100) rayleigh = np.random.rayleigh(3, 100) original = np.concatenate((linear, rayleigh)).reshape(-1, 1) #original = rayleigh.reshape(-1, 1) # Create scalers mmx = MinMaxScaler().fit(original) std = StandardScaler().fit(original) # Display fig, axs = plt.subplots(nrows=1, ncols=4, sharey=True, sharex=False, figsize=(8, 7)) for i, (name, data) in enumerate( [('original', original), ('MinMax', mmx.transform(original)), ('StdScaler', std.transform(original)), ('log', np.log(original))]): sns.heatmap(data.reshape(10, -1), annot=False, linewidth=0.5, cmap='coolwarm', ax=axs[i], zorder=1, cbar_kws={ # 'label': 'value [unit]', 'use_gridspec': True, 'location': 'right' } ) axs[i].set_title(name) fig, axs = plt.subplots(nrows=3, ncols=1, sharey=True, sharex=False, figsize=(8, 7)) for i, (name, data) in enumerate( [('original', original), ('MinMax', mmx.transform(original)), ('StdScaler', std.transform(original))]): #sns.displot(data=data.reshape(1, -1).tolist(), ax=axs[i], #bins=100) #kind="kde") #sns.kdeplot(data=data.reshape(1, -1).tolist(), ax=axs) sns.histplot(data=data.reshape(1, -1).tolist(), ax=axs[i], kde=True) axs[i].set_title(name) # Show plt.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 0.976 seconds) .. _sphx_glr_download__examples_utils_plot_scale_colormap.py: .. only :: html .. container:: sphx-glr-footer :class: sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_scale_colormap.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_scale_colormap.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_