Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add _val_or_rc-function#26168

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
greglucas merged 1 commit intomatplotlib:mainfromoscargus:valorrc
Jul 28, 2023
Merged

Add _val_or_rc-function#26168

greglucas merged 1 commit intomatplotlib:mainfromoscargus:valorrc
Jul 28, 2023

Conversation

oscargus
Copy link
Member

@oscargusoscargus commentedJun 22, 2023
edited
Loading

PR summary

iffooisNone:foo=mpl.rcParams["bar.foo"]

is a very common code pattern, so may be good to have a helper for it.Right now I only consideredlegend.py, but if this is an accepted idea there are many places where it can be used.

(And, yes, the reason I started with legend is that it was defined as a local function there.)

PR checklist

@oscargusoscargusforce-pushed thevalorrc branch 6 times, most recently from3cfb5fc tobc1658eCompareJune 22, 2023 16:58
Copy link
Member

@efiringefiring left a comment

Choose a reason for hiding this comment

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

Becauselegend.val_or_rc is formally public API, it probably should be removed after a standard deprecation cycle.

@oscargus
Copy link
MemberAuthor

I do not think that? I think it is an internal function in__init__ that is not accessible from the outside?

Copy link
Member

@efiringefiring left a comment

Choose a reason for hiding this comment

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

Oops! You are right, of course. All set.

@@ -603,11 +592,9 @@ def val_or_rc(val, rc_name):
'markeredgecolor': ['get_markeredgecolor', 'get_edgecolor'],
'mec': ['get_markeredgecolor', 'get_edgecolor'],
}
labelcolor = mpl._val_or_rc(labelcolor, 'legend.labelcolor')
Copy link
Contributor

Choose a reason for hiding this comment

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

You could nest anothermpl._val_or_rc(..., 'text.color') here and add a short comment about falling back totext.color iflegend.labelcolor is not present.

Comment on lines -450 to -451
def val_or_rc(val, rc_name):
return val if val is not None else mpl.rcParams[rc_name]
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you could possibly save a bunch of method gets below by setting this and reusing it?
val_or_rc = mpl._val_or_rc

Copy link
Member

Choose a reason for hiding this comment

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

I would like to warn on ineffective micro optimizations. Squeezing out nanoseconds does not make any measureable difference.

A function lookup cost 30ns (Python 3.11):

In [2]: %timeit mpl.rc_params_from_file29.7 ns ± 0.544 ns per loop

If we want to improve performance (and there's a lot to gain) that would need to be guided by profiling to identify the real pain points. In other cases, code structure/readability should be the primary guideline. - Not shure what is better here, but I tend to not do the additional logic indirection for saving a method to a new variable just to save method lookups.

@@ -1294,6 +1294,13 @@ def is_interactive():
return rcParams['interactive']


def _val_or_rc(val, rc_name):
"""
If *val* is None, return ``mpl.rcParams[rc_name]``, otherwise return val.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
If*val*isNone,return``mpl.rcParams[rc_name]``,otherwisereturnval.
Returnthevalueifpresent,otherwiselookup`rc_name`inthercParamsdictionary.

I'd suggest rewording this to be more human friendly since the code already explains what you had written.

Copy link
Member

Choose a reason for hiding this comment

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

Using None andmpl.rcParams[rc_name] is good, because that's precise and comprehensible. Optional, slightly less algorithmic variant.

Suggested change
If*val*isNone,return``mpl.rcParams[rc_name]``,otherwisereturnval.
Pass*val*throughunlessitisNone,inwhichcasereturn``mpl.rcParams[rc_name]``.

@@ -1294,6 +1294,13 @@ def is_interactive():
return rcParams['interactive']


def _val_or_rc(val, rc_name):
"""
If *val* is None, return ``mpl.rcParams[rc_name]``, otherwise return val.
Copy link
Member

Choose a reason for hiding this comment

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

Using None andmpl.rcParams[rc_name] is good, because that's precise and comprehensible. Optional, slightly less algorithmic variant.

Suggested change
If*val*isNone,return``mpl.rcParams[rc_name]``,otherwisereturnval.
Pass*val*throughunlessitisNone,inwhichcasereturn``mpl.rcParams[rc_name]``.

@greglucasgreglucas merged commit72888a1 intomatplotlib:mainJul 28, 2023
@QuLogicQuLogic added this to thev3.8.0 milestoneJul 28, 2023
QuLogic added a commit to QuLogic/matplotlib that referenced this pull requestAug 15, 2023
I think an accident during confict resolution ofmatplotlib#26168 incorrectlyoverwrote antialias settings for MathText.Also, re-arrange the tests to better catch this error.
QuLogic added a commit to QuLogic/matplotlib that referenced this pull requestAug 15, 2023
I think an accident during confict resolution ofmatplotlib#26168 incorrectlyoverwrote antialias settings for MathText. This puts the `_val_or_rc`call in the correct location.Also, re-arrange the tests to better catch this error.
@QuLogicQuLogic mentioned this pull requestAug 15, 2023
1 task
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@greglucasgreglucasgreglucas left review comments

@efiringefiringefiring approved these changes

@timhoffmtimhoffmtimhoffm approved these changes

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
v3.8.0
Development

Successfully merging this pull request may close these issues.

5 participants
@oscargus@efiring@timhoffm@greglucas@QuLogic

[8]ページ先頭

©2009-2025 Movatter.jp