{"id":1218,"date":"2021-11-28T10:54:49","date_gmt":"2021-11-28T18:54:49","guid":{"rendered":"https:\/\/gantovnik.com\/bio-tips\/?p=1218"},"modified":"2021-11-28T10:54:49","modified_gmt":"2021-11-28T18:54:49","slug":"210-parametric-curve-in-3d-2-2-2-2-2-2","status":"publish","type":"post","link":"https:\/\/gantovnik.com\/bio-tips\/2021\/11\/210-parametric-curve-in-3d-2-2-2-2-2-2\/","title":{"rendered":"#216 Mathtext Latex parser in matplotlib"},"content":{"rendered":"<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nimport matplotlib.pyplot as plt\r\nfig, ax = plt.subplots()\r\nax.plot(&#x5B;1, 2, 3], label=r'$\\sqrt{x^2}$')\r\nax.legend()\r\nax.set_xlabel(r'$\\Delta_i^j$', fontsize=20)\r\nax.set_ylabel(r'$\\Delta_{i+1}^j$', fontsize=20)\r\nax.set_title(r'$\\Delta_i^j \\hspace{0.4} \\mathrm{versus} \\hspace{0.4} '\r\n             r'\\Delta_{i+1}^j$', fontsize=20)\r\ntex = r'$\\mathcal{R}\\prod_{i=\\alpha_{i+1}}^\\infty a_i\\sin(2 \\pi f x_i)$'\r\nax.text(1, 1.6, tex, fontsize=20, va='bottom')\r\nfig.tight_layout()\r\nplt.savefig('ex216.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\/ex216.png?resize=460%2C345&#038;ssl=1\" alt=\"\" width=\"460\" height=\"345\" class=\"alignnone size-full wp-image-1219\" srcset=\"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2021\/11\/ex216.png?w=460&amp;ssl=1 460w, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2021\/11\/ex216.png?resize=300%2C225&amp;ssl=1 300w, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2021\/11\/ex216.png?resize=150%2C113&amp;ssl=1 150w\" sizes=\"(max-width: 460px) 100vw, 460px\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>import matplotlib.pyplot as plt fig, ax = plt.subplots() ax.plot(&#x5B;1, 2, 3], label=r&#8217;$\\sqrt{x^2}$&#8217;) ax.legend() ax.set_xlabel(r&#8217;$\\Delta_i^j$&#8217;, fontsize=20) ax.set_ylabel(r&#8217;$\\Delta_{i+1}^j$&#8217;, fontsize=20) ax.set_title(r&#8217;$\\Delta_i^j \\hspace{0.4} \\mathrm{versus} \\hspace{0.4} &#8216; r&#8217;\\Delta_{i+1}^j$&#8217;, fontsize=20) tex = r&#8217;$\\mathcal{R}\\prod_{i=\\alpha_{i+1}}^\\infty a_i\\sin(2 \\pi f x_i)$&#8217; ax.text(1, 1.6, tex, fontsize=20, va=&#8217;bottom&#8217;) fig.tight_layout() plt.savefig(&#8216;ex216.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-1218","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-jE","jetpack_likes_enabled":true,"jetpack-related-posts":[{"id":96,"url":"https:\/\/gantovnik.com\/bio-tips\/2018\/12\/bisection-method\/","url_meta":{"origin":1218,"position":0},"title":"#16 Bisection method using python","author":"gantovnik","date":"2018-12-31","format":false,"excerpt":"[code language=\"python\"] import os import matplotlib.pyplot as plt import numpy as np os.chdir('\/home\/vg\/Downloads\/projects\/ex16') os.getcwd() f = lambda x: np.exp(x)-2 tol=0.1 a,b=-2,2 x=np.linspace(-2.1,2.1,1000) fig,ax=plt.subplots(1,1,figsize=(12,4)) ax.plot(x,f(x),lw=1.5) ax.axhline(0,ls=':',color='k') ax.set_xticks([-2,-1,0,1,2]) ax.set_xlabel(r'$x$',fontsize=18) ax.set_ylabel(r'$f(x)$',fontsize=18) fa,fb=f(a),f(b) ax.plot(a,fa,'ko') ax.plot(b,fb,'ko') ax.text(a,fa+0.5,r\"$a$\",ha='center',fontsize=18) ax.text(b,fb+0.5,r\"$b$\",ha='center',fontsize=18) n=1 while b-a &gt; tol: m=a+(b-a)\/2 fm=f(m) ax.plot(m,fm,'ko') ax.text(m,fm-0.5,r\"$m_%d$\" % n,ha='center') n=n+1 if (np.sign(fa)==np.sign(fm)): a,fa=m,fm else: b,fb=m,fm\u2026","rel":"","context":"In &quot;optimization&quot;","block_context":{"text":"optimization","link":"https:\/\/gantovnik.com\/bio-tips\/category\/optimization\/"},"img":{"alt_text":"example16","src":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2018\/12\/example16.png?resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2018\/12\/example16.png?resize=350%2C200 1x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2018\/12\/example16.png?resize=525%2C300 1.5x"},"classes":[]},{"id":82,"url":"https:\/\/gantovnik.com\/bio-tips\/2018\/12\/plot-with-an-inset\/","url_meta":{"origin":1218,"position":1},"title":"#12: Plot with an inset in python","author":"gantovnik","date":"2018-12-29","format":false,"excerpt":"[code language=\"python\"] import os import matplotlib as mpl import matplotlib.pyplot as plt import numpy as np os.chdir('\/home\/vg\/Downloads\/projects\/ex12') os.getcwd() fig = plt.figure(figsize=(10,8)) def f(x): return 1\/(1+x**2) + 0.1\/(1+((3-x)\/0.1)**2) def plot_and_format_axes(ax,x,f,fontsize): ax.plot(x,f(x),linewidth=2) ax.xaxis.set_major_locator(mpl.ticker.MaxNLocator(5)) ax.yaxis.set_major_locator(mpl.ticker.MaxNLocator(4)) ax.set_xlabel(r\"$x$\",fontsize=fontsize) ax.set_ylabel(r\"$f(x)$\",fontsize=fontsize) ax=fig.add_axes([0.1,0.15,0.8,0.8],facecolor=\"#f5f5f5\") x = np.linspace(-4,14,1000) plot_and_format_axes(ax,x,f,18) plt.title('Plot with inset') x0,x1=2.5,3.5 ax.axvline(x0,ymax=0.3,color=\"grey\",linestyle=\":\") ax.axvline(x1,ymax=0.3,color=\"grey\",linestyle=\":\") ax_insert=fig.add_axes([0.5,0.5,0.38,0.42],facecolor='none') x=np.linspace(x0,x1,1000) plot_and_format_axes(ax_insert,x,f,14) plt.savefig(\"example12.png\", dpi=100)\u2026","rel":"","context":"In &quot;matplotlib&quot;","block_context":{"text":"matplotlib","link":"https:\/\/gantovnik.com\/bio-tips\/category\/matplotlib\/"},"img":{"alt_text":"example12","src":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2018\/12\/example12.png?resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2018\/12\/example12.png?resize=350%2C200 1x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2018\/12\/example12.png?resize=525%2C300 1.5x"},"classes":[]},{"id":203,"url":"https:\/\/gantovnik.com\/bio-tips\/2019\/01\/laplace-equation-2d\/","url_meta":{"origin":1218,"position":2},"title":"Laplace equation (2D)","author":"gantovnik","date":"2019-01-10","format":false,"excerpt":"import os import numpy as np import matplotlib.pyplot as plt import scipy.sparse as sp import matplotlib as mpl import scipy.sparse.linalg os.chdir(r'D:\\projects\\wordpress\\ex42') os.getcwd() N = 100 u0_t, u0_b = 5, -5 u0_l, u0_r = 3, -1 dx = 1. \/ (N+1) A_1d = (sp.eye(N, k=-1) + sp.eye(N, k=1) - 4 *\u2026","rel":"","context":"In &quot;python&quot;","block_context":{"text":"python","link":"https:\/\/gantovnik.com\/bio-tips\/category\/python\/"},"img":{"alt_text":"example42","src":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2019\/01\/example42.png?resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2019\/01\/example42.png?resize=350%2C200 1x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2019\/01\/example42.png?resize=525%2C300 1.5x"},"classes":[]},{"id":136,"url":"https:\/\/gantovnik.com\/bio-tips\/2019\/01\/multivariate-interpolation\/","url_meta":{"origin":1218,"position":3},"title":"Multivariate interpolation","author":"gantovnik","date":"2019-01-04","format":false,"excerpt":"import os import matplotlib.pyplot as plt import numpy as np from scipy import interpolate os.chdir(r'D:\\data\\scripts\\web1\\ex28') os.getcwd() x = y = np.linspace(-2, 2, 20) def f(x, y): return np.exp(-(x + .5)**2 - 2*(y + .5)**2) - np.exp(-(x - .5)**2 - 2*(y - .5)**2) X, Y = np.meshgrid(x, y) # simulate noisy\u2026","rel":"","context":"In &quot;python&quot;","block_context":{"text":"python","link":"https:\/\/gantovnik.com\/bio-tips\/category\/python\/"},"img":{"alt_text":"example28","src":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2019\/01\/example28.png?resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2019\/01\/example28.png?resize=350%2C200 1x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2019\/01\/example28.png?resize=525%2C300 1.5x"},"classes":[]},{"id":210,"url":"https:\/\/gantovnik.com\/bio-tips\/2019\/01\/2nd-order-runge-kutta-type-a\/","url_meta":{"origin":1218,"position":4},"title":"#44 2nd-order Runge-Kutta type A using python","author":"gantovnik","date":"2019-01-12","format":false,"excerpt":"[code language=\"python\"] import os import numpy as np import matplotlib.pyplot as plt os.chdir(r'D:\\projects\\wordpress\\ex44') os.getcwd() #2nd-order Runge-Kutta methods with A=1\/2 (type A) # dy\/dx=exp(-2x)-2y # y(0)=0.1, interval x=[0,2], step size = h=0.2 def feval(funcName, *args): return eval(funcName)(*args) def RK2A(func, yinit, x_range, h): m = len(yinit) n = int((x_range[-1] - x_range[0])\/h) x\u2026","rel":"","context":"In &quot;numerical&quot;","block_context":{"text":"numerical","link":"https:\/\/gantovnik.com\/bio-tips\/category\/numerical\/"},"img":{"alt_text":"example44","src":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2019\/01\/example44-1.png?resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2019\/01\/example44-1.png?resize=350%2C200 1x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2019\/01\/example44-1.png?resize=525%2C300 1.5x"},"classes":[]},{"id":217,"url":"https:\/\/gantovnik.com\/bio-tips\/2019\/01\/2nd-order-runge-kutta-type-b\/","url_meta":{"origin":1218,"position":5},"title":"#45  2nd-order Runge-Kutta type B using python","author":"gantovnik","date":"2019-01-12","format":false,"excerpt":"import os import numpy as np import matplotlib.pyplot as plt os.chdir(r'D:\\projects\\wordpress\\ex45') os.getcwd() #2nd-order Runge-Kutta methods with A=0 (type B) # dy\/dx=exp(-2x)-2y # y(0)=0.1, interval x=[0,2], step size = h=0.2 def feval(funcName, *args): return eval(funcName)(*args) def RK2B(func, yinit, x_range, h): m = len(yinit) n = int((x_range[-1] - x_range[0])\/h) x = x_range[0]\u2026","rel":"","context":"In &quot;differential equations&quot;","block_context":{"text":"differential equations","link":"https:\/\/gantovnik.com\/bio-tips\/category\/differential-equations\/"},"img":{"alt_text":"example45","src":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2019\/01\/example45.png?resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2019\/01\/example45.png?resize=350%2C200 1x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2019\/01\/example45.png?resize=525%2C300 1.5x"},"classes":[]}],"_links":{"self":[{"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/posts\/1218","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=1218"}],"version-history":[{"count":0,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/posts\/1218\/revisions"}],"wp:attachment":[{"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/media?parent=1218"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/categories?post=1218"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/tags?post=1218"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}