{"id":1854,"date":"2023-05-25T11:12:51","date_gmt":"2023-05-25T18:12:51","guid":{"rendered":"https:\/\/gantovnik.com\/bio-tips\/?p=1854"},"modified":"2023-06-18T22:42:12","modified_gmt":"2023-06-19T05:42:12","slug":"test-2","status":"publish","type":"post","link":"https:\/\/gantovnik.com\/bio-tips\/2023\/05\/test-2\/","title":{"rendered":"#348 Histogram plot with python"},"content":{"rendered":"<p><a href=\"https:\/\/gantovnik.com\/bio-tips\/2023\/05\/test-2\/ex348\/\" rel=\"attachment wp-att-1859\"><img data-recalc-dims=\"1\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2023\/05\/ex348.png?resize=432%2C288&#038;ssl=1\" alt=\"\" width=\"432\" height=\"288\" class=\"alignnone size-full wp-image-1859\" srcset=\"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2023\/05\/ex348.png?w=432&amp;ssl=1 432w, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2023\/05\/ex348.png?resize=300%2C200&amp;ssl=1 300w, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2023\/05\/ex348.png?resize=150%2C100&amp;ssl=1 150w\" sizes=\"(max-width: 432px) 100vw, 432px\" \/><\/a><\/p>\n<p>In this example, plot ticks coincide with bin edges.<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nimport numpy as np\r\nimport matplotlib.pyplot as plt\r\ndata = np.random.default_rng(1234).rayleigh(1,40)\r\ncounts, edges, bars = plt.hist(data, edgecolor=&quot;red&quot;,bins=&#x5B;0, 1, 2, 3, 4])\r\nplt.bar_label(bars)\r\nplt.xticks(edges)\r\nplt.savefig('ex348.png', dpi=72)\r\nplt.show()\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>In this example, plot ticks coincide with bin edges. 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=&quot;red&quot;,bins=&#x5B;0, 1, 2, 3, 4]) plt.bar_label(bars) plt.xticks(edges) plt.savefig(&#8216;ex348.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":[84],"class_list":["post-1854","post","type-post","status-publish","format-standard","hentry","category-python","tag-plt-hist"],"modified_by":"gantovnik","jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p8bH0k-tU","jetpack_likes_enabled":true,"jetpack-related-posts":[{"id":2171,"url":"https:\/\/gantovnik.com\/bio-tips\/2024\/05\/424-an-animation-of-a-decaying-sine-curve-using-python\/","url_meta":{"origin":1854,"position":0},"title":"#424 An animation of a decaying sine curve using python","author":"gantovnik","date":"2024-05-05","format":false,"excerpt":"[code language=\"python\"] import numpy as np import matplotlib.pyplot as plt import matplotlib.animation as animation # Time step for the animation (s), max time to animate for (s). dt, tmax = 0.01, 5 # Signal frequency (s-1), decay constant (s-1). f, alpha = 2.5, 1 # These lists will hold the\u2026","rel":"","context":"In &quot;animation&quot;","block_context":{"text":"animation","link":"https:\/\/gantovnik.com\/bio-tips\/category\/animation\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2024\/05\/ex424.gif?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2024\/05\/ex424.gif?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2024\/05\/ex424.gif?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":2099,"url":"https:\/\/gantovnik.com\/bio-tips\/2024\/01\/410-2d-random-walk-animation-in-python\/","url_meta":{"origin":1854,"position":1},"title":"#410 2D random walk animation in python","author":"gantovnik","date":"2024-01-14","format":false,"excerpt":"[code language=\"python\"] import numpy import random import matplotlib.pyplot as plt from matplotlib import animation # define some plot variables fig, ax = plt.subplots(figsize=(8,8)) bound = 25 ax.set_xlim(-bound,bound) ax.set_ylim(-bound,bound) # define a numpy array to hold the locations visited on the random walk locations = numpy.zeros((1,2)) # 1 row, 2 columns\u2026","rel":"","context":"In &quot;animation&quot;","block_context":{"text":"animation","link":"https:\/\/gantovnik.com\/bio-tips\/category\/animation\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2024\/01\/ex410.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2024\/01\/ex410.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2024\/01\/ex410.png?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":2140,"url":"https:\/\/gantovnik.com\/bio-tips\/2024\/02\/417-polar-plot-using-sympy-plotting-functions-in-python\/","url_meta":{"origin":1854,"position":2},"title":"#417 Polar plot using SymPy plotting functions in python","author":"gantovnik","date":"2024-02-21","format":false,"excerpt":"[code language=\"python\"] import matplotlib.pyplot as plt from sympy import symbols, sin, cos, pi, latex from spb import plot_polar x = symbols(\"x\") expr = sin(2 * x) * cos(5 * x) + pi \/ 2 plot_polar(expr, (x, 0, 2 * pi), polar_axis=True, ylim=(0, 3), title=\"$%s$\" % latex(expr)) plt.savefig(\"ex417.png\", dpi=100) plt.show() [\/code]","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\/02\/ex417.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2024\/02\/ex417.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2024\/02\/ex417.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2024\/02\/ex417.png?resize=700%2C400&ssl=1 2x"},"classes":[]},{"id":2135,"url":"https:\/\/gantovnik.com\/bio-tips\/2024\/02\/416-plot-using-sympy-in-python\/","url_meta":{"origin":1854,"position":3},"title":"#416 Plot using sympy and plot_implicit in python","author":"gantovnik","date":"2024-02-21","format":false,"excerpt":"[code language=\"python\"] import matplotlib.pyplot as plt from sympy import symbols, plot_implicit, And plt.rcParams[\"figure.figsize\"] = (8,8) x,y=symbols('x y') p = plot_implicit(And( x**2 + y**2 < 25, x**2 + y**2 > 10,), (x,-10, 10), (y, -10, 10)) plt.savefig(\"ex416.png\", dpi=100) plt.show() [\/code]","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\/02\/ex416.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2024\/02\/ex416.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2024\/02\/ex416.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2024\/02\/ex416.png?resize=700%2C400&ssl=1 2x"},"classes":[]},{"id":1754,"url":"https:\/\/gantovnik.com\/bio-tips\/2023\/01\/334-polar-plot-using-python\/","url_meta":{"origin":1854,"position":4},"title":"#334 Polar plot using python","author":"gantovnik","date":"2023-01-06","format":false,"excerpt":"ex334.py [code language=\"python\"] import numpy as np import matplotlib.pyplot as plt plt.axes(projection = 'polar') # creating an array # containing the angle values rads = np.arange(0,(2*np.pi),0.1) a=6 # plotting the cardioid for rad in rads: r = a*(1 + np.cos(rad)) plt.polar(rad,r,'ro',markersize=4) plt.savefig('ex334.png', dpi=72) plt.show() [\/code]","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\/2023\/01\/ex334.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":1880,"url":"https:\/\/gantovnik.com\/bio-tips\/2023\/07\/356-animation-of-plot-legend-using-python\/","url_meta":{"origin":1854,"position":5},"title":"#356 Animation of plot legend using python","author":"gantovnik","date":"2023-07-01","format":false,"excerpt":"[code language=\"python\"] # pip install celluloid #%matplotlib qt from matplotlib import pyplot as plt from celluloid import Camera import numpy as np fig = plt.figure() camera = Camera(fig) t = np.linspace(0, 2 * np.pi, 128, endpoint=False) for i in range(0,41) : p=plt.plot(t, i*np.sin(t)) plt.legend(p, [f'line {i}']) camera.snap() animation = camera.animate()\u2026","rel":"","context":"In &quot;animation&quot;","block_context":{"text":"animation","link":"https:\/\/gantovnik.com\/bio-tips\/category\/animation\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2023\/07\/ex356.gif?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2023\/07\/ex356.gif?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2023\/07\/ex356.gif?resize=525%2C300&ssl=1 1.5x"},"classes":[]}],"_links":{"self":[{"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/posts\/1854","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=1854"}],"version-history":[{"count":0,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/posts\/1854\/revisions"}],"wp:attachment":[{"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/media?parent=1854"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/categories?post=1854"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/tags?post=1854"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}