{"id":1147,"date":"2021-11-23T13:21:01","date_gmt":"2021-11-23T21:21:01","guid":{"rendered":"https:\/\/gantovnik.com\/bio-tips\/?p=1147"},"modified":"2021-11-23T13:37:55","modified_gmt":"2021-11-23T21:37:55","slug":"201-polyfit-and-polyval-2","status":"publish","type":"post","link":"https:\/\/gantovnik.com\/bio-tips\/2021\/11\/201-polyfit-and-polyval-2\/","title":{"rendered":"#202 Histogram using seaborn"},"content":{"rendered":"<p>Note LaTeX format in the plot title!<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nimport numpy as np\r\nimport matplotlib.pyplot as plt\r\nimport seaborn as sns\r\n# random vector with normal distribution\r\nsigma, mu = 2, 10\r\nx = sigma*np.random.standard_normal(10000) + mu\r\nsns.histplot(x, kde=True, bins=50)\r\n# title with LaTeX formatting\r\nplt.title('Histogram with $\\mu$={0}, $\\sigma$={1}'.format(mu,sigma))\r\nplt.savefig('ex202.png', dpi=72)\r\nplt.show()\r\n<\/pre>\n<p><img data-recalc-dims=\"1\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2021\/11\/ex202-1.png?resize=921%2C633&#038;ssl=1\" alt=\"\" width=\"921\" height=\"633\" class=\"alignnone size-full wp-image-1150\" srcset=\"https:\/\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2021\/11\/ex202-1.png 921w, https:\/\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2021\/11\/ex202-1-480x330.png 480w\" sizes=\"(min-width: 0px) and (max-width: 480px) 480px, (min-width: 481px) 921px, 100vw\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Note LaTeX format in the plot title! import numpy as np import matplotlib.pyplot as plt import seaborn as sns # random vector with normal distribution sigma, mu = 2, 10 x = sigma*np.random.standard_normal(10000) + mu sns.histplot(x, kde=True, bins=50) # title with LaTeX formatting plt.title(&#8216;Histogram with $\\mu$={0}, $\\sigma$={1}&#8217;.format(mu,sigma)) plt.savefig(&#8216;ex202.png&#8217;, dpi=72) plt.show()<\/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":[2],"tags":[],"class_list":["post-1147","post","type-post","status-publish","format-standard","hentry","category-python"],"modified_by":"gantovnik","jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p8bH0k-iv","jetpack_likes_enabled":true,"jetpack-related-posts":[{"id":2154,"url":"https:\/\/gantovnik.com\/bio-tips\/2024\/05\/420-histogram-plot-of-10000-random-samples-from-the-normal-distribution\/","url_meta":{"origin":1147,"position":0},"title":"#420 Histogram plot of 10000 random samples from the normal distribution","author":"gantovnik","date":"2024-05-03","format":false,"excerpt":"[code language=\"python\"] #Histogram of 10 000 random samples from the normal distribution import numpy as np import matplotlib.pyplot as plt # the mean and the standard deviation mu, sigma = 100.0, 8.0 samples = np.random.normal(loc=mu, scale=sigma, size=10000) counts, bins, patches = plt.hist(samples , bins=100, density=True, color='skyblue', alpha=0.75,edgecolor='black') plt.plot(bins, 1\/(sigma *\u2026","rel":"","context":"In &quot;matplotlib&quot;","block_context":{"text":"matplotlib","link":"https:\/\/gantovnik.com\/bio-tips\/category\/matplotlib\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2024\/05\/ex420.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2024\/05\/ex420.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2024\/05\/ex420.png?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":1923,"url":"https:\/\/gantovnik.com\/bio-tips\/2023\/08\/377-stacked-histogram-on-a-log-scale-using-seaborn\/","url_meta":{"origin":1147,"position":1},"title":"#377 Stacked histogram on a log scale using seaborn library","author":"gantovnik","date":"2023-08-10","format":false,"excerpt":"[code language=\"python\"] #Stacked histogram on a log scale import matplotlib.pyplot as plt import matplotlib as mpl #conda install -c anaconda seaborn import seaborn as sns sns.set_theme(style=\"ticks\") def main(): diamonds = sns.load_dataset(\"diamonds\") f, ax = plt.subplots(figsize=(7, 5)) sns.despine(f) sns.histplot( diamonds, x=\"price\", hue=\"cut\", multiple=\"stack\", palette=\"light:m_r\", edgecolor=\".3\", linewidth=.5, log_scale=True, ) ax.xaxis.set_major_formatter(mpl.ticker.ScalarFormatter()) ax.set_xticks([500, 1000,\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\/ex377.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2023\/08\/ex377.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2023\/08\/ex377.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2023\/08\/ex377.png?resize=700%2C400&ssl=1 2x"},"classes":[]},{"id":1028,"url":"https:\/\/gantovnik.com\/bio-tips\/2021\/11\/183-creating-a-histogram-using-seaborn\/","url_meta":{"origin":1147,"position":2},"title":"#184 Creating a histogram 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\\ex183') 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\/ex183.jpg?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2021\/11\/ex183.jpg?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2021\/11\/ex183.jpg?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2021\/11\/ex183.jpg?resize=700%2C400&ssl=1 2x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2021\/11\/ex183.jpg?resize=1050%2C600&ssl=1 3x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2021\/11\/ex183.jpg?resize=1400%2C800&ssl=1 4x"},"classes":[]},{"id":1215,"url":"https:\/\/gantovnik.com\/bio-tips\/2021\/11\/210-parametric-curve-in-3d-2-2-2-2-2\/","url_meta":{"origin":1147,"position":3},"title":"#215 Placing text boxes","author":"gantovnik","date":"2021-11-28","format":false,"excerpt":"[code language=\"python\"] import numpy as np import matplotlib.pyplot as plt np.random.seed(19680801) fig, ax = plt.subplots() x = 30*np.random.randn(10000) mu = x.mean() median = np.median(x) sigma = x.std() textstr = '\\n'.join(( r'$\\mu=%.2f$' % (mu, ), r'$\\mathrm{median}=%.2f$' % (median, ), r'$\\sigma=%.2f$' % (sigma, ))) ax.hist(x, 50) # these are matplotlib.patch.Patch properties props\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\/ex215.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":1929,"url":"https:\/\/gantovnik.com\/bio-tips\/2023\/08\/379-joint-and-marginal-histograms-using-seaborn-library\/","url_meta":{"origin":1147,"position":4},"title":"#379 Joint and marginal histograms using seaborn library","author":"gantovnik","date":"2023-08-10","format":false,"excerpt":"[code language=\"python\"] #Joint and marginal histograms 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 planets dataset and initialize the figure planets = sns.load_dataset(\"planets\") g = sns.JointGrid(data=planets, x=\"year\", y=\"distance\", marginal_ticks=True) # Set a log scaling on the\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\/ex379.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2023\/08\/ex379.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2023\/08\/ex379.png?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":318,"url":"https:\/\/gantovnik.com\/bio-tips\/2019\/01\/weighted-and-unweighted-least-squares-fitting\/","url_meta":{"origin":1147,"position":5},"title":"Weighted and unweighted least squares fitting","author":"gantovnik","date":"2019-01-22","format":false,"excerpt":"[code language=\"python\"] import os import numpy as np import matplotlib.pyplot as plt from scipy.optimize import curve_fit os.chdir(r'D:\\data\\scripts\\wordpress\\ex55') os.getcwd() x0,A,gamma=12,3,5 n=200 x=np.linspace(1,20,n) yexact=A*gamma**2\/(gamma**2+(x-x0)**2) #Learning Scientific Programming with Python # Add some noise with a sigma of 0.5 apart from a particularly noisy region # near x0 where sigma is 3 sigma=np.ones(n)*0.5\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\/2019\/01\/example55.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2019\/01\/example55.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2019\/01\/example55.png?resize=525%2C300&ssl=1 1.5x"},"classes":[]}],"_links":{"self":[{"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/posts\/1147","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=1147"}],"version-history":[{"count":0,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/posts\/1147\/revisions"}],"wp:attachment":[{"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/media?parent=1147"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/categories?post=1147"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/tags?post=1147"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}