{"id":1781,"date":"2023-01-16T01:33:37","date_gmt":"2023-01-16T09:33:37","guid":{"rendered":"https:\/\/gantovnik.com\/bio-tips\/?p=1781"},"modified":"2023-01-16T01:33:37","modified_gmt":"2023-01-16T09:33:37","slug":"339-nested-gridspec-using-python","status":"publish","type":"post","link":"https:\/\/gantovnik.com\/bio-tips\/2023\/01\/339-nested-gridspec-using-python\/","title":{"rendered":"#339 Nested GridSpec using python"},"content":{"rendered":"<p><a href=\"https:\/\/gantovnik.com\/bio-tips\/2023\/01\/339-nested-gridspec-using-python\/ex339\/\" rel=\"attachment wp-att-1782\"><img data-recalc-dims=\"1\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2023\/01\/ex339.png?resize=800%2C800&#038;ssl=1\" alt=\"\" width=\"800\" height=\"800\" class=\"alignnone size-full wp-image-1782\" srcset=\"https:\/\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2023\/01\/ex339.png 800w, https:\/\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2023\/01\/ex339-480x480.png 480w\" sizes=\"(min-width: 0px) and (max-width: 480px) 480px, (min-width: 481px) 800px, 100vw\" \/><\/a><\/p>\n<p>ex339.py<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nimport numpy as np\r\nimport matplotlib.pyplot as plt\r\n\r\ndef squiggle_xy(a, b, c, d, i=np.arange(0.0, 2*np.pi, 0.05)):\r\n    return np.sin(i*a)*np.cos(i*b), np.sin(i*c)*np.cos(i*d)\r\n\r\nfig11 = plt.figure(figsize=(8, 8), constrained_layout=False)\r\nouter_grid = fig11.add_gridspec(4, 4, wspace=0, hspace=0)\r\n\r\nfor a in range(4):\r\n    for b in range(4):\r\n        # gridspec inside gridspec\r\n        inner_grid = outer_grid&#x5B;a, b].subgridspec(3, 3, wspace=0, hspace=0)\r\n        axs = inner_grid.subplots()  # Create all subplots for the inner grid.\r\n        for (c, d), ax in np.ndenumerate(axs):\r\n            ax.plot(*squiggle_xy(a + 1, b + 1, c + 1, d + 1),color=&quot;black&quot;)\r\n            ax.set(xticks=&#x5B;], yticks=&#x5B;])\r\n\r\n# show only the outside spines\r\nfor ax in fig11.get_axes():\r\n    ss = ax.get_subplotspec()\r\n    ax.spines.top.set_visible(ss.is_first_row())\r\n    ax.spines.bottom.set_visible(ss.is_last_row())\r\n    ax.spines.left.set_visible(ss.is_first_col())\r\n    ax.spines.right.set_visible(ss.is_last_col())\r\n\r\nplt.savefig('ex339.png', dpi=100)\r\nplt.show()\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>ex339.py import numpy as np import matplotlib.pyplot as plt def squiggle_xy(a, b, c, d, i=np.arange(0.0, 2*np.pi, 0.05)): return np.sin(i*a)*np.cos(i*b), np.sin(i*c)*np.cos(i*d) fig11 = plt.figure(figsize=(8, 8), constrained_layout=False) outer_grid = fig11.add_gridspec(4, 4, wspace=0, hspace=0) for a in range(4): for b in range(4): # gridspec inside gridspec inner_grid = outer_grid&#x5B;a, b].subgridspec(3, 3, wspace=0, hspace=0) axs = inner_grid.subplots() # Create [&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-1781","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-sJ","jetpack_likes_enabled":true,"jetpack-related-posts":[{"id":2127,"url":"https:\/\/gantovnik.com\/bio-tips\/2024\/02\/414-how-to-remove-gaps-between-subplots-in-python\/","url_meta":{"origin":1781,"position":0},"title":"#414 How to remove gaps between subplots in python?","author":"gantovnik","date":"2024-02-20","format":false,"excerpt":"[code language=\"python\"] import matplotlib.pyplot as plt import numpy as np fig, axes = plt.subplots(1, 2, sharey=True) xx = np.linspace(-10, 10, 1000) [ax.grid() for ax in axes] axes[0].plot(np.sin(xx * xx), color=\"blue\") axes[1].plot(np.cos(xx) * xx, color=\"red\") fig.subplots_adjust(wspace=0) # no horizontal space plt.savefig(\"ex414.png\", dpi=100) plt.show() [\/code]","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\/02\/ex414.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2024\/02\/ex414.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2024\/02\/ex414.png?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":2059,"url":"https:\/\/gantovnik.com\/bio-tips\/2024\/01\/407-multiple-axes-animation-using-python\/","url_meta":{"origin":1781,"position":1},"title":"#407 Multiple axes animation using python","author":"gantovnik","date":"2024-01-14","format":false,"excerpt":"y=sin(x) [code language=\"python\"] import matplotlib.pyplot as plt import numpy as np import matplotlib.animation as animation from matplotlib.patches import ConnectionPatch fig, (axl, axr) = plt.subplots( ncols=2, sharey=True, figsize=(6, 2), gridspec_kw=dict(width_ratios=[1, 3], wspace=0), ) axl.set_aspect(1) axr.set_box_aspect(1 \/ 3) axr.yaxis.set_visible(False) axr.xaxis.set_ticks([0, np.pi, 2 * np.pi], [\"0\", r\"$\\pi$\", r\"$2\\pi$\"]) # draw circle with initial\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\/01\/ex407.gif?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2024\/01\/ex407.gif?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2024\/01\/ex407.gif?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":114,"url":"https:\/\/gantovnik.com\/bio-tips\/2019\/01\/figure-with-no-inter-subplot-spacing\/","url_meta":{"origin":1781,"position":2},"title":"Figure with no inter-subplot spacing","author":"gantovnik","date":"2019-01-03","format":false,"excerpt":"import os import matplotlib.pyplot as plt from numpy.random import randn os.chdir(r'D:\\data\\scripts\\web1\\ex21') os.getcwd() fig,ax = plt.subplots(2,2,sharex=True,sharey=True) for i in range(2): for j in range (2): ax[i,j].hist(randn(500),bins=50,color='k',alpha=0.5) plt.subplots_adjust(wspace=0,hspace=0) fig.suptitle('Figure with no inter-subplot spacing') plt.savefig(\"example21.png\", dpi=100) plt.show() plt.close()","rel":"","context":"In &quot;python&quot;","block_context":{"text":"python","link":"https:\/\/gantovnik.com\/bio-tips\/category\/python\/"},"img":{"alt_text":"example21","src":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2019\/01\/example21.png?resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2019\/01\/example21.png?resize=350%2C200 1x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2019\/01\/example21.png?resize=525%2C300 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":1781,"position":3},"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":2889,"url":"https:\/\/gantovnik.com\/bio-tips\/2024\/07\/440-cycloid-on-interactive-figure-with-widgets-in-python\/","url_meta":{"origin":1781,"position":4},"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":3018,"url":"https:\/\/gantovnik.com\/bio-tips\/2024\/07\/441-parametric-curve-lemniscate-of-bernoulli-with-slider-in-python\/","url_meta":{"origin":1781,"position":5},"title":"#441 Parametric curve Lemniscate of Bernoulli with Slider in python","author":"gantovnik","date":"2024-07-25","format":false,"excerpt":"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('equal') ax1.set_ylim(-0.5,0.5) ax1.set_xlim(-1.2,1.2) ax1.title.set_text('Parametric curve: Lemniscate of Bernoulli') ax1.grid('on') r, = ax1.plot(rx(t), ry(t),'b', markersize=3) Pnt1, = ax1.plot(rx(t), ry(t),'ro', markersize=6) axt = plt.axes([0.25, 0.1,\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\/ex441.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2024\/07\/ex441.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2024\/07\/ex441.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2024\/07\/ex441.png?resize=700%2C400&ssl=1 2x"},"classes":[]}],"_links":{"self":[{"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/posts\/1781","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=1781"}],"version-history":[{"count":0,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/posts\/1781\/revisions"}],"wp:attachment":[{"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/media?parent=1781"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/categories?post=1781"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/tags?post=1781"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}