{"id":3018,"date":"2024-07-25T02:44:58","date_gmt":"2024-07-25T09:44:58","guid":{"rendered":"https:\/\/gantovnik.com\/bio-tips\/?p=3018"},"modified":"2024-07-25T02:44:59","modified_gmt":"2024-07-25T09:44:59","slug":"441-parametric-curve-lemniscate-of-bernoulli-with-slider-in-python","status":"publish","type":"post","link":"https:\/\/gantovnik.com\/bio-tips\/2024\/07\/441-parametric-curve-lemniscate-of-bernoulli-with-slider-in-python\/","title":{"rendered":"#441 Parametric curve Lemniscate of Bernoulli with Slider in python"},"content":{"rendered":"<p><a href=\"https:\/\/gantovnik.com\/bio-tips\/2024\/07\/441-parametric-curve-lemniscate-of-bernoulli-with-slider-in-python\/ex441\/\" rel=\"attachment wp-att-3019\"><img data-recalc-dims=\"1\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2024\/07\/ex441.png?resize=1000%2C600&#038;ssl=1\" alt=\"\" width=\"1000\" height=\"600\" class=\"alignnone size-full wp-image-3019\" srcset=\"https:\/\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2024\/07\/ex441.png 1000w, https:\/\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2024\/07\/ex441-980x588.png 980w, https:\/\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2024\/07\/ex441-480x288.png 480w\" sizes=\"(min-width: 0px) and (max-width: 480px) 480px, (min-width: 481px) and (max-width: 980px) 980px, (min-width: 981px) 1000px, 100vw\" \/><\/a><\/p>\n<pre class=\"lang:python decode:true \" >import numpy as np\nimport matplotlib.pyplot as plt\nfrom matplotlib.widgets import Slider\n\ndef rx(t):\n    return np.cos(t)\/(1+np.sin(t)**2)\n\ndef ry(t):\n    return np.sin(t)*np.cos(t)\/(1+np.sin(t)**2)\n\nt = 0\nfig,ax1 = plt.subplots(1,1,figsize=(10,6))\nplt.subplots_adjust(bottom=0.2)\nax1.set_aspect('equal')\nax1.set_ylim(-0.5,0.5)\nax1.set_xlim(-1.2,1.2)\nax1.title.set_text('Parametric curve: Lemniscate of Bernoulli')\nax1.grid('on')\nr, = ax1.plot(rx(t), ry(t),'b', markersize=3)\nPnt1, = ax1.plot(rx(t), ry(t),'ro', markersize=6)\naxt = plt.axes([0.25, 0.1, 0.5, 0.01])\nt_slide = Slider(axt,'t',0, 2.0*np.pi,valstep=0.01,valinit=t)\ndef update(val):\n    t = t_slide.val\n    T = np.linspace(0,t,200)\n    r.set_data(rx(T),ry(T))\n    Pnt1.set_data(rx(t),ry(t))\n    fig.canvas.draw_idle()\n\nt_slide.on_changed(update)\nplt.show()<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>import numpy as np import matplotlib.pyplot as plt from matplotlib.widgets import Slider def rx(t): return np.cos(t)\/(1+np.sin(t)**2) def ry(t): return np.sin(t)*np.cos(t)\/(1+np.sin(t)**2) t = 0 fig,ax1 = plt.subplots(1,1,figsize=(10,6)) plt.subplots_adjust(bottom=0.2) ax1.set_aspect(&#8216;equal&#8217;) ax1.set_ylim(-0.5,0.5) ax1.set_xlim(-1.2,1.2) ax1.title.set_text(&#8216;Parametric curve: Lemniscate of Bernoulli&#8217;) ax1.grid(&#8216;on&#8217;) r, = ax1.plot(rx(t), ry(t),&#8217;b&#8217;, markersize=3) Pnt1, = ax1.plot(rx(t), ry(t),&#8217;ro&#8217;, markersize=6) axt = plt.axes([0.25, 0.1, 0.5, 0.01]) t_slide = Slider(axt,&#8217;t&#8217;,0, [&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":[89,56,69,2],"tags":[136],"class_list":["post-3018","post","type-post","status-publish","format-standard","hentry","category-animation","category-math","category-matplotlib","category-python","tag-lemniscate-of-bernoulli"],"modified_by":"gantovnik","jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p8bH0k-MG","jetpack_likes_enabled":true,"jetpack-related-posts":[{"id":1774,"url":"https:\/\/gantovnik.com\/bio-tips\/2023\/01\/338-minimization-using-newtons-method-on-the-non-quadratic-problem-in-python\/","url_meta":{"origin":3018,"position":0},"title":"#338 Minimization using Newton\u2019s method on the non-quadratic problem in python","author":"gantovnik","date":"2023-01-16","format":false,"excerpt":"ex338.py","rel":"","context":"In &quot;optimization&quot;","block_context":{"text":"optimization","link":"https:\/\/gantovnik.com\/bio-tips\/category\/optimization\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2023\/01\/ex338.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2023\/01\/ex338.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2023\/01\/ex338.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2023\/01\/ex338.png?resize=700%2C400&ssl=1 2x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2023\/01\/ex338.png?resize=1050%2C600&ssl=1 3x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2023\/01\/ex338.png?resize=1400%2C800&ssl=1 4x"},"classes":[]},{"id":193,"url":"https:\/\/gantovnik.com\/bio-tips\/2019\/01\/double-pendulum\/","url_meta":{"origin":3018,"position":1},"title":"#39 Double pendulum using python","author":"gantovnik","date":"2019-01-10","format":false,"excerpt":"import os import numpy as np import matplotlib.pyplot as plt from scipy import integrate import sympy os.chdir(r'D:\\projects\\wordpress\\ex39') os.getcwd() t, g, m1, l1, m2, l2 = sympy.symbols(\"t, g, m_1, l_1, m_2, l_2\") theta1, theta2 = sympy.symbols(\"theta_1, theta_2\", cls=sympy.Function) ode1 = sympy.Eq((m1+m2)*l1 * theta1(t).diff(t,t) + m2*l2 * theta2(t).diff(t,t) + m2*l2 * theta2(t).diff(t)**2\u2026","rel":"","context":"In &quot;python&quot;","block_context":{"text":"python","link":"https:\/\/gantovnik.com\/bio-tips\/category\/python\/"},"img":{"alt_text":"example39","src":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2019\/01\/example39.png?resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2019\/01\/example39.png?resize=350%2C200 1x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2019\/01\/example39.png?resize=525%2C300 1.5x"},"classes":[]},{"id":2889,"url":"https:\/\/gantovnik.com\/bio-tips\/2024\/07\/440-cycloid-on-interactive-figure-with-widgets-in-python\/","url_meta":{"origin":3018,"position":2},"title":"#440 Cycloid on interactive figure with widgets in python","author":"gantovnik","date":"2024-07-21","format":false,"excerpt":"import numpy as np import matplotlib.pyplot as plt from matplotlib.widgets import Slider theta = np.linspace(0,2*np.pi) circ_x = lambda t: t + np.cos(theta) circ_y = 1 + np.sin(theta) cycl_x = lambda t: t - np.sin(t) cycl_y = lambda t: 1 - np.cos(t) t = 0 fig,ax = plt.subplots() plt.subplots_adjust(bottom=0.2) plt.ylim(0, 3)\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\/07\/ex440.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2024\/07\/ex440.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2024\/07\/ex440.png?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":190,"url":"https:\/\/gantovnik.com\/bio-tips\/2019\/01\/coupled-damped-springs-jacobian-is-available\/","url_meta":{"origin":3018,"position":3},"title":"Coupled damped springs (Jacobian is available)","author":"gantovnik","date":"2019-01-10","format":false,"excerpt":"\u00a0 import os import numpy as np import matplotlib.pyplot as plt from scipy import integrate os.chdir(r'D:\\projects\\wordpress\\ex38') os.getcwd() def f(t, y, args): m1, k1, g1, m2, k2, g2 = args return [y[1], - k1\/m1 * y[0] + k2\/m1 * (y[2] - y[0]) - g1\/m1 * y[1], y[3], - k2\/m2 * (y[2]\u2026","rel":"","context":"In &quot;python&quot;","block_context":{"text":"python","link":"https:\/\/gantovnik.com\/bio-tips\/category\/python\/"},"img":{"alt_text":"example38","src":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2019\/01\/example38.png?resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2019\/01\/example38.png?resize=350%2C200 1x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2019\/01\/example38.png?resize=525%2C300 1.5x"},"classes":[]},{"id":187,"url":"https:\/\/gantovnik.com\/bio-tips\/2019\/01\/coupled-damped-springs\/","url_meta":{"origin":3018,"position":4},"title":"Coupled damped springs","author":"gantovnik","date":"2019-01-09","format":false,"excerpt":"\u00a0 import os import numpy as np import matplotlib.pyplot as plt from scipy import integrate os.chdir(r'D:\\projects\\wordpress\\ex37') os.getcwd() def f(t, y, args): m1, k1, g1, m2, k2, g2 = args return [y[1], - k1\/m1 * y[0] + k2\/m1 * (y[2] - y[0]) - g1\/m1 * y[1], y[3], - k2\/m2 * (y[2]\u2026","rel":"","context":"In &quot;python&quot;","block_context":{"text":"python","link":"https:\/\/gantovnik.com\/bio-tips\/category\/python\/"},"img":{"alt_text":"example37","src":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2019\/01\/example37.png?resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2019\/01\/example37.png?resize=350%2C200 1x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2019\/01\/example37.png?resize=525%2C300 1.5x"},"classes":[]},{"id":1540,"url":"https:\/\/gantovnik.com\/bio-tips\/2022\/09\/210-parametric-curve-in-3d-2-2-2-2-2-2-2-2-2-2-2-2-2-3-3\/","url_meta":{"origin":3018,"position":5},"title":"#296 y-y plot in python","author":"gantovnik","date":"2022-09-02","format":false,"excerpt":"y-y plots are a type of line plot where one line corresponds to one y-axis, and another line on the same plot corresponds to a different y-axis. y-y plots typically have one vertical y-axis on the left edge of the plot and one vertical y-axis on the right edge of\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\/2022\/09\/ex295.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]}],"_links":{"self":[{"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/posts\/3018","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=3018"}],"version-history":[{"count":2,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/posts\/3018\/revisions"}],"predecessor-version":[{"id":3021,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/posts\/3018\/revisions\/3021"}],"wp:attachment":[{"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/media?parent=3018"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/categories?post=3018"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/tags?post=3018"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}