.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/plotting/_ridge.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note Click :ref:`here ` to download the full example code or to run this example in your browser via Binder .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_plotting__ridge.py: ================== 6.10 ridge plot ================== .. GENERATED FROM PYTHON SOURCE LINES 7-18 .. code-block:: default # sphinx_gallery_thumbnail_number = 2 import numpy as np import pandas as pd from easy_mpl import ridge import matplotlib.pyplot as plt from easy_mpl.utils import version_info version_info() # print version information of all the packages being used .. rst-class:: sphx-glr-script-out .. code-block:: none {'easy_mpl': '0.21.4', 'matplotlib': '3.8.4', 'numpy': '1.26.4', 'pandas': '1.5.3', 'scipy': '1.13.1'} .. GENERATED FROM PYTHON SOURCE LINES 19-23 .. code-block:: default data_ = np.random.random(size=100) _ = ridge(data_) .. image-sg:: /auto_examples/plotting/images/sphx_glr__ridge_001.png :alt: ridge :srcset: /auto_examples/plotting/images/sphx_glr__ridge_001.png, /auto_examples/plotting/images/sphx_glr__ridge_001_2_0x.png 2.0x :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 24-28 .. code-block:: default data_ = np.random.random((100, 3)) _ = ridge(data_) .. image-sg:: /auto_examples/plotting/images/sphx_glr__ridge_002.png :alt: ridge :srcset: /auto_examples/plotting/images/sphx_glr__ridge_002.png, /auto_examples/plotting/images/sphx_glr__ridge_002_2_0x.png 2.0x :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 29-30 specifying colormap .. GENERATED FROM PYTHON SOURCE LINES 30-33 .. code-block:: default _ = ridge(data_, color="Blues") .. image-sg:: /auto_examples/plotting/images/sphx_glr__ridge_003.png :alt: ridge :srcset: /auto_examples/plotting/images/sphx_glr__ridge_003.png, /auto_examples/plotting/images/sphx_glr__ridge_003_2_0x.png 2.0x :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 34-35 The data can also be in the form of pandas DataFrame .. GENERATED FROM PYTHON SOURCE LINES 35-38 .. code-block:: default _ = ridge(pd.DataFrame(data_)) .. image-sg:: /auto_examples/plotting/images/sphx_glr__ridge_004.png :alt: ridge :srcset: /auto_examples/plotting/images/sphx_glr__ridge_004.png, /auto_examples/plotting/images/sphx_glr__ridge_004_2_0x.png 2.0x :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 39-40 if we don't want to fill the ridge, we can specify the color as white .. GENERATED FROM PYTHON SOURCE LINES 40-43 .. code-block:: default _ = ridge(np.random.random(100), color=["white"]) .. image-sg:: /auto_examples/plotting/images/sphx_glr__ridge_005.png :alt: ridge :srcset: /auto_examples/plotting/images/sphx_glr__ridge_005.png, /auto_examples/plotting/images/sphx_glr__ridge_005_2_0x.png 2.0x :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 44-45 we can draw all the ridges on same axes as below .. GENERATED FROM PYTHON SOURCE LINES 45-49 .. code-block:: default df = pd.DataFrame(np.random.random((100, 3)), dtype='object') _ = ridge(df, share_axes=True, fill_kws={"alpha": 0.5}) .. image-sg:: /auto_examples/plotting/images/sphx_glr__ridge_006.png :alt: ridge :srcset: /auto_examples/plotting/images/sphx_glr__ridge_006.png, /auto_examples/plotting/images/sphx_glr__ridge_006_2_0x.png 2.0x :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 50-51 we can also provide an existing axes to plot on .. GENERATED FROM PYTHON SOURCE LINES 51-55 .. code-block:: default _, ax = plt.subplots() _ = ridge(df, ax=ax, fill_kws={"alpha": 0.5}) .. image-sg:: /auto_examples/plotting/images/sphx_glr__ridge_007.png :alt: ridge :srcset: /auto_examples/plotting/images/sphx_glr__ridge_007.png, /auto_examples/plotting/images/sphx_glr__ridge_007_2_0x.png 2.0x :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 56-57 The data can also be in the form of list of arrays .. GENERATED FROM PYTHON SOURCE LINES 57-62 .. code-block:: default x1 = np.random.random(100) x2 = np.random.random(100) _ = ridge([x1, x2], color=np.random.random((3, 2))) .. image-sg:: /auto_examples/plotting/images/sphx_glr__ridge_008.png :alt: ridge :srcset: /auto_examples/plotting/images/sphx_glr__ridge_008.png, /auto_examples/plotting/images/sphx_glr__ridge_008_2_0x.png 2.0x :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 63-64 The length of arrays need not to be constant/same. We can use arrays of different lengths .. GENERATED FROM PYTHON SOURCE LINES 64-69 .. code-block:: default x1 = np.random.random(100) x2 = np.random.random(90) _ = ridge([x1, x2], color=np.random.random((3, 2))) .. image-sg:: /auto_examples/plotting/images/sphx_glr__ridge_009.png :alt: ridge :srcset: /auto_examples/plotting/images/sphx_glr__ridge_009.png, /auto_examples/plotting/images/sphx_glr__ridge_009_2_0x.png 2.0x :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 70-74 .. code-block:: default f = "https://raw.githubusercontent.com/AtrCheema/AI4Water/master/ai4water/datasets/arg_busan.csv" df = pd.read_csv(f, index_col='index') print(df.shape) df.head() .. rst-class:: sphx-glr-script-out .. code-block:: none (1446, 25) .. raw:: html
tide_cm wat_temp_c sal_psu air_temp_c pcp_mm ... aac_coppml Total_otus otu_5575 otu_273 otu_94
index
6/19/2018 0:00 36.407149 19.321232 33.956058 19.780000 0.0 ... NaN NaN NaN NaN NaN
6/19/2018 0:30 35.562515 19.320124 33.950508 19.093333 0.0 ... NaN NaN NaN NaN NaN
6/19/2018 1:00 34.808016 19.319666 33.942532 18.733333 0.0 ... NaN NaN NaN NaN NaN
6/19/2018 1:30 30.645216 19.320406 33.931263 18.760000 0.0 ... NaN NaN NaN NaN NaN
6/19/2018 2:00 26.608980 19.326729 33.917961 18.633333 0.0 ... NaN NaN NaN NaN NaN

