{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\n# Move x-axis tick labels to the top\n\n`~.axes.Axes.tick_params` can be used to configure the ticks. *top* and\n*labeltop* control the visibility tick lines and labels at the top x-axis.\nTo move x-axis ticks from bottom to top, we have to activate the top ticks\nand deactivate the bottom ticks::\n\n ax.tick_params(top=True, labeltop=True, bottom=False, labelbottom=False)\n\n

Note

If the change should be made for all future plots and not only the current\n Axes, you can adapt the respective config parameters\n\n - :rc:`xtick.top`\n - :rc:`xtick.labeltop`\n - :rc:`xtick.bottom`\n - :rc:`xtick.labelbottom`

\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import matplotlib.pyplot as plt\n\nfig, ax = plt.subplots()\nax.plot(range(10))\nax.tick_params(top=True, labeltop=True, bottom=False, labelbottom=False)\nax.set_title('x-ticks moved to the top')\n\nplt.show()" ] } ], "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 }