{"id":1933,"date":"2023-08-10T23:40:47","date_gmt":"2023-08-11T06:40:47","guid":{"rendered":"https:\/\/gantovnik.com\/bio-tips\/?p=1933"},"modified":"2023-08-10T23:40:48","modified_gmt":"2023-08-11T06:40:48","slug":"381-overlapping-densities-ridge-plot-using-seaborn-library","status":"publish","type":"post","link":"https:\/\/gantovnik.com\/bio-tips\/2023\/08\/381-overlapping-densities-ridge-plot-using-seaborn-library\/","title":{"rendered":"#381 Overlapping densities ridge plot using seaborn library"},"content":{"rendered":"<p><a href=\"https:\/\/gantovnik.com\/bio-tips\/2023\/08\/381-overlapping-densities-ridge-plot-using-seaborn-library\/ex381\/\" rel=\"attachment wp-att-1935\"><img data-recalc-dims=\"1\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2023\/08\/ex381.png?resize=750%2C500&#038;ssl=1\" alt=\"\" width=\"750\" height=\"500\" class=\"alignnone size-full wp-image-1935\" srcset=\"https:\/\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2023\/08\/ex381.png 750w, https:\/\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2023\/08\/ex381-480x320.png 480w\" sizes=\"(min-width: 0px) and (max-width: 480px) 480px, (min-width: 481px) 750px, 100vw\" \/><\/a><\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\n#Overlapping densities ridge plot using seaborn library\r\nimport matplotlib.pyplot as plt\r\nimport pandas as pd\r\nimport numpy as np\r\n#conda install -c anaconda seaborn\r\nimport seaborn as sns\r\nsns.set_theme(style=&quot;white&quot;, rc={&quot;axes.facecolor&quot;: (0, 0, 0, 0)})\r\n\r\n\r\ndef main():\r\n    # Create the data\r\n    rs = np.random.RandomState(1979)\r\n    x = rs.randn(500)\r\n    g = np.tile(list(&quot;ABCDEFGHIJ&quot;), 50)\r\n    df = pd.DataFrame(dict(x=x, g=g))\r\n    m = df.g.map(ord)\r\n    df&#x5B;&quot;x&quot;] += m\r\n\r\n    # Initialize the FacetGrid object\r\n    pal = sns.cubehelix_palette(10, rot=-.25, light=.7)\r\n    g = sns.FacetGrid(df, row=&quot;g&quot;, hue=&quot;g&quot;, aspect=15, height=.5, palette=pal)\r\n\r\n    # Draw the densities in a few steps\r\n    g.map(sns.kdeplot, &quot;x&quot;,\r\n          bw_adjust=.5, clip_on=False,\r\n          fill=True, alpha=1, linewidth=1.5)\r\n    g.map(sns.kdeplot, &quot;x&quot;, clip_on=False, color=&quot;w&quot;, lw=2, bw_adjust=.5)\r\n\r\n    # passing color=None to refline() uses the hue mapping\r\n    g.refline(y=0, linewidth=2, linestyle=&quot;-&quot;, color=None, clip_on=False)\r\n\r\n\r\n    # Define and use a simple function to label the plot in axes coordinates\r\n    def label(x, color, label):\r\n        ax = plt.gca()\r\n        ax.text(0, .2, label, fontweight=&quot;bold&quot;, color=color,\r\n                ha=&quot;left&quot;, va=&quot;center&quot;, transform=ax.transAxes)\r\n\r\n\r\n    g.map(label, &quot;x&quot;)\r\n\r\n    # Set the subplots to overlap\r\n    g.figure.subplots_adjust(hspace=-.25)\r\n\r\n    # Remove axes details that don't play well with overlap\r\n    g.set_titles(&quot;&quot;)\r\n    g.set(yticks=&#x5B;], ylabel=&quot;&quot;)\r\n    g.despine(bottom=True, left=True)\r\n    plt.savefig(&quot;ex381.png&quot;, dpi=100)\r\n    plt.show()\r\n\r\nif __name__ == '__main__':\r\n    main()\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>#Overlapping densities ridge plot using seaborn library import matplotlib.pyplot as plt import pandas as pd import numpy as np #conda install -c anaconda seaborn import seaborn as sns sns.set_theme(style=&quot;white&quot;, rc={&quot;axes.facecolor&quot;: (0, 0, 0, 0)}) def main(): # Create the data rs = np.random.RandomState(1979) x = rs.randn(500) g = np.tile(list(&quot;ABCDEFGHIJ&quot;), 50) df = pd.DataFrame(dict(x=x, g=g)) m [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"nf_dc_page":"","_et_pb_use_builder":"","_et_pb_old_content":"","_et_gb_content_width":"","_lmt_disableupdate":"yes","_lmt_disable":"","jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[91,2,92],"tags":[],"class_list":["post-1933","post","type-post","status-publish","format-standard","hentry","category-plot","category-python","category-seaborn"],"modified_by":"gantovnik","jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p8bH0k-vb","jetpack_likes_enabled":true,"jetpack-related-posts":[{"id":1936,"url":"https:\/\/gantovnik.com\/bio-tips\/2023\/08\/382-dot-plot-with-several-variables-using-seaborn-library\/","url_meta":{"origin":1933,"position":0},"title":"#382 Dot plot with several variables using seaborn library","author":"gantovnik","date":"2023-08-10","format":false,"excerpt":"[code language=\"python\"] #Overlapping densities ridge plot using seaborn library import matplotlib.pyplot as plt #conda install -c anaconda seaborn import seaborn as sns sns.set_theme(style=\"whitegrid\") def main(): # Load the dataset crashes = sns.load_dataset(\"car_crashes\") # Make the PairGrid g = sns.PairGrid(crashes.sort_values(\"total\", ascending=False), x_vars=crashes.columns[:-3], y_vars=[\"abbrev\"], height=10, aspect=.25) # Draw a dot plot using\u2026","rel":"","context":"In &quot;plot&quot;","block_context":{"text":"plot","link":"https:\/\/gantovnik.com\/bio-tips\/category\/plot\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2023\/08\/ex382.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2023\/08\/ex382.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2023\/08\/ex382.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2023\/08\/ex382.png?resize=700%2C400&ssl=1 2x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2023\/08\/ex382.png?resize=1050%2C600&ssl=1 3x"},"classes":[]},{"id":1037,"url":"https:\/\/gantovnik.com\/bio-tips\/2021\/11\/185-creating-a-scatter-plot-using-seaborn\/","url_meta":{"origin":1933,"position":1},"title":"#185 Creating a scatter plot using seaborn","author":"gantovnik","date":"2021-11-07","format":false,"excerpt":"[code language=\"python\"] import matplotlib.pyplot as plt import numpy as np import pandas as pd import os import seaborn as sns os.chdir(r'D:\\projects\\wordpress\\ex185') os.getcwd() url = \"https:\/\/archive.ics.uci.edu\/ml\/machine-learning-databases\/auto-mpg\/auto-mpg.data\" df = pd.read_csv(url) column_names = ['mpg', 'cylinders', 'displacement', 'horsepower', 'weight', 'acceleration', 'year', 'origin', 'name'] df = pd.read_csv(url, names= column_names, delim_whitespace=True) df.loc[df.horsepower == '?', 'horsepower'] =\u2026","rel":"","context":"In &quot;python&quot;","block_context":{"text":"python","link":"https:\/\/gantovnik.com\/bio-tips\/category\/python\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2021\/11\/ex185b.jpg?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2021\/11\/ex185b.jpg?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2021\/11\/ex185b.jpg?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2021\/11\/ex185b.jpg?resize=700%2C400&ssl=1 2x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2021\/11\/ex185b.jpg?resize=1050%2C600&ssl=1 3x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2021\/11\/ex185b.jpg?resize=1400%2C800&ssl=1 4x"},"classes":[]},{"id":1943,"url":"https:\/\/gantovnik.com\/bio-tips\/2023\/08\/385-scatterplot-matrix-using-seaborn-library\/","url_meta":{"origin":1933,"position":2},"title":"#385 Scatterplot matrix using seaborn library","author":"gantovnik","date":"2023-08-13","format":false,"excerpt":"[code language=\"python\"] #Scatterplot matrix using seaborn library import matplotlib.pyplot as plt #conda install -c anaconda seaborn import seaborn as sns sns.set_theme(style=\"ticks\") def main(): df = sns.load_dataset(\"penguins\") sns.pairplot(df, hue=\"species\") plt.savefig(\"ex385.png\", dpi=100) plt.show() if __name__ == '__main__': main() [\/code]","rel":"","context":"In &quot;plot&quot;","block_context":{"text":"plot","link":"https:\/\/gantovnik.com\/bio-tips\/category\/plot\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2023\/08\/ex385.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2023\/08\/ex385.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2023\/08\/ex385.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2023\/08\/ex385.png?resize=700%2C400&ssl=1 2x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2023\/08\/ex385.png?resize=1050%2C600&ssl=1 3x"},"classes":[]},{"id":1032,"url":"https:\/\/gantovnik.com\/bio-tips\/2021\/11\/184-creating-a-boxplot-using-seaborn\/","url_meta":{"origin":1933,"position":3},"title":"#183 Creating a boxplot using seaborn","author":"gantovnik","date":"2021-11-07","format":false,"excerpt":"[code language=\"python\"] import numpy as np import pandas as pd import seaborn as sns import matplotlib.pyplot as plt import os os.chdir(r'D:\\projects\\wordpress\\ex184') os.getcwd() url = \"https:\/\/archive.ics.uci.edu\/ml\/machine-learning-databases\/auto-mpg\/auto-mpg.data\" df = pd.read_csv(url) column_names = ['mpg', 'cylinders', 'displacement', 'horsepower', 'weight', 'acceleration', 'year', 'origin', 'name'] df = pd.read_csv(url, names= column_names, delim_whitespace=True) print(df.head()) #Convert the horsepower and\u2026","rel":"","context":"In &quot;python&quot;","block_context":{"text":"python","link":"https:\/\/gantovnik.com\/bio-tips\/category\/python\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2021\/11\/ex184.jpg?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2021\/11\/ex184.jpg?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2021\/11\/ex184.jpg?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2021\/11\/ex184.jpg?resize=700%2C400&ssl=1 2x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2021\/11\/ex184.jpg?resize=1050%2C600&ssl=1 3x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2021\/11\/ex184.jpg?resize=1400%2C800&ssl=1 4x"},"classes":[]},{"id":1940,"url":"https:\/\/gantovnik.com\/bio-tips\/2023\/08\/384-linear-regression-with-marginal-distributions-using-seaborn-library\/","url_meta":{"origin":1933,"position":4},"title":"#384 Linear regression with marginal distributions using seaborn library","author":"gantovnik","date":"2023-08-11","format":false,"excerpt":"[code language=\"python\"] #Linear regression with marginal distributions using seaborn library import matplotlib.pyplot as plt #conda install -c anaconda seaborn import seaborn as sns sns.set_theme(style=\"darkgrid\") def main(): tips = sns.load_dataset(\"tips\") g = sns.jointplot(x=\"total_bill\", y=\"tip\", data=tips, kind=\"reg\", truncate=False, xlim=(0, 60), ylim=(0, 12), color=\"m\", height=7) plt.savefig(\"ex384.png\", dpi=100) plt.show() if __name__ == '__main__': main()\u2026","rel":"","context":"In &quot;plot&quot;","block_context":{"text":"plot","link":"https:\/\/gantovnik.com\/bio-tips\/category\/plot\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2023\/08\/ex384.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2023\/08\/ex384.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2023\/08\/ex384.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2023\/08\/ex384.png?resize=700%2C400&ssl=1 2x"},"classes":[]},{"id":1931,"url":"https:\/\/gantovnik.com\/bio-tips\/2023\/08\/380-joint-kernel-density-estimate-using-seaborn-library\/","url_meta":{"origin":1933,"position":5},"title":"#380 Joint kernel density estimate using seaborn library","author":"gantovnik","date":"2023-08-10","format":false,"excerpt":"[code language=\"python\"] #Joint kernel density estimate using seaborn library import matplotlib.pyplot as plt #conda install -c anaconda seaborn import seaborn as sns sns.set_theme(style=\"ticks\") def main(): # Load the penguins dataset penguins = sns.load_dataset(\"penguins\") # Show the joint distribution using kernel density estimation g = sns.jointplot( data=penguins, x=\"bill_length_mm\", y=\"bill_depth_mm\", hue=\"species\", kind=\"kde\"\u2026","rel":"","context":"In &quot;plot&quot;","block_context":{"text":"plot","link":"https:\/\/gantovnik.com\/bio-tips\/category\/plot\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2023\/08\/ex380.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2023\/08\/ex380.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2023\/08\/ex380.png?resize=525%2C300&ssl=1 1.5x"},"classes":[]}],"_links":{"self":[{"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/posts\/1933","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/comments?post=1933"}],"version-history":[{"count":0,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/posts\/1933\/revisions"}],"wp:attachment":[{"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/media?parent=1933"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/categories?post=1933"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/tags?post=1933"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}