Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 82ef9cf

Browse files
committed
Added xtick.labeltop and xtick.labelbottom for matplotlibrc
1 parent 6bdef9f commit 82ef9cf

5 files changed

Lines changed: 54 additions & 0 deletions

File tree

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
"""
2+
==========================================
3+
Set default x-axis tick labels on the top
4+
==========================================
5+
6+
We can use :rc:`xtick.labeltop` (default False) and :rc:`xtick.top`
7+
(default False) and :rc:`xtick.labelbottom` (default True) and
8+
:rc:`xtick.bottom` (default True) to control where on the axes ticks and
9+
their labels appear.
10+
These properties can also be set in the ``.matplotlib/matplotlibrc``.
11+
12+
"""
13+
14+
15+
import matplotlib.pyplot as plt
16+
import numpy as np
17+
18+
19+
plt.rcParams['xtick.bottom'], plt.rcParams['xtick.labelbottom'] = False, False
20+
plt.rcParams['xtick.top'], plt.rcParams['xtick.labeltop'] = True, True
21+
22+
x = np.array([x for x in range(10)])
23+
24+
plt.plot(x)
25+
plt.title('xlabel top')
26+
plt.show()

lib/matplotlib/axes/_base.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,10 @@ def __init__(self, fig, rect,
549549
self.tick_params(
550550
top=rcParams['xtick.top'] and rcParams['xtick.minor.top'],
551551
bottom=rcParams['xtick.bottom'] and rcParams['xtick.minor.bottom'],
552+
labeltop=(rcParams['xtick.labeltop'] and
553+
rcParams['xtick.minor.top']),
554+
labelbottom=(rcParams['xtick.labelbottom'] and
555+
rcParams['xtick.minor.bottom']),
552556
left=rcParams['ytick.left'] and rcParams['ytick.minor.left'],
553557
right=rcParams['ytick.right'] and rcParams['ytick.minor.right'],
554558
labelleft=(rcParams['ytick.labelleft'] and
@@ -560,6 +564,10 @@ def __init__(self, fig, rect,
560564
self.tick_params(
561565
top=rcParams['xtick.top'] and rcParams['xtick.major.top'],
562566
bottom=rcParams['xtick.bottom'] and rcParams['xtick.major.bottom'],
567+
labeltop=(rcParams['xtick.labeltop'] and
568+
rcParams['xtick.major.top']),
569+
labelbottom=(rcParams['xtick.labelbottom'] and
570+
rcParams['xtick.major.bottom']),
563571
left=rcParams['ytick.left'] and rcParams['ytick.major.left'],
564572
right=rcParams['ytick.right'] and rcParams['ytick.major.right'],
565573
labelleft=(rcParams['ytick.labelleft'] and

lib/matplotlib/rcsetup.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1234,6 +1234,8 @@ def _validate_linestyle(ls):
12341234
# tick properties
12351235
'xtick.top': [False, validate_bool], # draw ticks on the top side
12361236
'xtick.bottom': [True, validate_bool], # draw ticks on the bottom side
1237+
'xtick.labeltop': [False, validate_bool], # draw label on the top
1238+
'xtick.labelbottom': [True, validate_bool], # draw label on the bottom
12371239
'xtick.major.size': [3.5, validate_float], # major xtick size in points
12381240
'xtick.minor.size': [2, validate_float], # minor xtick size in points
12391241
'xtick.major.width': [0.8, validate_float], # major xtick width in points

lib/matplotlib/tests/test_axes.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5238,6 +5238,22 @@ def test_axes_tick_params_ylabelside():
52385238
assert(ax.yaxis.minorTicks[0].label2On is True)
52395239

52405240

5241+
def test_axes_tick_params_xlabelside():
5242+
# Tests fix for issue 10267
5243+
ax = plt.subplot()
5244+
ax.tick_params(labeltop=True, labelbottom=False,
5245+
which='major')
5246+
ax.tick_params(labeltop=True, labelbottom=False,
5247+
which='minor')
5248+
# expects top True, bottom False
5249+
# label1On mapped to labelbottom
5250+
# label2On mapped to labeltop
5251+
assert(ax.xaxis.majorTicks[0].label1On is False)
5252+
assert(ax.xaxis.majorTicks[0].label2On is True)
5253+
assert(ax.xaxis.minorTicks[0].label1On is False)
5254+
assert(ax.xaxis.minorTicks[0].label2On is True)
5255+
5256+
52415257
def test_none_kwargs():
52425258
fig, ax = plt.subplots()
52435259
ln, = ax.plot(range(32), linestyle=None)

matplotlibrc.template

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,8 @@ backend : $TEMPLATE_BACKEND
357357
# see http://matplotlib.org/api/axis_api.html#matplotlib.axis.Tick
358358
#xtick.top : False # draw ticks on the top side
359359
#xtick.bottom : True # draw ticks on the bottom side
360+
#xtick.labeltop : False # draw label on the top
361+
#xtick.labelbottom : True # draw label on the bottom
360362
#xtick.major.size : 3.5 # major tick size in points
361363
#xtick.minor.size : 2 # minor tick size in points
362364
#xtick.major.width : 0.8 # major tick width in points

0 commit comments

Comments
 (0)