|
1 | 1 | """
|
2 |
| -========================================== |
3 |
| -Set default x-axis tick labels on the top |
4 |
| -========================================== |
| 2 | +================================== |
| 3 | +Move x-axis tick labels to the top |
| 4 | +================================== |
5 | 5 |
|
6 |
| -We can use :rc:`xtick.labeltop` and :rc:`xtick.top` and :rc:`xtick.labelbottom` |
7 |
| -and :rc:`xtick.bottom` to control where on the axes ticks and their labels |
8 |
| -appear. |
| 6 | +`~.axes.Axes.tick_params` can be used to configure the ticks. *top* and |
| 7 | +*labeltop* control the visibility tick lines and labels at the top x-axis. |
| 8 | +To move x-axis ticks from bottom to top, we have to activate the top ticks |
| 9 | +and deactivate the bottom ticks:: |
9 | 10 |
|
10 |
| -These properties can also be set in ``.matplotlib/matplotlibrc``. |
11 |
| -""" |
| 11 | + ax.tick_params(top=True, labeltop=True, bottom=False, labelbottom=False) |
12 | 12 |
|
13 |
| -import matplotlib.pyplot as plt |
14 |
| -import numpy as np |
| 13 | +.. note:: |
| 14 | +
|
| 15 | + If the change should be made for all future plots and not only the current |
| 16 | + Axes, you can adapt the respective config parameters |
15 | 17 |
|
| 18 | + - :rc:`xtick.top` |
| 19 | + - :rc:`xtick.labeltop` |
| 20 | + - :rc:`xtick.bottom` |
| 21 | + - :rc:`xtick.labelbottom` |
16 | 22 |
|
17 |
| -plt.rcParams['xtick.bottom'] = plt.rcParams['xtick.labelbottom'] = False |
18 |
| -plt.rcParams['xtick.top'] = plt.rcParams['xtick.labeltop'] = True |
| 23 | +""" |
19 | 24 |
|
20 |
| -x = np.arange(10) |
| 25 | +import matplotlib.pyplot as plt |
21 | 26 |
|
22 | 27 | fig, ax = plt.subplots()
|
23 |
| - |
24 |
| -ax.plot(x) |
25 |
| -ax.set_title('xlabel top') # Note title moves to make room for ticks |
| 28 | +ax.plot(range(10)) |
| 29 | +ax.tick_params(top=True, labeltop=True, bottom=False, labelbottom=False) |
| 30 | +ax.set_title('x-ticks moved to the top') |
26 | 31 |
|
27 | 32 | plt.show()
|
0 commit comments