{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\n# 3D surface (checkerboard)\n\nDemonstrates plotting a 3D surface colored in a checkerboard pattern.\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import matplotlib.pyplot as plt\nimport numpy as np\n\nfrom matplotlib.ticker import LinearLocator\n\nax = plt.figure().add_subplot(projection='3d')\n\n# Make data.\nX = np.arange(-5, 5, 0.25)\nxlen = len(X)\nY = np.arange(-5, 5, 0.25)\nylen = len(Y)\nX, Y = np.meshgrid(X, Y)\nR = np.sqrt(X**2 + Y**2)\nZ = np.sin(R)\n\n# Create an empty array of strings with the same shape as the meshgrid, and\n# populate it with two colors in a checkerboard pattern.\ncolortuple = ('y', 'b')\ncolors = np.empty(X.shape, dtype=str)\nfor y in range(ylen):\n for x in range(xlen):\n colors[y, x] = colortuple[(x + y) % len(colortuple)]\n\n# Plot the surface with face colors taken from the array we made.\nsurf = ax.plot_surface(X, Y, Z, facecolors=colors, linewidth=0)\n\n# Customize the z axis.\nax.set_zlim(-1, 1)\nax.zaxis.set_major_locator(LinearLocator(6))\n\nplt.show()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ ".. tags::\n plot-type: 3D,\n styling: color, styling: texture,\n level: intermediate\n\n" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.13.2" } }, "nbformat": 4, "nbformat_minor": 0 }