{"id":1229,"date":"2021-11-28T11:29:31","date_gmt":"2021-11-28T19:29:31","guid":{"rendered":"https:\/\/gantovnik.com\/bio-tips\/?p=1229"},"modified":"2021-11-28T11:29:31","modified_gmt":"2021-11-28T19:29:31","slug":"210-parametric-curve-in-3d-2-2-2-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-2-2-2\/","title":{"rendered":"#219 Polar plot legend"},"content":{"rendered":"<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nimport matplotlib.pyplot as plt\r\nimport numpy as np\r\nfig = plt.figure()\r\nax = fig.add_subplot(projection=&quot;polar&quot;, facecolor=&quot;lightgoldenrodyellow&quot;)\r\nr = np.linspace(0, 3, 301)\r\ntheta = 2 * np.pi * r\r\nax.plot(theta, r, color=&quot;tab:orange&quot;, lw=3, label=&quot;a line&quot;)\r\nax.plot(0.5 * theta, r, color=&quot;tab:blue&quot;, ls=&quot;--&quot;, lw=3, label=&quot;another line&quot;)\r\nax.tick_params(grid_color=&quot;palegoldenrod&quot;)\r\n# For polar axes, it may be useful to move the legend slightly away from the\r\n# axes center, to avoid overlap between the legend and the axes.  The following\r\n# snippet places the legend's lower left corner just outside of the polar axes\r\n# at an angle of 67.5 degrees in polar coordinates.\r\nangle = np.deg2rad(67.5)\r\nax.legend(loc=&quot;lower left&quot;,bbox_to_anchor=(.5 + np.cos(angle)\/2, .5 + np.sin(angle)\/2))\r\nplt.savefig('ex219.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\/ex219.png?resize=460%2C345&#038;ssl=1\" alt=\"\" width=\"460\" height=\"345\" class=\"alignnone size-full wp-image-1230\" srcset=\"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2021\/11\/ex219.png?w=460&amp;ssl=1 460w, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2021\/11\/ex219.png?resize=300%2C225&amp;ssl=1 300w, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2021\/11\/ex219.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 import numpy as np fig = plt.figure() ax = fig.add_subplot(projection=&quot;polar&quot;, facecolor=&quot;lightgoldenrodyellow&quot;) r = np.linspace(0, 3, 301) theta = 2 * np.pi * r ax.plot(theta, r, color=&quot;tab:orange&quot;, lw=3, label=&quot;a line&quot;) ax.plot(0.5 * theta, r, color=&quot;tab:blue&quot;, ls=&quot;&#8211;&quot;, lw=3, label=&quot;another line&quot;) ax.tick_params(grid_color=&quot;palegoldenrod&quot;) # For polar axes, it may be useful to move the legend [&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_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-1229","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-jP","jetpack_likes_enabled":true,"jetpack-related-posts":[{"id":383,"url":"https:\/\/gantovnik.com\/bio-tips\/2019\/02\/annotating-text\/","url_meta":{"origin":1229,"position":0},"title":"#55 Annotating text in matplotlib plot","author":"gantovnik","date":"2019-02-12","format":false,"excerpt":"[code language=\"python\"] import os import matplotlib.pyplot as plt import numpy as np os.chdir(r'D:\\projects\\wordpress\\ex55') os.getcwd() fig = plt.figure() ax = fig.add_subplot(111) t = np.arange(0.0, 5.0, 0.01) s = np.cos(2*np.pi*t) line, = ax.plot(t, s, lw=2) ax.annotate('local max', xy=(2, 1), xytext=(3, 1.5), arrowprops=dict(facecolor='red', shrink=0.05), ) ax.set_ylim(-2,2) plt.savefig(\"example55.png\", dpi=100) plt.show() fig = plt.figure() ax\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\/02\/example64_1.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2019\/02\/example64_1.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2019\/02\/example64_1.png?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":1226,"url":"https:\/\/gantovnik.com\/bio-tips\/2021\/11\/210-parametric-curve-in-3d-2-2-2-2-2-2-2-2\/","url_meta":{"origin":1229,"position":1},"title":"#218 Polar plot","author":"gantovnik","date":"2021-11-28","format":false,"excerpt":"[code language=\"python\"] import numpy as np import matplotlib.pyplot as plt r = np.arange(0, 2, 0.01) theta = 2 * np.pi * r fig, ax = plt.subplots(subplot_kw={'projection': 'polar'}) ax.plot(theta, r) ax.set_rmax(2) ax.set_rticks([0.5, 1, 1.5, 2]) # Less radial ticks ax.set_rlabel_position(-22.5) # Move radial labels away from plotted line ax.grid(True) ax.set_title(\"A line\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\/ex218.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":2048,"url":"https:\/\/gantovnik.com\/bio-tips\/2024\/01\/405-cardioid-in-polar-coordinates-by-matplot-in-python\/","url_meta":{"origin":1229,"position":2},"title":"#405 Cardioid in polar coordinates by matplotlib in python","author":"gantovnik","date":"2024-01-14","format":false,"excerpt":"A cardioid is a two-dimensional plane figure that has a heart-shaped curve described in polar coordinates by the equation r = 2a(1 + cos \u03b8) for 0 \u2264 \u03b8 \u2264 2\u03c0: [code language=\"python\"] import numpy as np import matplotlib.pyplot as plt theta = np.linspace(0, 2.*np.pi, 1000) a = 1.0 r\u2026","rel":"","context":"In &quot;math&quot;","block_context":{"text":"math","link":"https:\/\/gantovnik.com\/bio-tips\/category\/math\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2024\/01\/ex405.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2024\/01\/ex405.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2024\/01\/ex405.png?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":1221,"url":"https:\/\/gantovnik.com\/bio-tips\/2021\/11\/210-parametric-curve-in-3d-2-2-2-2-2-2-2\/","url_meta":{"origin":1229,"position":3},"title":"#217 Annotation in matplotlib","author":"gantovnik","date":"2021-11-28","format":false,"excerpt":"[code language=\"python\"] import numpy as np import matplotlib.pyplot as plt from matplotlib.ticker import AutoMinorLocator, MultipleLocator np.random.seed(19680801) X = np.linspace(0.5, 3.5, 100) Y1 = 3+np.cos(X) Y2 = 1+np.cos(1+X\/0.75)\/2 Y3 = np.random.uniform(Y1, Y2, len(X)) fig = plt.figure(figsize=(8, 8)) ax = fig.add_subplot(1, 1, 1, aspect=1) def minor_tick(x, pos): if not x % 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\/2021\/11\/ex217-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\/ex217-1.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2021\/11\/ex217-1.png?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":154,"url":"https:\/\/gantovnik.com\/bio-tips\/2019\/01\/inexact-solutions-to-odes\/","url_meta":{"origin":1229,"position":4},"title":"Inexact solutions to ODEs","author":"gantovnik","date":"2019-01-08","format":false,"excerpt":"\u00a0 import os import numpy as np import matplotlib.pyplot as plt import matplotlib as mpl import sympy from IPython.display import display sympy.init_printing() mpl.rcParams['text.usetex'] = True import sympy os.chdir(r'D:\\projects\\wordpress\\ex33') os.getcwd() def plot_direction_field(x, y_x, f_xy, x_lim=(-5, 5), y_lim=(-5, 5), ax=None): f_np = sympy.lambdify((x, y_x), f_xy, 'numpy') x_vec = np.linspace(x_lim[0], x_lim[1], 20) y_vec\u2026","rel":"","context":"In &quot;python&quot;","block_context":{"text":"python","link":"https:\/\/gantovnik.com\/bio-tips\/category\/python\/"},"img":{"alt_text":"example33","src":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2019\/01\/example33.png?resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2019\/01\/example33.png?resize=350%2C200 1x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2019\/01\/example33.png?resize=525%2C300 1.5x"},"classes":[]},{"id":88,"url":"https:\/\/gantovnik.com\/bio-tips\/2018\/12\/linear-least-square-fit\/","url_meta":{"origin":1229,"position":5},"title":"#14 Linear least square fit 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 import scipy.linalg as la os.chdir('\/home\/vg\/Downloads\/projects\/ex14') os.getcwd() #define model parameters x=np.linspace(-1,1,200) a,b,c=1,2,3 y_exact=a+b*x+c*x**2 #simulate noisy data m=200 X=1-2*np.random.rand(m) Y=a+b*X+c*X**2+np.random.randn(m) #linear least square fit A=np.vstack([X**0,X**1,X**2]) sol,r,rank,sv=la.lstsq(A.T,Y) y_fit=sol[0]+sol[1]*x+sol[2]*x**2 fig,ax=plt.subplots(figsize=(12,4)) ax.plot(X,Y,'go',alpha=0.5,label='simulated data') ax.plot(x,y_exact,'k',lw=2,label='true value $y=1+2x+3x^2$') ax.plot(x,y_fit,'b',lw=2,label='least square fit') #1st order polynomial A=np.vstack([X**n\u2026","rel":"","context":"In &quot;matplotlib&quot;","block_context":{"text":"matplotlib","link":"https:\/\/gantovnik.com\/bio-tips\/category\/matplotlib\/"},"img":{"alt_text":"example13","src":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2018\/12\/example13-1.png?resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2018\/12\/example13-1.png?resize=350%2C200 1x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2018\/12\/example13-1.png?resize=525%2C300 1.5x"},"classes":[]}],"_links":{"self":[{"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/posts\/1229","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=1229"}],"version-history":[{"count":0,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/posts\/1229\/revisions"}],"wp:attachment":[{"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/media?parent=1229"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/categories?post=1229"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/tags?post=1229"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}