Matplotlib Ref Triangles Polar
\n\n\n\nMatplotlib Triangulation and Polar Functions | Online Tutorial \n\n\n\n* * *\n\n[ Matplotlib Reference Documentation](https://example.com/matplotlib/matplotlib-apiref.html)\n\nTriangulation functions are used to plot and visualize data on unstructured grids, and polar functions plot in a polar coordinate system.\n\n## Function Overview\n\n| Function | Description |\n| --- | --- |\n| triplot() | Draw wireframe for unstructured triangulation |\n| tripcolor() | Draw pseudo-color plot on triangulation |\n| tricontour() | Draw contour lines on triangulation |\n| tricontourf() | Draw filled contours on triangulation |\n| polar() | Plot in polar coordinate system (equivalent to subplot_kw projection='polar') |\n\n* * *\n\n## Triangulation Functions\n\n### triplot() - Mesh Wireframe\n\nmatplotlib.pyplot.triplot(*args, **kwargs)Axes.triplot(triangulation, **kwargs)# triangulation: Triangulation object (created from x, y coordinates)\n### tripcolor() - Triangle Pseudo-color\n\nmatplotlib.pyplot.tripcolor(*args, **kwargs)Axes.tripcolor(triangulation, C=None, **kwargs)\n### tricontour() / tricontourf() - Triangle Contour\n\nmatplotlib.pyplot.tricontour(*args, **kwargs) matplotlib.pyplot.tricontourf(*args, **kwargs)Axes.tricontour(triangulation, C=None, levels=None, **kwargs)Axes.tricontourf(triangulation, C=None, levels=None, **kwargs)\n\n## Example\n\nimport matplotlib.pyplot as plt\n\nimport matplotlib.tri as tri\n\nimport numpy as np\n\nnp.random.seed(42)\n\n# Generate random scatter points\n\n n =200\n\n x = np.random.rand(n) * 4 - 2\n\n y = np.random.rand(n) * 4 - 2\n\n# perFunction values at each point\n\n z = x * np.exp(-x**2 - y**2)\n\n# Create Delaunay triangulation\n\n triang = tri.Triangulation(x, y)\n\nfig, axes = plt.subplots(2,2, figsize=(10,8),\n\n layout='constrained')\n\n# Triangular mesh wireframe\n\n axes[0,0].triplot(triang,'k-', linewidth=0.5, alpha=0.5)\n\n axes[0,0].scatter(x, y, c=z, s=8, cmap='viridis')\n\n axes[0,0].set_title('triplot() - Mesh + Scatter')\n\n# Triangular pseudocolor\n\n tc1 = axes[0,1].tripcolor(triang, z, cmap='viridis',\n\n shading='gouraud')# Smooth coloring\n\n fig.colorbar(tc1, ax=axes[0,1], label='z value')\n\n axes[0,1].set_title('tripcolor()')\n\n# Triangular contour\n\n tc2 = axes[1,0].tricontourf(triang, z, levels=12,\n\n cmap='RdYlBu')\n\n axes[1,0].tricontour(triang, z, levels=12,\n\ncolors='black', linewidths=0.3)\n\n fig.colorbar(tc2, ax=axes[1,0], label='z value')\n\n axes[1,0].set_title('tricontourf()')\n\n# Contours only\n\n axes[1,1].tricontour(triang, z, levels=15,\n\ncmap='viridis', linewidths=1.5)\n\n axes[1,1].set_title('tricontour()')\n\nplt.show()\n\n* * *\n\n## polar() - Polar Plotting\n\nmatplotlib.pyplot.polar(*args, **kwargs)# Equivalent to:# plt.subplot(projection='polar')# ax.plot(theta, r)\n| Parameter | Description |\n| --- | --- |\n| theta | Angle array (radians) |\n| r | Radial distance array |\n\n## Example\n\nimport matplotlib.pyplot as plt\n\nimport numpy as np\n\ntheta = np.linspace(0,2*np.pi,100)\n\nfig, axes = plt.subplots(2,2, figsize=(10,10),\n\n subplot_kw={'projection': 'polar'},\n\n layout='constrained')\n\n# Rose curve r = sin(3ΞΈ)\n\n r1 = np.abs(np.sin(3 * theta))\n\n axes[0,0].plot(theta, r1,'blue', linewidth=2)\n\n axes[0,0].set_title('Rose Curve: r=|sin(3ΞΈ)|')\n\n# Archimedean spiral r = ΞΈ\n\n r2 = theta\n\n axes[0,1].plot(theta, r2,'red', linewidth=2)\n\n axes[0,1].set_title('Archimedean Spiral: r=ΞΈ')\n\n# Cardioid r = 1 + cos(ΞΈ)\n\n r3 =1 + np.cos(theta)\n\n axes[1,0].fill(theta, r3, alpha=0.5, color='coral')\n\n axes[1,0].plot(theta, r3,'red', linewidth=2)\n\n axes[1,0].set_title('Cardioid: r=1+cos(ΞΈ)')\n\n# Multiple petals\n\n r4 = np.sin(4 * theta)\n\n axes[1,1].fill(theta, np.abs(r4), alpha=0.5, color='purple')\n\n axes[1,1].plot(theta, np.abs(r4),'purple', linewidth=2)\n\n axes[1,1].set_rticks([0.5,1.0])\n\n axes[1,1].set_title('4-petal Rose: r=|sin(4ΞΈ)|')\n\nplt.show()\n\n### rgrids() / thetagrids() - Polar Grid\n\nmatplotlib.pyplot.rgrids(radii=None, labels=None, angle=None, fmt=None, **kwargs) matplotlib.pyplot.thetagrids(angles=None, labels=None, fmt=None, **kwargs)\n\n## Example\n\nimport matplotlib.pyplot as plt\n\nimport numpy as np\n\nfig, ax = plt.subplots(subplot_kw={'projection': 'polar'},\n\n figsize=(6,6), layout='constrained')\n\ntheta = np.linspace(0,2*np.pi,100)\n\n ax.plot(theta, theta/3, linewidth=2)\n\n# Customize radial grid\n\n ax.set_rticks([1,3,5,7,9])# Radial tick positions in degrees\n\n ax.set_rlabel_position(-22.5)# Radial label position\n\n# Custom angular grid in degrees\n\n ax.set_thetagrids(np.arange(0,360,45),# per 45 degree\n\n labels=['0Β°','45Β°','90Β°','135Β°','180Β°',\n\n'225Β°','270Β°','315Β°'])\n\nax.set_title('Custom Polar Grid')\n\n plt.show()\n\n[ Matplotlib Reference Documentation](https://example.com/matplotlib/matplotlib-apiref.html)\n\n
\n
YouTip