{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\n# Scales on 3D (Log, Symlog, etc.)\n\nDemonstrate how to use non-linear scales such as logarithmic scales on 3D axes.\n\n3D axes support the same axis scales as 2D plots: 'linear', 'log', 'symlog',\n'logit', 'asinh', and custom 'function' scales. This example shows a mix of\nscales: linear on X, log on Y, and symlog on Z.\n\nFor a complete list of built-in scales, see `matplotlib.scale`. For an overview\nof scale transformations, see :doc:`/gallery/scales/scales`.\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import matplotlib.pyplot as plt\nimport numpy as np\n\n# A sine chirp with increasing frequency and amplitude\nx = np.linspace(0, 1, 400) # time\ny = 10 ** (2 * x) # frequency, growing exponentially from 1 to 100 Hz\nphase = 2 * np.pi * (10 ** (2 * x) - 1) / (2 * np.log(10))\nz = np.sin(phase) * x **2 * 10 # amplitude, growing quadratically\n\nfig = plt.figure()\nax = fig.add_subplot(projection='3d')\nax.plot(x, y, z)\n\nax.set_xlabel('Time (linear)')\nax.set_ylabel('Frequency, Hz (log)')\nax.set_zlabel('Amplitude (symlog)')\n\nax.set_yscale('log')\nax.set_zscale('symlog')\n\nplt.show()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ ".. admonition:: References\n\n The use of the following functions, methods, classes and modules is shown\n in this example:\n\n - `mpl_toolkits.mplot3d.axes3d.Axes3D.set_xscale`\n - `mpl_toolkits.mplot3d.axes3d.Axes3D.set_yscale`\n - `mpl_toolkits.mplot3d.axes3d.Axes3D.set_zscale`\n - `matplotlib.scale`\n\n.. tags::\n plot-type: 3D,\n level: beginner\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.12.15" } }, "nbformat": 4, "nbformat_minor": 0 }