File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 33Set default x-axis tick labels on the top
44==========================================
55
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::
910
10- These properties can also be set in ``.matplotlib/matplotlibrc``.
11- """
11+ ax.tick_params(top=True, labeltop=True, bottom=False, labelbottom=False)
1212
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
1517
18+ - :rc:`xtick.top`
19+ - :rc:`xtick.labeltop`
20+ - :rc:`xtick.bottom`
21+ - :rc:`xtick.labelbottom`
1622
17- plt .rcParams ['xtick.bottom' ] = plt .rcParams ['xtick.labelbottom' ] = False
18- plt .rcParams ['xtick.top' ] = plt .rcParams ['xtick.labeltop' ] = True
23+ """
1924
20- x = np . arange ( 10 )
25+ import matplotlib . pyplot as plt
2126
2227fig , 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' )
2631
2732plt .show ()
You can’t perform that action at this time.
0 commit comments