Skip to content

Fix ax.set_xticklabels(fontproperties=fp) #18838

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

Closed
wants to merge 1 commit into from

Conversation

shevawen
Copy link

PR Summary

Only one label is changed on an axis when set fontproperties using set_xticklabels().

from matplotlib import pyplot as plt
from matplotlib.font_manager import FontProperties

fig = plt.figure()
ax = plt.gca()
ax.set_xticklabels(["label1", "label2"], fontproperties=FontProperties(weight="bold"))

plt.show()

PR Checklist

  • Has pytest style unit tests (and pytest passes).
  • Is Flake 8 compliant (run flake8 on changed files to check).
  • New features are documented, with examples if plot related.
  • Documentation is sphinx and numpydoc compliant (the docs should build without error).
  • Conforms to Matplotlib style conventions (install flake8-docstrings and run flake8 --docstring-convention=all).
  • New features have an entry in doc/users/next_whats_new/ (follow instructions in README.rst there).
  • API changes documented in doc/api/next_api_changes/ (follow instructions in README.rst there).

@jklymak
Copy link
Member

jklymak commented Oct 29, 2020

Can this get a new test that demonstrates that what used to break but is now working? I agree the code above appears broken? What is happening here - are the kwagrs being stripped as they are used?

@tacaswell
Copy link
Member

Thanks for this @shevawen The core of this bug is that in Text.update we mutate the user supplied dictionary (!!), I'm going to open a new PR to address the core of the problem.

@tacaswell tacaswell added this to the v3.3.3 milestone Oct 29, 2020
tacaswell added a commit to tacaswell/matplotlib that referenced this pull request Oct 29, 2020
We take in a dictionary (called kwargs rather than collecting kwargs)
which we mutate in the method.  We pop bbox and fontproperties keys
out of the user supplied dictionary (to make sure the precedence and
default behaviors are correct) which is propagated back out to user
code.

This makes an internal copy of the dictionary before we mutate it.

closes matplotlib#18838
Copy link
Member

@tacaswell tacaswell left a comment

Choose a reason for hiding this comment

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

flagging an request changes as I think #18839 is a more general fix to the same problem.

tacaswell added a commit to tacaswell/matplotlib that referenced this pull request Oct 29, 2020
We take in a dictionary (called kwargs rather than collecting kwargs)
which we mutate in the method.  We pop bbox and fontproperties keys
out of the user supplied dictionary (to make sure the precedence and
default behaviors are correct) which is propagated back out to user
code.

This makes an internal copy of the dictionary before we mutate it.

closes matplotlib#18838
@shevawen
Copy link
Author

flagging an request changes as I think #18839 is a more general fix to the same problem.

I think that is the final way to fix the problem.

@shevawen shevawen closed this Oct 30, 2020
@shevawen shevawen deleted the fix_set_xticklabels branch October 30, 2020 01:59
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.

3 participants