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

Skip to content

Commit f763230

Browse files
committed
Use named args for xticks, yticks in pyplot
1 parent 4536165 commit f763230

File tree

1 file changed

+21
-26
lines changed

1 file changed

+21
-26
lines changed

lib/matplotlib/pyplot.py

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1552,19 +1552,19 @@ def yscale(scale, **kwargs):
15521552
gca().set_yscale(scale, **kwargs)
15531553

15541554

1555-
def xticks(*args, **kwargs):
1555+
def xticks(ticks=None, labels=None, **kwargs):
15561556
"""
15571557
Get or set the current tick locations and labels of the x-axis.
15581558
15591559
Call signatures::
15601560
15611561
locs, labels = xticks() # Get locations and labels
15621562
1563-
xticks(locs, [labels], **kwargs) # Set locations and labels
1563+
xticks(ticks, [labels], **kwargs) # Set locations and labels
15641564
15651565
Parameters
15661566
----------
1567-
locs : array_like
1567+
ticks : array_like
15681568
A list of positions at which ticks should be placed. You can pass an
15691569
empty list to disable xticks.
15701570
@@ -1614,36 +1614,35 @@ def xticks(*args, **kwargs):
16141614
"""
16151615
ax = gca()
16161616

1617-
if len(args)==0:
1617+
if ticks is None and labels is None:
16181618
locs = ax.get_xticks()
16191619
labels = ax.get_xticklabels()
1620-
elif len(args)==1:
1621-
locs = ax.set_xticks(args[0])
1620+
elif labels is None:
1621+
locs = ax.set_xticks(ticks)
16221622
labels = ax.get_xticklabels()
1623-
elif len(args)==2:
1624-
locs = ax.set_xticks(args[0])
1625-
labels = ax.set_xticklabels(args[1], **kwargs)
1626-
else: raise TypeError('Illegal number of arguments to xticks')
1627-
if len(kwargs):
1623+
else:
1624+
locs = ax.set_xticks(ticks)
1625+
labels = ax.set_xticklabels(labels, **kwargs)
1626+
if kwargs:
16281627
for l in labels:
16291628
l.update(kwargs)
16301629

16311630
return locs, silent_list('Text xticklabel', labels)
16321631

16331632

1634-
def yticks(*args, **kwargs):
1633+
def yticks(ticks=None, labels=None, **kwargs):
16351634
"""
16361635
Get or set the current tick locations and labels of the y-axis.
16371636
16381637
Call signatures::
16391638
16401639
locs, labels = yticks() # Get locations and labels
16411640
1642-
yticks(locs, [labels], **kwargs) # Set locations and labels
1641+
yticks(ticks, [labels], **kwargs) # Set locations and labels
16431642
16441643
Parameters
16451644
----------
1646-
locs : array_like
1645+
ticks : array_like
16471646
A list of positions at which ticks should be placed. You can pass an
16481647
empty list to disable yticks.
16491648
@@ -1693,24 +1692,20 @@ def yticks(*args, **kwargs):
16931692
"""
16941693
ax = gca()
16951694

1696-
if len(args)==0:
1695+
if ticks is None and labels is None:
16971696
locs = ax.get_yticks()
16981697
labels = ax.get_yticklabels()
1699-
elif len(args)==1:
1700-
locs = ax.set_yticks(args[0])
1698+
elif labels is None:
1699+
locs = ax.set_yticks(ticks)
17011700
labels = ax.get_yticklabels()
1702-
elif len(args)==2:
1703-
locs = ax.set_yticks(args[0])
1704-
labels = ax.set_yticklabels(args[1], **kwargs)
1705-
else: raise TypeError('Illegal number of arguments to yticks')
1706-
if len(kwargs):
1701+
else:
1702+
locs = ax.set_yticks(ticks)
1703+
labels = ax.set_yticklabels(labels, **kwargs)
1704+
if kwargs:
17071705
for l in labels:
17081706
l.update(kwargs)
17091707

1710-
1711-
return ( locs,
1712-
silent_list('Text yticklabel', labels)
1713-
)
1708+
return locs, silent_list('Text yticklabel', labels)
17141709

17151710

17161711
def minorticks_on():

0 commit comments

Comments
 (0)