{"id":7619,"date":"2021-01-13T20:36:37","date_gmt":"2021-01-13T15:06:37","guid":{"rendered":"http:\/\/www.pythonpool.com\/?p=7619"},"modified":"2026-07-13T12:31:08","modified_gmt":"2026-07-13T07:01:08","slug":"matplotlib-pcolormesh","status":"publish","type":"post","link":"https:\/\/www.pythonpool.com\/matplotlib-pcolormesh\/","title":{"rendered":"Matplotlib pcolormesh: X, Y, C Shapes and Shading"},"content":{"rendered":"<p><code>matplotlib.pyplot.pcolormesh()<\/code> creates a pseudocolor plot from a 2D value array. It is useful for heatmaps, scientific fields, and gridded measurements where the x and y coordinates matter. Unlike a simple image display, <code>pcolormesh()<\/code> can represent non-uniform rectangular coordinates and gives explicit control over how cells receive colors.<\/p>\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_85 counter-hierarchy ez-toc-counter ez-toc-transparent ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #990303;color:#990303\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #990303;color:#990303\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 eztoc-toggle-hide-by-default' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/www.pythonpool.com\/matplotlib-pcolormesh\/#Quick_answer\" >Quick answer<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/www.pythonpool.com\/matplotlib-pcolormesh\/#Basic_pcolormesh_example\" >Basic pcolormesh example<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/www.pythonpool.com\/matplotlib-pcolormesh\/#Understand_X_Y_and_C_shapes\" >Understand X, Y, and C shapes<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/www.pythonpool.com\/matplotlib-pcolormesh\/#Use_flat_shading_for_cell_corners\" >Use flat shading for cell corners<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/www.pythonpool.com\/matplotlib-pcolormesh\/#Use_nearest_shading_for_same-shape_grid_points\" >Use nearest shading for same-shape grid points<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/www.pythonpool.com\/matplotlib-pcolormesh\/#Use_Gouraud_shading_for_interpolation\" >Use Gouraud shading for interpolation<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/www.pythonpool.com\/matplotlib-pcolormesh\/#Plot_a_non-uniform_grid\" >Plot a non-uniform grid<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/www.pythonpool.com\/matplotlib-pcolormesh\/#Control_colors_and_the_colorbar\" >Control colors and the colorbar<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/www.pythonpool.com\/matplotlib-pcolormesh\/#Common_mistakes\" >Common mistakes<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/www.pythonpool.com\/matplotlib-pcolormesh\/#Use_the_Axes_API_and_layout_carefully\" >Use the Axes API and layout carefully<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/www.pythonpool.com\/matplotlib-pcolormesh\/#Mask_missing_grid_values\" >Mask missing grid values<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/www.pythonpool.com\/matplotlib-pcolormesh\/#Frequently_Asked_Questions\" >Frequently Asked Questions<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-13\" href=\"https:\/\/www.pythonpool.com\/matplotlib-pcolormesh\/#Frequently_Asked_Questions-2\" >Frequently Asked Questions<\/a><\/li><\/ul><\/nav><\/div>\n<h2><span class=\"ez-toc-section\" id=\"Quick_answer\"><\/span>Quick answer<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Start with <code>ax.pcolormesh(X, Y, C, shading=\"auto\")<\/code>, where <code>C<\/code> contains the values and <code>X<\/code> and <code>Y<\/code> define the grid. For <code>shading=\"flat\"<\/code>, the coordinate dimensions are one larger than <code>C<\/code> because they describe cell corners. For <code>shading=\"nearest\"<\/code> or <code>\"gouraud\"<\/code>, the coordinate dimensions match <code>C<\/code>. Add the returned mesh to <code>fig.colorbar()<\/code>.<\/p>\n<p>The <a href=\"https:\/\/matplotlib.org\/stable\/api\/_as_gen\/matplotlib.pyplot.pcolormesh.html\">Matplotlib pcolormesh reference<\/a> documents the X, Y, and C shape rules, while the <a href=\"https:\/\/matplotlib.org\/stable\/gallery\/images_contours_and_fields\/pcolormesh_grids.html\">pcolormesh grids example<\/a> shows how shading changes the interpretation of coordinates. Use the object-oriented Axes method for maintainable figures.<\/p>\n<figure class=\"pythonpool-article-visual\"><img src=\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2026\/07\/pcolormesh-shading-modes.png\" alt=\"Matplotlib pcolormesh X Y C grid shapes compared across flat nearest gouraud and auto shading\" width=\"1536\" height=\"1024\" loading=\"lazy\" decoding=\"async\"><figcaption>Choose corner or center coordinates first, then match X and Y dimensions to C for the selected shading mode.<\/figcaption><\/figure>\n<h2><span class=\"ez-toc-section\" id=\"Basic_pcolormesh_example\"><\/span>Basic pcolormesh example<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Create a grid, calculate one value for each point, and store the returned QuadMesh so the colorbar uses the same normalization.<\/p>\n<pre><code class=\"language-python\">import numpy as np\nimport matplotlib.pyplot as plt\n\nx = np.linspace(-3, 3, 80)\ny = np.linspace(-2, 2, 60)\nX, Y = np.meshgrid(x, y)\nZ = np.sin(X**2 + Y**2)\n\nfig, ax = plt.subplots()\nmesh = ax.pcolormesh(X, Y, Z, shading=\"auto\", cmap=\"viridis\")\nfig.colorbar(mesh, ax=ax, label=\"value\")\nax.set_title(\"pcolormesh example\")\nplt.show()<\/code><\/pre>\n<p><code>shading=\"auto\"<\/code> is a practical default because Matplotlib chooses a compatible interpretation from the coordinate shapes. When you need a specific cell model, set the shading mode explicitly and verify the dimensions.<\/p>\n<p><!-- Python Pool visual layout repair 2026-07-13 --><\/p>\n<figure class=\"pythonpool-article-visual pythonpool-supporting-visual\"><img src=\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2026\/07\/mesh-grid-b153.png\" alt=\"Python Pool infographic showing X Y grids, cell corners, C values, pcolormesh, and a colored mesh\" width=\"1536\" height=\"1054\" loading=\"lazy\" decoding=\"async\"><figcaption>Mesh grid: X Y grids, cell corners, C values, pcolormesh, and a colored mesh.<\/figcaption><\/figure>\n<h2><span class=\"ez-toc-section\" id=\"Understand_X_Y_and_C_shapes\"><\/span>Understand X, Y, and C shapes<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>If <code>C<\/code> has shape <code>(M, N)<\/code>, flat shading expects x and y corner coordinates with shape <code>(M+1, N+1)<\/code>. Nearest and Gouraud shading use coordinates with shape <code>(M, N)<\/code>. One-dimensional x and y arrays can be expanded into a rectangular grid.<\/p>\n<pre><code class=\"language-python\">import numpy as np\n\nC = np.arange(15).reshape(3, 5)\nprint(C.shape)\n\nx_edges = np.arange(6)\ny_edges = np.arange(4)\nprint(x_edges.shape)\nprint(y_edges.shape)<\/code><\/pre>\n<p>Shape errors are usually more useful than they look. Compare each dimension instead of changing array sizes blindly. Ask whether your coordinates describe cell corners or cell centers.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Use_flat_shading_for_cell_corners\"><\/span>Use flat shading for cell corners<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Flat shading gives each quadrilateral one solid color from the corresponding entry in <code>C<\/code>. The coordinate arrays describe the edges around those cells.<\/p>\n<pre><code class=\"language-python\">import numpy as np\nimport matplotlib.pyplot as plt\n\nC = np.arange(15).reshape(3, 5)\nx = np.arange(6)\ny = np.arange(4)\n\nfig, ax = plt.subplots()\nmesh = ax.pcolormesh(x, y, C, shading=\"flat\", cmap=\"plasma\")\nfig.colorbar(mesh, ax=ax)\nplt.show()<\/code><\/pre>\n<p>This mode is a good fit when measurements are attached to rectangular cells, such as bins or finite-volume regions. The extra coordinate is not an arbitrary padding value; it closes the final boundary.<\/p>\n<figure class=\"pythonpool-article-visual pythonpool-supporting-visual\"><img src=\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2026\/07\/mesh-shading-b153.png\" alt=\"Python Pool infographic comparing flat, nearest, gouraud, grid shapes, and cell interpretation\" width=\"1536\" height=\"1054\" loading=\"lazy\" decoding=\"async\"><figcaption>Shading modes: Flat, nearest, gouraud, grid shapes, and cell interpretation.<\/figcaption><\/figure>\n<h2><span class=\"ez-toc-section\" id=\"Use_nearest_shading_for_same-shape_grid_points\"><\/span>Use nearest shading for same-shape grid points<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Nearest shading centers each color around its matching coordinate point. The X, Y, and C arrays must have the same shape.<\/p>\n<pre><code class=\"language-python\">import numpy as np\nimport matplotlib.pyplot as plt\n\nx = np.arange(5)\ny = np.arange(3)\nX, Y = np.meshgrid(x, y)\nC = X + Y\n\nfig, ax = plt.subplots()\nmesh = ax.pcolormesh(X, Y, C, shading=\"nearest\", cmap=\"magma\")\nfig.colorbar(mesh, ax=ax)\nplt.show()<\/code><\/pre>\n<p>Use this interpretation when each value belongs to a known grid point rather than the space between corner coordinates. It is different from simply resizing an image.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Use_Gouraud_shading_for_interpolation\"><\/span>Use Gouraud shading for interpolation<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Gouraud shading interpolates colors between neighboring grid points and can produce a smooth visual transition. It still requires X, Y, and C to have matching dimensions.<\/p>\n<pre><code class=\"language-python\">import numpy as np\nimport matplotlib.pyplot as plt\n\nx = np.linspace(-2, 2, 80)\ny = np.linspace(-2, 2, 80)\nX, Y = np.meshgrid(x, y)\nC = np.exp(-(X**2 + Y**2))\n\nfig, ax = plt.subplots()\nmesh = ax.pcolormesh(X, Y, C, shading=\"gouraud\", cmap=\"viridis\")\nfig.colorbar(mesh, ax=ax)\nplt.show()<\/code><\/pre>\n<p>Smooth rendering does not add information to the data. Use it when interpolation is an honest visual representation, not when a rough grid needs to look more precise.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Plot_a_non-uniform_grid\"><\/span>Plot a non-uniform grid<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>One advantage over <code>imshow()<\/code> is that x and y spacing can be uneven. This matters when the coordinate system is not a regular image grid.<\/p>\n<pre><code class=\"language-python\">import numpy as np\nimport matplotlib.pyplot as plt\n\nx = np.array([-3, -2, -1.4, -0.7, -0.2, 0.4, 1.2, 2.4, 3.0])\ny = np.linspace(-2, 2, 60)\nX, Y = np.meshgrid(x, y)\nZ = np.cos(X) * np.sin(Y)\n\nfig, ax = plt.subplots()\nmesh = ax.pcolormesh(X, Y, Z, shading=\"auto\", cmap=\"coolwarm\")\nfig.colorbar(mesh, ax=ax)\nplt.show()<\/code><\/pre>\n<p>Choose <code>imshow()<\/code> when the data is an evenly spaced image-like array and explicit coordinates do not matter. Choose <code>pcolormesh()<\/code> when the grid geometry is part of the meaning.<\/p>\n<figure class=\"pythonpool-article-visual pythonpool-supporting-visual\"><img src=\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2026\/07\/mesh-colors-b153.png\" alt=\"Python Pool infographic mapping C values through cmap, Normalize, vmin, vmax, and colorbar\" width=\"1536\" height=\"1054\" loading=\"lazy\" decoding=\"async\"><figcaption>Mesh colors: C values through cmap, Normalize, vmin, vmax, and colorbar.<\/figcaption><\/figure>\n<h2><span class=\"ez-toc-section\" id=\"Control_colors_and_the_colorbar\"><\/span>Control colors and the colorbar<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>The <code>cmap<\/code> argument selects a colormap. <code>vmin<\/code> and <code>vmax<\/code> control the numeric range mapped to that colormap, which is important when comparing several panels.<\/p>\n<pre><code class=\"language-python\">mesh = ax.pcolormesh(\n    X,\n    Y,\n    Z,\n    shading=\"auto\",\n    cmap=\"viridis\",\n    vmin=-1,\n    vmax=1,\n)\nfig.colorbar(mesh, ax=ax, label=\"normalized value\")<\/code><\/pre>\n<p>Use a shared normalization when separate plots must be comparable. A colorbar without the returned mesh can accidentally use a different object or fail to communicate the data range.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Common_mistakes\"><\/span>Common mistakes<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<ul>\n<li>Passing corner coordinates with same-shape data while using flat shading.<\/li>\n<li>Assuming nearest shading describes cell corners.<\/li>\n<li>Forgetting the colorbar or using a different mesh for it.<\/li>\n<li>Using imshow when the x and y spacing is non-uniform.<\/li>\n<li>Using smooth shading to imply precision the measurements do not have.<\/li>\n<\/ul>\n<p>The practical workflow is to identify what each value represents, choose corner or center coordinates, check the shapes, then choose the shading mode. With that model clear, most pcolormesh errors become straightforward shape corrections rather than trial and error.<\/p>\n<figure class=\"pythonpool-article-visual pythonpool-supporting-visual\"><img src=\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2026\/07\/mesh-check-b153.png\" alt=\"Python Pool infographic testing X Y shape, masked values, edge lines, aspect, and output\" width=\"1536\" height=\"1054\" loading=\"lazy\" decoding=\"async\"><figcaption>Mesh checks: X Y shape, masked values, edge lines, aspect, and output.<\/figcaption><\/figure>\n<h2><span class=\"ez-toc-section\" id=\"Use_the_Axes_API_and_layout_carefully\"><\/span>Use the Axes API and layout carefully<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>The Axes method keeps a figure&#8217;s data and formatting in one object, which is especially useful when a page contains several heatmaps. Set axis labels, limits, and a title on the same Axes that owns the mesh. Let the figure manage the colorbar so its size and position stay aligned with the plot.<\/p>\n<p>For a report or article, choose a figure size that leaves room for the colorbar and long tick labels. Apply a layout method after adding the colorbar and inspect the result at the final display size. A technically correct mesh can still be unreadable if labels or the scale are clipped.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Mask_missing_grid_values\"><\/span>Mask missing grid values<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>If some C values are invalid, use a masked array or a documented replacement rather than drawing misleading colors. Check how the chosen colormap represents bad values and explain the missing-data convention in the caption. This is particularly important for scientific fields where a blank cell and a zero cell mean different things.<\/p>\n<p>Save the returned mesh when you need consistent normalization across panels. Reusing one value range makes visual comparisons meaningful; allowing each panel to autoscale can make identical values appear to have different importance.<\/p>\n<p data-pythonpool-link-set=\"2026-07-13-final\">For matrix-style plots, compare pcolormesh with colorbars and imshow(). Read <a href=\"https:\/\/www.pythonpool.com\/matplotlib-colorbar\/\">matplotlib colorbar<\/a> and <a href=\"https:\/\/www.pythonpool.com\/matplotlib-imshow\/\">matplotlib imshow<\/a> for the related workflow.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Frequently_Asked_Questions\"><\/span>Frequently Asked Questions<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<h2><span class=\"ez-toc-section\" id=\"Frequently_Asked_Questions-2\"><\/span>Frequently Asked Questions<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<h3>What is pcolormesh used for?<\/h3>\n<p>pcolormesh creates pseudocolor plots from a 2D value array and is especially useful when x and y grid coordinates are explicit or non-uniform.<\/p>\n<h3>What shape does pcolormesh need?<\/h3>\n<p>For flat shading, X and Y are one larger than C in each dimension. For nearest and gouraud, X, Y, and C have matching shapes.<\/p>\n<h3>What does shading auto do?<\/h3>\n<p>shading=&#8217;auto&#8217; chooses flat when the coordinate arrays are one larger than C and nearest when they have the same shape.<\/p>\n<h3>What is the difference between pcolormesh and imshow?<\/h3>\n<p>pcolormesh can represent explicit and uneven grid coordinates, while imshow is simpler for regular image-like arrays.<\/p>\n<p><script type=\"application\/ld+json\">{\"@context\":\"https:\/\/schema.org\",\"@type\":\"FAQPage\",\"mainEntity\":[{\"@type\":\"Question\",\"name\":\"What is pcolormesh used for?\",\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"pcolormesh creates pseudocolor plots from a 2D value array and is especially useful when x and y grid coordinates are explicit or non-uniform.\"}},{\"@type\":\"Question\",\"name\":\"What shape does pcolormesh need?\",\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"For flat shading, X and Y are one larger than C in each dimension. For nearest and gouraud, X, Y, and C have matching shapes.\"}},{\"@type\":\"Question\",\"name\":\"What does shading auto do?\",\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"shading='auto' chooses flat when the coordinate arrays are one larger than C and nearest when they have the same shape.\"}},{\"@type\":\"Question\",\"name\":\"What is the difference between pcolormesh and imshow?\",\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"pcolormesh can represent explicit and uneven grid coordinates, while imshow is simpler for regular image-like arrays.\"}}]}<\/script><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Use Matplotlib pcolormesh for 2D grids with correct X, Y, C dimensions, shading modes, colorbars, and uneven coordinate spacing.<\/p>\n","protected":false},"author":12,"featured_media":32116,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[2071],"tags":[3275,3269,3268,3273,3274,3270,3272,3271],"class_list":["post-7619","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-matplotlib","tag-pcolormesh-matplotlib-inner","tag-matplotlib-axes-pcolormesh","tag-matplotlib-colorbar-pcolormesh","tag-matplotlib-pcolormesh-log-scale","tag-matplotlib-pcolormesh-mask","tag-matplotlib-pyplot-pcolormesh","tag-pcolormesh-matplotlib","tag-python-matplotlib-pcolormesh-cmap","infinite-scroll-item"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v20.1 (Yoast SEO v28.0) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Matplotlib pcolormesh: X, Y, C Shapes and Shading<\/title>\n<meta name=\"description\" content=\"Learn Matplotlib pcolormesh with X, Y, and C shape rules, shading auto, flat, nearest, gouraud, colorbars, and non-uniform grids.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.pythonpool.com\/matplotlib-pcolormesh\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Matplotlib pcolormesh: X, Y, C Shapes and Shading\" \/>\n<meta property=\"og:description\" content=\"Use Matplotlib pcolormesh for 2D grids with correct X, Y, C dimensions, shading modes, colorbars, and uneven coordinate spacing.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.pythonpool.com\/matplotlib-pcolormesh\/\" \/>\n<meta property=\"og:site_name\" content=\"Python Pool\" \/>\n<meta property=\"article:published_time\" content=\"2021-01-13T15:06:37+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-07-13T07:01:08+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2026\/07\/pcolormesh-shading-modes.png\" \/>\n<meta name=\"author\" content=\"Prachee Sao\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:title\" content=\"Python Pool\" \/>\n<meta name=\"twitter:description\" content=\"Practical Python tutorials, error fixes, code examples, and project guides.\" \/>\n<meta name=\"twitter:image\" content=\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2026\/07\/pcolormesh-shading-modes.png\" \/>\n<meta name=\"twitter:creator\" content=\"@pythonpool\" \/>\n<meta name=\"twitter:site\" content=\"@pythonpool\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Prachee Sao\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/matplotlib-pcolormesh\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/matplotlib-pcolormesh\\\/\"},\"author\":{\"name\":\"Prachee Sao\",\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/#\\\/schema\\\/person\\\/b91d749826b21e606d55cda77d51ef47\"},\"headline\":\"Matplotlib pcolormesh: X, Y, C Shapes and Shading\",\"datePublished\":\"2021-01-13T15:06:37+00:00\",\"dateModified\":\"2026-07-13T07:01:08+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/matplotlib-pcolormesh\\\/\"},\"wordCount\":1017,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/matplotlib-pcolormesh\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.pythonpool.com\\\/wp-content\\\/uploads\\\/2026\\\/07\\\/matplotlib-pcolormesh-quadmesh-grid.png\",\"keywords\":[\"&quot;pcolormesh&quot; &quot;matplotlib&quot; &quot;inner&quot;\",\"matplotlib axes pcolormesh\",\"matplotlib colorbar pcolormesh\",\"matplotlib pcolormesh log scale\",\"matplotlib pcolormesh mask\",\"matplotlib pyplot pcolormesh\",\"pcolormesh matplotlib\",\"python matplotlib pcolormesh cmap\"],\"articleSection\":[\"Matplotlib\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.pythonpool.com\\\/matplotlib-pcolormesh\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/matplotlib-pcolormesh\\\/\",\"url\":\"https:\\\/\\\/www.pythonpool.com\\\/matplotlib-pcolormesh\\\/\",\"name\":\"Matplotlib pcolormesh: X, Y, C Shapes and Shading\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/matplotlib-pcolormesh\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/matplotlib-pcolormesh\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.pythonpool.com\\\/wp-content\\\/uploads\\\/2026\\\/07\\\/matplotlib-pcolormesh-quadmesh-grid.png\",\"datePublished\":\"2021-01-13T15:06:37+00:00\",\"dateModified\":\"2026-07-13T07:01:08+00:00\",\"description\":\"Learn Matplotlib pcolormesh with X, Y, and C shape rules, shading auto, flat, nearest, gouraud, colorbars, and non-uniform grids.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/matplotlib-pcolormesh\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.pythonpool.com\\\/matplotlib-pcolormesh\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/matplotlib-pcolormesh\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.pythonpool.com\\\/wp-content\\\/uploads\\\/2026\\\/07\\\/matplotlib-pcolormesh-quadmesh-grid.png\",\"contentUrl\":\"https:\\\/\\\/www.pythonpool.com\\\/wp-content\\\/uploads\\\/2026\\\/07\\\/matplotlib-pcolormesh-quadmesh-grid.png\",\"width\":1350,\"height\":650,\"caption\":\"Matplotlib pcolormesh QuadMesh grid with shading auto and colorbar\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/matplotlib-pcolormesh\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.pythonpool.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Matplotlib pcolormesh: X, Y, C Shapes and Shading\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/#website\",\"url\":\"https:\\\/\\\/www.pythonpool.com\\\/\",\"name\":\"Python Pool\",\"description\":\"Practical Python tutorials, error fixes, code examples, and project guides.\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.pythonpool.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/#organization\",\"name\":\"Python Pool\",\"url\":\"https:\\\/\\\/www.pythonpool.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.pythonpool.com\\\/wp-content\\\/uploads\\\/2020\\\/08\\\/aa.png\",\"contentUrl\":\"https:\\\/\\\/www.pythonpool.com\\\/wp-content\\\/uploads\\\/2020\\\/08\\\/aa.png\",\"width\":452,\"height\":185,\"caption\":\"Python Pool\"},\"image\":{\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/x.com\\\/pythonpool\",\"https:\\\/\\\/www.youtube.com\\\/c\\\/pythonpool\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/#\\\/schema\\\/person\\\/b91d749826b21e606d55cda77d51ef47\",\"name\":\"Prachee Sao\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/d018c3758049ab2511d0772ac1f73c338aaa8c921577f39e0f1e5716fc7efcb4?s=96&d=wavatar&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/d018c3758049ab2511d0772ac1f73c338aaa8c921577f39e0f1e5716fc7efcb4?s=96&d=wavatar&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/d018c3758049ab2511d0772ac1f73c338aaa8c921577f39e0f1e5716fc7efcb4?s=96&d=wavatar&r=g\",\"caption\":\"Prachee Sao\"}}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Matplotlib pcolormesh: X, Y, C Shapes and Shading","description":"Learn Matplotlib pcolormesh with X, Y, and C shape rules, shading auto, flat, nearest, gouraud, colorbars, and non-uniform grids.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.pythonpool.com\/matplotlib-pcolormesh\/","og_locale":"en_US","og_type":"article","og_title":"Matplotlib pcolormesh: X, Y, C Shapes and Shading","og_description":"Use Matplotlib pcolormesh for 2D grids with correct X, Y, C dimensions, shading modes, colorbars, and uneven coordinate spacing.","og_url":"https:\/\/www.pythonpool.com\/matplotlib-pcolormesh\/","og_site_name":"Python Pool","article_published_time":"2021-01-13T15:06:37+00:00","article_modified_time":"2026-07-13T07:01:08+00:00","og_image":[{"url":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2026\/07\/pcolormesh-shading-modes.png","type":"","width":"","height":""}],"author":"Prachee Sao","twitter_card":"summary_large_image","twitter_title":"Python Pool","twitter_description":"Practical Python tutorials, error fixes, code examples, and project guides.","twitter_image":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2026\/07\/pcolormesh-shading-modes.png","twitter_creator":"@pythonpool","twitter_site":"@pythonpool","twitter_misc":{"Written by":"Prachee Sao","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.pythonpool.com\/matplotlib-pcolormesh\/#article","isPartOf":{"@id":"https:\/\/www.pythonpool.com\/matplotlib-pcolormesh\/"},"author":{"name":"Prachee Sao","@id":"https:\/\/www.pythonpool.com\/#\/schema\/person\/b91d749826b21e606d55cda77d51ef47"},"headline":"Matplotlib pcolormesh: X, Y, C Shapes and Shading","datePublished":"2021-01-13T15:06:37+00:00","dateModified":"2026-07-13T07:01:08+00:00","mainEntityOfPage":{"@id":"https:\/\/www.pythonpool.com\/matplotlib-pcolormesh\/"},"wordCount":1017,"commentCount":0,"publisher":{"@id":"https:\/\/www.pythonpool.com\/#organization"},"image":{"@id":"https:\/\/www.pythonpool.com\/matplotlib-pcolormesh\/#primaryimage"},"thumbnailUrl":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2026\/07\/matplotlib-pcolormesh-quadmesh-grid.png","keywords":["&quot;pcolormesh&quot; &quot;matplotlib&quot; &quot;inner&quot;","matplotlib axes pcolormesh","matplotlib colorbar pcolormesh","matplotlib pcolormesh log scale","matplotlib pcolormesh mask","matplotlib pyplot pcolormesh","pcolormesh matplotlib","python matplotlib pcolormesh cmap"],"articleSection":["Matplotlib"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.pythonpool.com\/matplotlib-pcolormesh\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.pythonpool.com\/matplotlib-pcolormesh\/","url":"https:\/\/www.pythonpool.com\/matplotlib-pcolormesh\/","name":"Matplotlib pcolormesh: X, Y, C Shapes and Shading","isPartOf":{"@id":"https:\/\/www.pythonpool.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.pythonpool.com\/matplotlib-pcolormesh\/#primaryimage"},"image":{"@id":"https:\/\/www.pythonpool.com\/matplotlib-pcolormesh\/#primaryimage"},"thumbnailUrl":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2026\/07\/matplotlib-pcolormesh-quadmesh-grid.png","datePublished":"2021-01-13T15:06:37+00:00","dateModified":"2026-07-13T07:01:08+00:00","description":"Learn Matplotlib pcolormesh with X, Y, and C shape rules, shading auto, flat, nearest, gouraud, colorbars, and non-uniform grids.","breadcrumb":{"@id":"https:\/\/www.pythonpool.com\/matplotlib-pcolormesh\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.pythonpool.com\/matplotlib-pcolormesh\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.pythonpool.com\/matplotlib-pcolormesh\/#primaryimage","url":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2026\/07\/matplotlib-pcolormesh-quadmesh-grid.png","contentUrl":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2026\/07\/matplotlib-pcolormesh-quadmesh-grid.png","width":1350,"height":650,"caption":"Matplotlib pcolormesh QuadMesh grid with shading auto and colorbar"},{"@type":"BreadcrumbList","@id":"https:\/\/www.pythonpool.com\/matplotlib-pcolormesh\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.pythonpool.com\/"},{"@type":"ListItem","position":2,"name":"Matplotlib pcolormesh: X, Y, C Shapes and Shading"}]},{"@type":"WebSite","@id":"https:\/\/www.pythonpool.com\/#website","url":"https:\/\/www.pythonpool.com\/","name":"Python Pool","description":"Practical Python tutorials, error fixes, code examples, and project guides.","publisher":{"@id":"https:\/\/www.pythonpool.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.pythonpool.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.pythonpool.com\/#organization","name":"Python Pool","url":"https:\/\/www.pythonpool.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.pythonpool.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/aa.png","contentUrl":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/aa.png","width":452,"height":185,"caption":"Python Pool"},"image":{"@id":"https:\/\/www.pythonpool.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/x.com\/pythonpool","https:\/\/www.youtube.com\/c\/pythonpool"]},{"@type":"Person","@id":"https:\/\/www.pythonpool.com\/#\/schema\/person\/b91d749826b21e606d55cda77d51ef47","name":"Prachee Sao","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/d018c3758049ab2511d0772ac1f73c338aaa8c921577f39e0f1e5716fc7efcb4?s=96&d=wavatar&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/d018c3758049ab2511d0772ac1f73c338aaa8c921577f39e0f1e5716fc7efcb4?s=96&d=wavatar&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/d018c3758049ab2511d0772ac1f73c338aaa8c921577f39e0f1e5716fc7efcb4?s=96&d=wavatar&r=g","caption":"Prachee Sao"}}]}},"_links":{"self":[{"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/posts\/7619","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/users\/12"}],"replies":[{"embeddable":true,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/comments?post=7619"}],"version-history":[{"count":24,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/posts\/7619\/revisions"}],"predecessor-version":[{"id":41541,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/posts\/7619\/revisions\/41541"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/media\/32116"}],"wp:attachment":[{"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/media?parent=7619"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/categories?post=7619"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/tags?post=7619"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}