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

Skip to content

Fix get_tick_params #27408

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
Closed

Conversation

StefRe
Copy link
Contributor

@StefRe StefRe commented Nov 30, 2023

PR summary

Fix get_tick_params

  • show values for x axis too
  • fix nonfunctional test
  • move axis tests from test_axes.py to test_axis.py
  • make note in get_tick_params docstring more precise
  • add GridOn to set_tick_params as it's always returned by get_tick_params, so it would be illogical if you couldn't set the paramter in the setter

Closes #27416.

PR checklist

@StefRe StefRe force-pushed the fix/get_tick_params branch from a89696f to 4a313a6 Compare December 1, 2023 09:25
@@ -3394,6 +3394,8 @@ def tick_params(self, axis='both', **kwargs):
Width of gridlines in points.
grid_linestyle : str
Any valid `.Line2D` line style spec.
gridOn : bool
Copy link
Member

Choose a reason for hiding this comment

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

I'm hesitant to further expand the use of camelcase variables. But I don't have an overview of its usage and whether grid_on would be a viable alternative. (No code editor access right now).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

grid_on would be available as an alternative. gridOn is only used internally in 4 files, no big deal to rename.

As an alternative one could translate gridOn to grid_on (which wouldn't, however, prevent anyone to use the then undocumented keyword in set_tick_params etc., as it's the case now).

If we don't want to have gridOn I'd opt for renaming it to grid_on. This wouldn't be an API change as gridOn is not documented.

@@ -0,0 +1,8 @@
Classes derived from Axis must implement get_tick_params
Copy link
Member

Choose a reason for hiding this comment

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

Wouldn't it be sufficient to implement the translation, either as a dict or as _translate_tick_params()?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, but _translate_tick_params is 18 LOC (not counting continuation lines) whereas get_tick_params is just 2.

Another thing is that set/get_tick_params currently doesn't work correctly for Axes3D (I'm going to open an issue about it) and I assume that it's easier fix with dedicated setters/getters (didn't look into it closely yet)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

On second thought, I think you're right and it's less convoluted to make the translation dicts axis-specific in the first place rather than modify a generic dict. I'll change it later this week, changing this PR to draft in the meantime.

- show values for x axis too
- fix nonfunctional test
- move axis tests from test_axes.py to test_axis.py
- make note in get_tick_params docstring more precise
- add GridOn to set_tick_params as it's always returned by
  get_tick_params, so it would be illogical if you couldn't
  set the paramter in the setter
@StefRe StefRe force-pushed the fix/get_tick_params branch from 4a313a6 to 538f2eb Compare December 1, 2023 13:15
@StefRe
Copy link
Contributor Author

StefRe commented Dec 1, 2023

This re-write of the Note in the get_tick_params documentation was caused by this example:

import matplotlib.pyplot as plt
import matplotlib as mpl

with mpl.rc_context({"ytick.labelcolor": "blue"}):
    fig, ax = plt.subplots()

for label in ax.get_xticklabels():
    label.set_fontweight("bold")

plt.xticks(ha="left")

fig.text(0.2, 0.7, "\n".join(["___x___"] + [f"{k}: {v}" for k, v in ax.xaxis.get_tick_params().items()]), va="top")
fig.text(0.6, 0.7, "\n".join(["___y___"] + [f"{k}: {v}" for k, v in ax.yaxis.get_tick_params().items()]), va="top")
plt.show()

get_params

This shows that

  • neither the label color nor the horizontal alignement are returned by get_tick_params although the were not set via the set_* methods on the individual tick objects
  • the bold fontweight set on the individual tick labels is also applied to new labels (the warning at get_major_ticks is correct as it says that there's a risk that the changes will not survive, it doesn't claim that these changes only apply to current labels.

@StefRe StefRe marked this pull request as ready for review December 1, 2023 13:59
@StefRe StefRe marked this pull request as draft December 4, 2023 07:11
.. note::
This method only returns the values of the parameters *bottom*, *top*,
*labelbottom*, *labeltop* or *left*, *right*, *labelleft*, *labelright*,
respectively, and *girdOn* as well as all additional parameters that were
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
respectively, and *girdOn* as well as all additional parameters that were
respectively, and *gridOn* as well as all additional parameters that were

@timhoffm
Copy link
Member

timhoffm commented Dec 9, 2024

I believe this has been superseeded by #29249.

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.

[Bug]: get_tick_params on xaxis shows wrong keywords
5 participants