Skip to content

Add labels parameter to set_ticks()#20047

Merged
tacaswell merged 1 commit intomatplotlib:masterfrom
timhoffm:set_ticks-labels
May 14, 2021
Merged

Add labels parameter to set_ticks()#20047
tacaswell merged 1 commit intomatplotlib:masterfrom
timhoffm:set_ticks-labels

Conversation

@timhoffm
Copy link
Copy Markdown
Member

@timhoffm timhoffm commented Apr 22, 2021

PR Summary

As proposed in #18848 (comment) and discussed on today's dev call.

Closes #18848, #19016.

kwargs: I've added kwargs for text properties. While this makes the function do a lot (borderline of too much), it is necessary if we want a full replacement of set_ticklabels(labels, **text_properties).
One can argue that this is actually too much, in which case we'd have to advertise

# Replace
set_ticks(locs)
set_ticklabels(labels, **text_properties)
# by
set_ticks(locs, labels)
tick_params(**text_properties)

Return value: set_ticks() has an undocumented return value (list of the Tick instances). While plt.xticks() returns a tuple (locs, labels) (list of Ticks and list of Texts), I don't want to do this here. First, I don't think the setter should return anything at all (but that's how it is for now and deprecating that is probably not worth it). Second, since labels are optional, I'm not even sure if we would want to give the texts only if labels is not None.

@timhoffm timhoffm added this to the v3.5.0 milestone Apr 22, 2021
Copy link
Copy Markdown
Member

@jklymak jklymak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good. Prob needs API note, or what's new...

@timhoffm timhoffm force-pushed the set_ticks-labels branch 2 times, most recently from 5c3983f to ddee963 Compare April 24, 2021 21:16
@jklymak jklymak requested a review from anntzer May 3, 2021 14:30
Comment thread lib/matplotlib/axes/_secondary_axes.py Outdated
Comment thread lib/matplotlib/axis.py
Copy link
Copy Markdown
Contributor

@anntzer anntzer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

approving modulo addressing (or rejecting) the two comments above.

Comment thread lib/matplotlib/axis.py Outdated
@timhoffm timhoffm force-pushed the set_ticks-labels branch from 5f54d29 to ed54043 Compare May 5, 2021 20:06
@jklymak
Copy link
Copy Markdown
Member

jklymak commented May 10, 2021

I think the doc error is real:

/home/circleci/project/lib/matplotlib/axis.py:docstring of matplotlib.axis.Axis.set_ticklabels:10: WARNING: more than one target found for cross-reference 'FixedLocator': mpl_toolkits.axisartist.grid_finder.FixedLocator, matplotlib.ticker.FixedLocator

@jklymak jklymak marked this pull request as draft May 10, 2021 22:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Setting xticklabels causes warning related to FixedFormatter

5 participants