{"id":1208,"date":"2021-11-27T16:17:12","date_gmt":"2021-11-28T00:17:12","guid":{"rendered":"https:\/\/gantovnik.com\/bio-tips\/?p=1208"},"modified":"2021-11-27T16:17:12","modified_gmt":"2021-11-28T00:17:12","slug":"210-parametric-curve-in-3d-2-2-2","status":"publish","type":"post","link":"https:\/\/gantovnik.com\/bio-tips\/2021\/11\/210-parametric-curve-in-3d-2-2-2\/","title":{"rendered":"#213 Annotate Text Arrow"},"content":{"rendered":"<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nimport numpy as np\r\nimport matplotlib.pyplot as plt\r\n# Fixing random state for reproducibility\r\nnp.random.seed(19680801)\r\nfig, ax = plt.subplots(figsize=(5, 5))\r\nax.set_aspect(1)\r\nx1 = -1 + np.random.randn(100)\r\ny1 = -1 + np.random.randn(100)\r\nx2 = 1. + np.random.randn(100)\r\ny2 = 1. + np.random.randn(100)\r\nax.scatter(x1, y1, color=&quot;r&quot;)\r\nax.scatter(x2, y2, color=&quot;g&quot;)\r\nbbox_props = dict(boxstyle=&quot;round&quot;, fc=&quot;w&quot;, ec=&quot;0.5&quot;, alpha=0.9)\r\nax.text(-2, -2, &quot;Sample A&quot;, ha=&quot;center&quot;, va=&quot;center&quot;, size=20, bbox=bbox_props)\r\nax.text(2, 2, &quot;Sample B&quot;, ha=&quot;center&quot;, va=&quot;center&quot;, size=20, bbox=bbox_props)\r\nbbox_props = dict(boxstyle=&quot;rarrow&quot;, fc=(0.8, 0.9, 0.9), ec=&quot;b&quot;, lw=2)\r\nt = ax.text(0, 0, &quot;Direction&quot;, ha=&quot;center&quot;, va=&quot;center&quot;, rotation=45, size=15, bbox=bbox_props)\r\nbb = t.get_bbox_patch()\r\nbb.set_boxstyle(&quot;rarrow&quot;, pad=0.6)\r\nax.set_xlim(-4, 4)\r\nax.set_ylim(-4, 4)\r\nplt.savefig('ex213.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\/ex213.png?resize=360%2C360&#038;ssl=1\" alt=\"\" width=\"360\" height=\"360\" class=\"alignnone size-full wp-image-1209\" srcset=\"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2021\/11\/ex213.png?w=360&amp;ssl=1 360w, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2021\/11\/ex213.png?resize=300%2C300&amp;ssl=1 300w, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2021\/11\/ex213.png?resize=150%2C150&amp;ssl=1 150w\" sizes=\"(max-width: 360px) 100vw, 360px\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>import numpy as np import matplotlib.pyplot as plt # Fixing random state for reproducibility np.random.seed(19680801) fig, ax = plt.subplots(figsize=(5, 5)) ax.set_aspect(1) x1 = -1 + np.random.randn(100) y1 = -1 + np.random.randn(100) x2 = 1. + np.random.randn(100) y2 = 1. + np.random.randn(100) ax.scatter(x1, y1, color=&quot;r&quot;) ax.scatter(x2, y2, color=&quot;g&quot;) bbox_props = dict(boxstyle=&quot;round&quot;, fc=&quot;w&quot;, ec=&quot;0.5&quot;, alpha=0.9) ax.text(-2, -2, [&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-1208","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-ju","jetpack_likes_enabled":true,"jetpack-related-posts":[{"id":1215,"url":"https:\/\/gantovnik.com\/bio-tips\/2021\/11\/210-parametric-curve-in-3d-2-2-2-2-2\/","url_meta":{"origin":1208,"position":0},"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":2104,"url":"https:\/\/gantovnik.com\/bio-tips\/2024\/01\/411-clustering-using-dbscan-algorithm-in-sklearn-cluster-in-python\/","url_meta":{"origin":1208,"position":1},"title":"#411 Clustering using DBSCAN algorithm in sklearn.cluster in python","author":"gantovnik","date":"2024-01-18","format":false,"excerpt":"DBSCAN works by finding core points that have many data points within a given radius. Once the core is defined, the process is iteratively computed until there are no more core points definable within the maximum radius. This algorithm does exceptionally well compared to kmeans where there is noise present\u2026","rel":"","context":"In &quot;cluster&quot;","block_context":{"text":"cluster","link":"https:\/\/gantovnik.com\/bio-tips\/category\/cluster\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2024\/01\/ex411.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":1232,"url":"https:\/\/gantovnik.com\/bio-tips\/2021\/11\/210-parametric-curve-in-3d-2-2-2-2-2-2-2-2-2-2\/","url_meta":{"origin":1208,"position":2},"title":"#220 Custom figure subclasses","author":"gantovnik","date":"2021-11-28","format":false,"excerpt":"[code language=\"python\"] import matplotlib.pyplot as plt from matplotlib.figure import Figure import numpy as np class WatermarkFigure(Figure): \"\"\"A figure with a text watermark.\"\"\" def __init__(self, *args, watermark=None, **kwargs): super().__init__(*args, **kwargs) if watermark is not None: bbox = dict(boxstyle='square', lw=3, ec='gray', fc=(0.9, 0.9, .9, .5), alpha=0.5) self.text(0.5, 0.5, watermark, ha='center', va='center', rotation=30,\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\/ex220.png?resize=350%2C200&ssl=1","width":350,"height":200},"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":1208,"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":85,"url":"https:\/\/gantovnik.com\/bio-tips\/2018\/12\/subplots-in-matplotlib\/","url_meta":{"origin":1208,"position":4},"title":"#13 Subplots in matplotlib","author":"gantovnik","date":"2018-12-29","format":false,"excerpt":"[code language=\"python\"] import os import matplotlib.pyplot as plt import numpy as np os.chdir('\/home\/vg\/Downloads\/projects\/ex13') os.getcwd() fig,axes = plt.subplots(2,2,figsize=(6,6),sharex=True,sharey=True,squeeze=False) x1=np.random.randn(100) x2=np.random.randn(100) axes[0,0].set_title(\"Uncorrelated\") axes[0,0].scatter(x1,x2) axes[0,1].set_title(\"Weakly positively correlated\") axes[0,1].scatter(x1,x1+x2) axes[1,0].set_title(\"Weakly negatively correlated\") axes[1,0].scatter(x1,-x1+x2) axes[1,1].set_title(\"Strongly correlated\") axes[1,1].scatter(x1,x1+0.15*x2) axes[1,1].set_xlabel(\"x\") axes[1,0].set_xlabel(\"x\") axes[0,0].set_ylabel(\"y\") axes[1,0].set_ylabel(\"y\") plt.subplots_adjust(left=0.1,right=0.95,bottom=0.1,top=0.95,wspace=0.1,hspace=0.2) plt.savefig(\"example13.png\", dpi=100) plt.show() plt.close() [\/code]","rel":"","context":"In &quot;python&quot;","block_context":{"text":"python","link":"https:\/\/gantovnik.com\/bio-tips\/category\/python\/"},"img":{"alt_text":"example13","src":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2018\/12\/example13.png?resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2018\/12\/example13.png?resize=350%2C200 1x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2018\/12\/example13.png?resize=525%2C300 1.5x"},"classes":[]},{"id":1204,"url":"https:\/\/gantovnik.com\/bio-tips\/2021\/11\/210-parametric-curve-in-3d-2-2\/","url_meta":{"origin":1208,"position":5},"title":"#212 The double pendulum simulation using python","author":"gantovnik","date":"2021-11-27","format":false,"excerpt":"[code language=\"python\"] from numpy import sin, cos import numpy as np import matplotlib.pyplot as plt import scipy.integrate as integrate import matplotlib.animation as animation from collections import deque G = 9.8 # acceleration due to gravity, in m\/s^2 L1 = 1.0 # length of pendulum 1 in m L2 = 1.0\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\/2021\/11\/ex212.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]}],"_links":{"self":[{"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/posts\/1208","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=1208"}],"version-history":[{"count":0,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/posts\/1208\/revisions"}],"wp:attachment":[{"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/media?parent=1208"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/categories?post=1208"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/tags?post=1208"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}