Version 3.1.2
matplotlib

Related Topics

Set default x-axis tick labels on the topΒΆ

We can use rcParams["xtick.labeltop"] = False (default False) and rcParams["xtick.top"] = False (default False) and rcParams["xtick.labelbottom"] = True (default True) and rcParams["xtick.bottom"] = True (default True) to control where on the axes ticks and their labels appear.

These properties can also be set in .matplotlib/matplotlibrc.

Traceback (most recent call last):
  File "/build/matplotlib-mO9dyQ/matplotlib-3.1.2/examples/ticks_and_spines/tick_xlabel_top.py", line 1
    ==========================================
    ^
SyntaxError: invalid syntax
==========================================
Set default x-axis tick labels on the top
==========================================

We can use :rc:`xtick.labeltop` (default False) and :rc:`xtick.top`
(default False) and :rc:`xtick.labelbottom` (default True) and
:rc:`xtick.bottom` (default True) to control where on the axes ticks and
their labels appear.

These properties can also be set in ``.matplotlib/matplotlibrc``.
"""

import matplotlib.pyplot as plt
import numpy as np


plt.rcParams['xtick.bottom'] = plt.rcParams['xtick.labelbottom'] = False
plt.rcParams['xtick.top'] = plt.rcParams['xtick.labeltop'] = True

x = np.arange(10)

fig, ax = plt.subplots()

ax.plot(x)
ax.set_title('xlabel top')  # Note title moves to make room for ticks

plt.show()

Keywords: matplotlib code example, codex, python plot, pyplot Gallery generated by Sphinx-Gallery