Skip to content

edited 2D Object to add labelfont alias so that tick_params can direc… #19110

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/matplotlib/axis.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ def _apply_params(self, **kw):
self.label2.set(rotation=self._labelrotation[1])

label_kw = {k[5:]: v for k, v in kw.items()
if k in ['labelsize', 'labelcolor']}
if k in ['labelsize', 'labelcolor', 'labelfont']}
self.label1.set(**label_kw)
self.label2.set(**label_kw)

Expand Down Expand Up @@ -863,7 +863,7 @@ def set_tick_params(self, which='major', reset=False, **kw):
def _translate_tick_kw(kw):
# The following lists may be moved to a more accessible location.
kwkeys = ['size', 'width', 'color', 'tickdir', 'pad',
'labelsize', 'labelcolor', 'zorder', 'gridOn',
'labelsize', 'labelcolor', 'labelfont', 'zorder', 'gridOn',
'tick1On', 'tick2On', 'label1On', 'label2On',
'length', 'direction', 'left', 'bottom', 'right', 'top',
'labelleft', 'labelbottom', 'labelright', 'labeltop',
Expand Down
15 changes: 15 additions & 0 deletions lib/matplotlib/lines.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ def _slice_or_none(in_v, slc):
"markerfacecolor": ["mfc"],
"markerfacecoloralt": ["mfcalt"],
"markersize": ["ms"],
"labelfont": ["lf"]
})
class Line2D(Artist):
"""
Expand Down Expand Up @@ -293,6 +294,7 @@ def __init__(self, xdata, ydata,
pickradius=5,
drawstyle=None,
markevery=None,
font=None,
**kwargs
):
"""
Expand Down Expand Up @@ -1027,6 +1029,12 @@ def get_xydata(self):
self.recache()
return self._xy

def get_labelfont(self):
"""
Return the label font as string
"""
return self._labelfont

def set_antialiased(self, b):
"""
Set whether to use antialiased rendering.
Expand Down Expand Up @@ -1264,6 +1272,13 @@ def set_ydata(self, y):
self._invalidy = True
self.stale = True

def set_labelfont(self, labelfont):
"""
"""
if self._labelfont != labelfont:
self.stale = True
self._labelfont = labelfont

def set_dashes(self, seq):
"""
Set the dash sequence.
Expand Down
9 changes: 9 additions & 0 deletions lib/matplotlib/tests/test_lines.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,3 +264,12 @@ def test_marker_as_markerstyle():
def test_odd_dashes(fig_test, fig_ref):
fig_test.add_subplot().plot([1, 2], dashes=[1, 2, 3])
fig_ref.add_subplot().plot([1, 2], dashes=[1, 2, 3, 1, 2, 3])


def test_labelfont():
# notice tick_params has labelfont
plt.plot(['ai', 'l', 'c3'], [4, 5, 6])
plt.ylabel('A Original set Y label', fontname='monospace', fontsize=20)
plt.tick_params(color='r', labelcolor='g', labelsize=10,
labelfont='monospace')
plt.title('Testing testing 1234')