{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\n# Rotated tick labels\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import matplotlib.pyplot as plt\n\nx = [1, 2, 3, 4]\ny = [1, 4, 9, 6]\nlabels = ['Frogs', 'Hogs', 'Bogs', 'Slogs']\n\nfig, ax = plt.subplots()\nax.plot(x, y)\n# A tick label rotation can be set using Axes.tick_params.\nax.tick_params(\"y\", rotation=45)\n# Alternatively, if setting custom labels with set_xticks/set_yticks, it can\n# be set at the same time as the labels.\n# For both APIs, the rotation can be an angle in degrees, or one of the strings\n# \"horizontal\" or \"vertical\".\nax.set_xticks(x, labels, rotation='vertical')\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 - `matplotlib.axes.Axes.tick_params` / `matplotlib.pyplot.tick_params`\n - `matplotlib.axes.Axes.set_xticks` / `matplotlib.pyplot.xticks`\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 }