{"id":1938,"date":"2023-08-11T01:19:54","date_gmt":"2023-08-11T08:19:54","guid":{"rendered":"https:\/\/gantovnik.com\/bio-tips\/?p=1938"},"modified":"2023-08-11T01:19:54","modified_gmt":"2023-08-11T08:19:54","slug":"383-horizontal-bar-plot-using-seaborn-library","status":"publish","type":"post","link":"https:\/\/gantovnik.com\/bio-tips\/2023\/08\/383-horizontal-bar-plot-using-seaborn-library\/","title":{"rendered":"#383 Horizontal bar plot using seaborn library"},"content":{"rendered":"<p><a href=\"https:\/\/gantovnik.com\/bio-tips\/2023\/08\/383-horizontal-bar-plot-using-seaborn-library\/ex383\/\" rel=\"attachment wp-att-1939\"><img data-recalc-dims=\"1\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2023\/08\/ex383.png?resize=600%2C1030&#038;ssl=1\" alt=\"\" width=\"600\" height=\"1030\" class=\"alignnone size-full wp-image-1939\" srcset=\"https:\/\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2023\/08\/ex383.png 600w, https:\/\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2023\/08\/ex383-480x824.png 480w\" sizes=\"(min-width: 0px) and (max-width: 480px) 480px, (min-width: 481px) 600px, 100vw\" \/><\/a><\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\n#Horizontal bar plot using seaborn library\r\nimport matplotlib.pyplot as plt\r\n#conda install -c anaconda seaborn\r\nimport seaborn as sns\r\nsns.set_theme(style=&quot;whitegrid&quot;)\r\n\r\ndef main():\r\n    # Initialize the matplotlib figure\r\n    f, ax = plt.subplots(figsize=(6, 15))\r\n\r\n    # Load the example car crash dataset\r\n    crashes = sns.load_dataset(&quot;car_crashes&quot;).sort_values(&quot;total&quot;, ascending=False)\r\n\r\n    # Plot the total crashes\r\n    sns.set_color_codes(&quot;pastel&quot;)\r\n    sns.barplot(x=&quot;total&quot;, y=&quot;abbrev&quot;, data=crashes,\r\n                label=&quot;Total&quot;, color=&quot;b&quot;)\r\n\r\n    # Plot the crashes where alcohol was involved\r\n    sns.set_color_codes(&quot;muted&quot;)\r\n    sns.barplot(x=&quot;alcohol&quot;, y=&quot;abbrev&quot;, data=crashes,\r\n                label=&quot;Alcohol-involved&quot;, color=&quot;b&quot;)\r\n\r\n    # Add a legend and informative axis label\r\n    ax.legend(ncol=2, loc=&quot;lower right&quot;, frameon=True)\r\n    ax.set(xlim=(0, 24), ylabel=&quot;&quot;,\r\n           xlabel=&quot;Automobile collisions per billion miles&quot;)\r\n    sns.despine(left=True, bottom=True)\r\n\r\n    plt.savefig(&quot;ex383.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>#Horizontal bar plot using seaborn library import matplotlib.pyplot as plt #conda install -c anaconda seaborn import seaborn as sns sns.set_theme(style=&quot;whitegrid&quot;) def main(): # Initialize the matplotlib figure f, ax = plt.subplots(figsize=(6, 15)) # Load the example car crash dataset crashes = sns.load_dataset(&quot;car_crashes&quot;).sort_values(&quot;total&quot;, ascending=False) # Plot the total crashes sns.set_color_codes(&quot;pastel&quot;) sns.barplot(x=&quot;total&quot;, y=&quot;abbrev&quot;, data=crashes, label=&quot;Total&quot;, color=&quot;b&quot;) # [&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-1938","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-vg","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":1938,"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":1927,"url":"https:\/\/gantovnik.com\/bio-tips\/2023\/08\/378-horizontal-boxplot-with-observations-using-seaborn-library\/","url_meta":{"origin":1938,"position":1},"title":"#378 Horizontal boxplot with observations using seaborn library","author":"gantovnik","date":"2023-08-10","format":false,"excerpt":"[code language=\"python\"] #Horizontal boxplot with observations import matplotlib.pyplot as plt #conda install -c anaconda seaborn import seaborn as sns sns.set_theme(style=\"ticks\") def main(): # Initialize the figure with a logarithmic x axis f, ax = plt.subplots(figsize=(7, 6)) ax.set_xscale(\"log\") # Load the example planets dataset planets = sns.load_dataset(\"planets\") # Plot the orbital\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\/ex378.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2023\/08\/ex378.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2023\/08\/ex378.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2023\/08\/ex378.png?resize=700%2C400&ssl=1 2x"},"classes":[]},{"id":1917,"url":"https:\/\/gantovnik.com\/bio-tips\/2023\/08\/374-hexbin-plot-with-marginal-distributions-using-seaborn-library\/","url_meta":{"origin":1938,"position":2},"title":"#374 Hexbin plot with marginal distributions using seaborn library","author":"gantovnik","date":"2023-08-10","format":false,"excerpt":"[code language=\"python\"] import numpy as np import matplotlib.pyplot as plt #conda install -c anaconda seaborn import seaborn as sns sns.set_theme(style=\"ticks\") def main(): rs = np.random.RandomState(11) x = rs.gamma(2, size=1000) y = -.5 * x + rs.normal(size=1000) sns.jointplot(x=x, y=y, kind=\"hex\", color=\"#4CB323\") plt.savefig(\"ex374.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\/ex374.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2023\/08\/ex374.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2023\/08\/ex374.png?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":1919,"url":"https:\/\/gantovnik.com\/bio-tips\/2023\/08\/375-regression-fit-over-a-strip-plot-using-seaborn-library\/","url_meta":{"origin":1938,"position":3},"title":"#375 Regression fit over a strip plot using seaborn library","author":"gantovnik","date":"2023-08-10","format":false,"excerpt":"[code language=\"python\"] #Regression fit over a strip plot import matplotlib.pyplot as plt #conda install -c anaconda seaborn import seaborn as sns sns.set_theme() def main(): mpg = sns.load_dataset(\"mpg\") sns.catplot( data=mpg, x=\"cylinders\", y=\"acceleration\", hue=\"weight\", native_scale=True, zorder=1 ) sns.regplot( data=mpg, x=\"cylinders\", y=\"acceleration\", scatter=False, truncate=False, order=2, color=\".2\", ) plt.savefig(\"ex375.png\", dpi=100) plt.show() if __name__ ==\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\/11\/ex394.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2023\/11\/ex394.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2023\/11\/ex394.png?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":1933,"url":"https:\/\/gantovnik.com\/bio-tips\/2023\/08\/381-overlapping-densities-ridge-plot-using-seaborn-library\/","url_meta":{"origin":1938,"position":4},"title":"#381 Overlapping densities ridge plot 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 import pandas as pd import numpy as np #conda install -c anaconda seaborn import seaborn as sns sns.set_theme(style=\"white\", rc={\"axes.facecolor\": (0, 0, 0, 0)}) def main(): # Create the data rs = np.random.RandomState(1979) x = rs.randn(500) g =\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\/ex381.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2023\/08\/ex381.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2023\/08\/ex381.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2023\/08\/ex381.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":1938,"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\/1938","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=1938"}],"version-history":[{"count":0,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/posts\/1938\/revisions"}],"wp:attachment":[{"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/media?parent=1938"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/categories?post=1938"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/tags?post=1938"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}