5 rows × 25 columns



.. GENERATED FROM PYTHON SOURCE LINES 75-88 .. code-block:: default cols = ['air_temp_c', 'wat_temp_c', 'sal_psu', 'tide_cm', 'rel_hum', 'pcp12_mm', 'wind_dir_deg', 'wind_speed_mps' ] _ = ridge(df[cols]) .. image-sg:: /auto_examples/plotting/images/sphx_glr__ridge_010.png :alt: ridge :srcset: /auto_examples/plotting/images/sphx_glr__ridge_010.png, /auto_examples/plotting/images/sphx_glr__ridge_010_2_0x.png 2.0x :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 89-94 .. code-block:: default f = 'https://media.githubusercontent.com/media/HakaiInstitute/essd2021-hydromet-datapackage/main/2013-2019_Discharge1015_5min.csv' df = pd.read_csv(f) df.index = pd.to_datetime(df.pop('Datetime')) print(df.shape) df.head() .. rst-class:: sphx-glr-script-out .. code-block:: none (543568, 12) .. raw:: html
Watershed Qlevel Qflag Qrate Qrate_min ... Qvol_min Qvol_max Qmm Qmm_min Qmm_max
Datetime
2014-07-31 13:50:00+00:00 WTS1015 2 AV 0.0442 0.0025 ... 0.75 29.85 0.004 0.0002 0.009
2014-07-31 13:55:00+00:00 WTS1015 2 AV 0.0442 0.0025 ... 0.75 29.85 0.004 0.0002 0.009
2014-07-31 14:00:00+00:00 WTS1015 2 AV 0.0442 0.0025 ... 0.75 29.85 0.004 0.0002 0.009
2014-07-31 14:05:00+00:00 WTS1015 2 AV 0.0442 0.0025 ... 0.75 29.85 0.004 0.0002 0.009
2014-07-31 14:10:00+00:00 WTS1015 2 AV 0.0442 0.0025 ... 0.75 29.85 0.004 0.0002 0.009

5 rows × 12 columns



.. GENERATED FROM PYTHON SOURCE LINES 95-101 .. code-block:: default groupby_year = df.groupby(lambda x: x.year) _ = ridge( [grp['Qrate'].resample('D').interpolate(method='linear') for _, grp in groupby_year], labels=[name for name, _ in groupby_year], ) .. image-sg:: /auto_examples/plotting/images/sphx_glr__ridge_011.png :alt: ridge :srcset: /auto_examples/plotting/images/sphx_glr__ridge_011.png, /auto_examples/plotting/images/sphx_glr__ridge_011_2_0x.png 2.0x :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 7.286 seconds) .. _sphx_glr_download_auto_examples_plotting__ridge.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: binder-badge .. image:: images/binder_badge_logo.svg :target: https://mybinder.org/v2/gh/AtrCheema/python-seekho/master?urlpath=lab/tree/notebooks/auto_examples/plotting/_ridge.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: _ridge.py <_ridge.py>` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: _ridge.ipynb <_ridge.ipynb>` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_