{"id":1971,"date":"2023-11-09T00:22:44","date_gmt":"2023-11-09T08:22:44","guid":{"rendered":"https:\/\/gantovnik.com\/bio-tips\/?p=1971"},"modified":"2024-01-14T15:09:22","modified_gmt":"2024-01-14T23:09:22","slug":"ex394","status":"publish","type":"post","link":"https:\/\/gantovnik.com\/bio-tips\/2023\/11\/ex394\/","title":{"rendered":"#394 Scatter plot of helix using matplotlib"},"content":{"rendered":"<p><a href=\"https:\/\/gantovnik.com\/bio-tips\/2023\/11\/ex394\/ex394\/\" rel=\"attachment wp-att-1972\"><img data-recalc-dims=\"1\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2023\/11\/ex394.png?resize=640%2C480&#038;ssl=1\" alt=\"\" width=\"640\" height=\"480\" class=\"alignnone size-full wp-image-1972\" srcset=\"https:\/\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2023\/11\/ex394.png 640w, https:\/\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2023\/11\/ex394-480x360.png 480w\" sizes=\"(min-width: 0px) and (max-width: 480px) 480px, (min-width: 481px) 640px, 100vw\" \/><\/a><\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nimport matplotlib.pyplot as plt\r\nfrom mpl_toolkits.mplot3d import Axes3D\r\nimport numpy as np\r\nfrom numpy import sin, cos\r\nimport pandas as pd\r\nfig = plt.figure()\r\n# preferred method for creating 3d axis\r\nax = fig.add_subplot(111, projection='3d')\r\nr = 10\r\nc = 2\r\nt = np.linspace(0, 20, 400)\r\n# parametric equation of a helix\r\nx = r*cos(t)\r\ny = r*sin(t)\r\nz = c*t\r\nax.scatter(x, y, z, zdir='z', lw=2, c='g', marker='.')\r\nplt.savefig(&quot;ex394.png&quot;, dpi=100)\r\nplt.show()\r\ndf = pd.DataFrame(x,columns=&#x5B;'x'])\r\ndf = df.assign(y=y)\r\ndf = df.assign(z=z)\r\ndf.to_csv('coordinates.txt', header=None, index=None, sep='\\t', mode='w')\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D import numpy as np from numpy import sin, cos import pandas as pd fig = plt.figure() # preferred method for creating 3d axis ax = fig.add_subplot(111, projection=&#8217;3d&#8217;) r = 10 c = 2 t = np.linspace(0, 20, 400) # parametric equation of a helix x = r*cos(t) [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1972,"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":[69,2],"tags":[],"class_list":["post-1971","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-matplotlib","category-python"],"modified_by":"gantovnik","jetpack_featured_media_url":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2023\/11\/ex394.png?fit=640%2C480&ssl=1","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/s8bH0k-ex394","jetpack_likes_enabled":true,"jetpack-related-posts":[{"id":2158,"url":"https:\/\/gantovnik.com\/bio-tips\/2024\/05\/421-plot-a-pandas-data-frame-for-loops-on-columns\/","url_meta":{"origin":1971,"position":0},"title":"#421 Plot a pandas data frame for loops on columns","author":"gantovnik","date":"2024-05-04","format":false,"excerpt":"[code language=\"python\"] import numpy as np import pandas as pd import matplotlib.pyplot as plt np.random.seed(2023) df = pd.DataFrame({ \"x\": np.linspace(0, 1, 10), \"A\": np.random.rand(10), \"B\": np.random.rand(10), \"C\": np.random.rand(10), }) for column in df: if column != 'x': plt.plot(df['x'], df[column],label=f\"x vs. {column}\") plt.scatter(df['x'], df[column]) plt.title(\"Performance\") plt.grid() plt.xlabel('x') plt.ylabel('Efficiency') plt.legend() plt.show() plt.savefig('ex421.png',\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\/2024\/05\/ex421.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2024\/05\/ex421.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2024\/05\/ex421.png?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":1980,"url":"https:\/\/gantovnik.com\/bio-tips\/2023\/12\/397-spiral-that-goes-around-circular-paraboloid-by-python\/","url_meta":{"origin":1971,"position":1},"title":"#397 Spiral that goes around circular paraboloid by python","author":"gantovnik","date":"2023-12-18","format":false,"excerpt":"[code language=\"python\"] import numpy as np import matplotlib.pyplot as plt fig = plt.figure() ax = plt.axes(projection='3d') # Surface ------------------ # Create the mesh in polar coordinates and compute corresponding Z r0 = 5 r = np.linspace(0, r0, 50) p = np.linspace(0, 2*np.pi, 50) R, P = np.meshgrid(r, p) Z =\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\/2023\/12\/ex397.png?fit=640%2C480&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2023\/12\/ex397.png?fit=640%2C480&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2023\/12\/ex397.png?fit=640%2C480&ssl=1&resize=525%2C300 1.5x"},"classes":[]},{"id":1786,"url":"https:\/\/gantovnik.com\/bio-tips\/2023\/01\/340-lorenz-attractors-using-python\/","url_meta":{"origin":1971,"position":2},"title":"#340 Lorenz attractors using python","author":"gantovnik","date":"2023-01-17","format":false,"excerpt":"[code language=\"python\"] import os import matplotlib.pyplot as plt from numpy import linspace from scipy.integrate import odeint os.chdir(r'D:\\projects\\wordpress\\ex340') os.getcwd() sigma=10.0 b=8\/3.0 r=28.0 f = lambda x,t: [sigma*(x[1]-x[0]), r*x[0]-x[1]-x[0]*x[2], x[0]*x[1]-b*x[2]] t=linspace(0,20,2000) y0=[5.0,5.0,5.0] solution=odeint(f,y0,t) X=solution[:,0]; Y=solution[:,1]; Z=solution[:,2] plt.subplot(projection='3d') plt.plot(X,Y,Z) plt.xlabel('x') plt.ylabel('y') plt.savefig(\"ex340_a.png\", dpi=100) plt.show() plt.rcParams['figure.figsize'] = (10.0, 5.0) plt.subplot(121) plt.plot(t,Z) plt.xlabel('t') plt.ylabel('Z') plt.subplot(122)\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\/2023\/01\/ex340_b.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2023\/01\/ex340_b.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2023\/01\/ex340_b.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2023\/01\/ex340_b.png?resize=700%2C400&ssl=1 2x"},"classes":[]},{"id":365,"url":"https:\/\/gantovnik.com\/bio-tips\/2019\/01\/solution-of-laplace-equation-using-fem\/","url_meta":{"origin":1971,"position":3},"title":"#51 Solution of Laplace equation using FEM","author":"gantovnik","date":"2019-01-29","format":false,"excerpt":"[code language=\"python\"] import os import matplotlib.pyplot as plt import numpy as np from numpy import linspace from scipy.spatial import Delaunay from numpy import cross from scipy.sparse import dok_matrix import matplotlib.cm as cm os.chdir(r'D:\\projects\\wordpress\\ex51') os.getcwd() xmin = 0 ; xmax = 1 ; nXpoints = 10 ymin = 0 ; ymax\u2026","rel":"","context":"In &quot;fem&quot;","block_context":{"text":"fem","link":"https:\/\/gantovnik.com\/bio-tips\/category\/fem\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2019\/01\/example61_3.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2019\/01\/example61_3.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2019\/01\/example61_3.png?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":169,"url":"https:\/\/gantovnik.com\/bio-tips\/2019\/01\/lorenz-equations\/","url_meta":{"origin":1971,"position":4},"title":"Lorenz equations","author":"gantovnik","date":"2019-01-09","format":false,"excerpt":"import os import numpy as np import matplotlib.pyplot as plt from scipy import integrate from mpl_toolkits.mplot3d.axes3d import Axes3D os.chdir(r'D:\\projects\\wordpress\\ex36') os.getcwd() def f(xyz, t, rho, sigma, beta): x, y, z = xyz return [sigma*(y-x),x*(rho-z)-y,x*y-beta*z] rho = 28 sigma = 8 beta = 8\/3.0 t = np.linspace(0, 25, 10000) xyz0 = [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\/2019\/01\/example36.png?fit=1200%2C514&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2019\/01\/example36.png?fit=1200%2C514&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2019\/01\/example36.png?fit=1200%2C514&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2019\/01\/example36.png?fit=1200%2C514&ssl=1&resize=700%2C400 2x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2019\/01\/example36.png?fit=1200%2C514&ssl=1&resize=1050%2C600 3x"},"classes":[]},{"id":1139,"url":"https:\/\/gantovnik.com\/bio-tips\/2021\/11\/200-plot-in-matplotlib\/","url_meta":{"origin":1971,"position":5},"title":"#200 Plot in matplotlib","author":"gantovnik","date":"2021-11-22","format":false,"excerpt":"[code language=\"python\"] # Plot in matplotlib import numpy as np import matplotlib.pyplot as plt from math import pi x = np.linspace(-2.0*pi,2.0*pi,200) plt.plot(x,np.sin(x)) samples=x[::2] plt.plot(samples,np.sin(samples),'r*') plt.title('Function sin(x) and some points plotted') plt.grid() plt.xlabel(\"x\") plt.ylabel(\"y\") plt.savefig('ex200.png', dpi=72) plt.show() [\/code]","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\/ex200.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2021\/11\/ex200.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2021\/11\/ex200.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2021\/11\/ex200.png?resize=700%2C400&ssl=1 2x"},"classes":[]}],"_links":{"self":[{"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/posts\/1971","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=1971"}],"version-history":[{"count":1,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/posts\/1971\/revisions"}],"predecessor-version":[{"id":2071,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/posts\/1971\/revisions\/2071"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/media\/1972"}],"wp:attachment":[{"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/media?parent=1971"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/categories?post=1971"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/tags?post=1971"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}