{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\n# Stem plot\n\n`~.pyplot.stem` plots vertical lines from a baseline to the y-coordinate and\nplaces a marker at the tip.\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import matplotlib.pyplot as plt\nimport numpy as np\n\nx = np.linspace(0.1, 2 * np.pi, 41)\ny = np.exp(np.sin(x))\n\nplt.stem(x, y)\nplt.show()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The position of the baseline can be adapted using *bottom*.\nThe parameters *linefmt*, *markerfmt*, and *basefmt* control basic format\nproperties of the plot. However, in contrast to `~.pyplot.plot` not all\nproperties are configurable via keyword arguments. For more advanced\ncontrol adapt the line objects returned by `.pyplot`.\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "markerline, stemlines, baseline = plt.stem(\n x, y, linefmt='grey', markerfmt='D', bottom=1.1)\nmarkerline.set_markerfacecolor('none')\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 - `matplotlib.axes.Axes.stem` / `matplotlib.pyplot.stem`\n\n.. tags::\n\n plot-type: stem\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.13.2" } }, "nbformat": 4, "nbformat_minor": 0 }