{"id":2154,"date":"2024-05-03T03:26:15","date_gmt":"2024-05-03T10:26:15","guid":{"rendered":"https:\/\/gantovnik.com\/bio-tips\/?p=2154"},"modified":"2024-05-03T03:26:15","modified_gmt":"2024-05-03T10:26:15","slug":"420-histogram-plot-of-10000-random-samples-from-the-normal-distribution","status":"publish","type":"post","link":"https:\/\/gantovnik.com\/bio-tips\/2024\/05\/420-histogram-plot-of-10000-random-samples-from-the-normal-distribution\/","title":{"rendered":"#420 Histogram plot of 10000 random samples from the normal distribution"},"content":{"rendered":"<p><a href=\"https:\/\/gantovnik.com\/bio-tips\/2024\/05\/420-histogram-plot-of-10000-random-samples-from-the-normal-distribution\/ex420\/\" rel=\"attachment wp-att-2155\"><img data-recalc-dims=\"1\" decoding=\"async\" class=\"alignnone size-full wp-image-2155\" src=\"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2024\/05\/ex420.png?resize=640%2C480&#038;ssl=1\" alt=\"\" width=\"640\" height=\"480\" srcset=\"https:\/\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2024\/05\/ex420.png 640w, https:\/\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2024\/05\/ex420-480x360.png 480w\" sizes=\"(min-width: 0px) and (max-width: 480px) 480px, (min-width: 481px) 640px, 100vw\" \/><\/a><\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\n#Histogram of 10 000 random samples from the normal distribution \r\nimport numpy as np\r\nimport matplotlib.pyplot as plt\r\n# the mean and the standard deviation\r\nmu, sigma = 100.0, 8.0\r\nsamples = np.random.normal(loc=mu, scale=sigma, size=10000)\r\ncounts, bins, patches = plt.hist(samples , bins=100, density=True, color=&#039;skyblue&#039;, alpha=0.75,edgecolor=&#039;black&#039;)\r\nplt.plot(bins, 1\/(sigma * np.sqrt(2 * np.pi)) * np.exp( -(bins - mu)**2 \/ (2 * sigma**2) ), lw=2)\r\nplt.title(r&#039;$\\mathrm{Histogram:}\\ \\mu=100,\\ \\sigma=15$&#039;)\r\nplt.savefig(&quot;ex420.png&quot;, dpi=100)\r\nplt.show()\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>#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=&#039;skyblue&#039;, alpha=0.75,edgecolor=&#039;black&#039;) plt.plot(bins, 1\/(sigma * np.sqrt(2 * np.pi)) * np.exp( -(bins &#8211; [&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_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":"","jetpack_post_was_ever_published":false},"categories":[69,2],"tags":[],"class_list":["post-2154","post","type-post","status-publish","format-standard","hentry","category-matplotlib","category-python"],"modified_by":"gantovnik","jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p8bH0k-yK","jetpack_likes_enabled":true,"jetpack-related-posts":[{"id":1147,"url":"https:\/\/gantovnik.com\/bio-tips\/2021\/11\/201-polyfit-and-polyval-2\/","url_meta":{"origin":2154,"position":0},"title":"#202 Histogram using seaborn","author":"gantovnik","date":"2021-11-23","format":false,"excerpt":"Note LaTeX format in the plot title! [code language=\"python\"] 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('Histogram with $\\mu$={0}, $\\sigma$={1}'.format(mu,sigma)) plt.savefig('ex202.png',\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\/ex202-1.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2021\/11\/ex202-1.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2021\/11\/ex202-1.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2021\/11\/ex202-1.png?resize=700%2C400&ssl=1 2x"},"classes":[]},{"id":1215,"url":"https:\/\/gantovnik.com\/bio-tips\/2021\/11\/210-parametric-curve-in-3d-2-2-2-2-2\/","url_meta":{"origin":2154,"position":1},"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":1854,"url":"https:\/\/gantovnik.com\/bio-tips\/2023\/05\/test-2\/","url_meta":{"origin":2154,"position":2},"title":"#348 Histogram plot with python","author":"gantovnik","date":"2023-05-25","format":false,"excerpt":"In this example, plot ticks coincide with bin edges. [code language=\"python\"] import numpy as np import matplotlib.pyplot as plt data = np.random.default_rng(1234).rayleigh(1,40) counts, edges, bars = plt.hist(data, edgecolor=\"red\",bins=[0, 1, 2, 3, 4]) plt.bar_label(bars) plt.xticks(edges) plt.savefig('ex348.png', dpi=72) plt.show() [\/code]","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\/2023\/05\/ex348.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":169,"url":"https:\/\/gantovnik.com\/bio-tips\/2019\/01\/lorenz-equations\/","url_meta":{"origin":2154,"position":3},"title":"Lorenz equations","author":"gantovnik","date":"2019-01-09","format":false,"excerpt":"import os import numpy as np import matplotlib.pyplot as plt from scipy import integrate from mpl_toolkits.mplot3d.axes3d import Axes3D os.chdir(r'D:\\projects\\wordpress\\ex36') os.getcwd() def f(xyz, t, rho, sigma, beta): x, y, z = xyz return [sigma*(y-x),x*(rho-z)-y,x*y-beta*z] rho = 28 sigma = 8 beta = 8\/3.0 t = np.linspace(0, 25, 10000) xyz0 = [1.0,\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\/example36.png?fit=1200%2C514&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2019\/01\/example36.png?fit=1200%2C514&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2019\/01\/example36.png?fit=1200%2C514&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2019\/01\/example36.png?fit=1200%2C514&ssl=1&resize=700%2C400 2x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2019\/01\/example36.png?fit=1200%2C514&ssl=1&resize=1050%2C600 3x"},"classes":[]},{"id":1923,"url":"https:\/\/gantovnik.com\/bio-tips\/2023\/08\/377-stacked-histogram-on-a-log-scale-using-seaborn\/","url_meta":{"origin":2154,"position":4},"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":318,"url":"https:\/\/gantovnik.com\/bio-tips\/2019\/01\/weighted-and-unweighted-least-squares-fitting\/","url_meta":{"origin":2154,"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\/2154","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=2154"}],"version-history":[{"count":2,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/posts\/2154\/revisions"}],"predecessor-version":[{"id":2157,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/posts\/2154\/revisions\/2157"}],"wp:attachment":[{"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/media?parent=2154"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/categories?post=2154"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/tags?post=2154"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}