8000 Doc: highlight rcparams by ImportanceOfBeingErnest · Pull Request #15115 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Doc: highlight rcparams #15115

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

Merged

Conversation

ImportanceOfBeingErnest
Copy link
Member

PR Summary

Many of the function parameters default to None, in which case the value from an rc parameter is taken. The custom :rc: role allows to link to the template, but it's always been bothering me that you then have to scroll through that complete file to locate the parameter you want to know the default of.

This PR will highlight the parameter in question, such that it is easier to locate.

I.e. if you click on a parameter, eg.

image

you will now be directed to

/tutorials/introductory/customizing.html?highlight=legend.numpoints#a-sample-matplotlibrc-file

and then scrolling down the file, the parameter in question is highlighted like this:

image

PR Checklist

  • Has Pytest style unit tests
  • Code is Flake 8 compliant
  • New features are documented, with examples if plot related
  • Documentation is sphinx and numpydoc compliant
  • Added an entry to doc/users/next_whats_new/ if major new feature (follow instructions in README.rst there)
  • Documented in doc/api/api_changes.rst if API changed in a backward-incompatible way

@anntzer
Copy link
Contributor
anntzer commented Aug 23, 2019

flake8 failure is real, but other than that I do like the idea a lot.

@ImportanceOfBeingErnest
Copy link
Member Author

Actually, we could in addition directly include the default value in the rc role output:

image

What do you think?


param = rcParamsDefault.get(text)
if isinstance(param, str):
txt = f' : "{param}"'
Copy link
Contributor
@anntzer anntzer Aug 24, 2019

Choose a reason for hiding this comment

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

  1. no space before the colon? (or use "=")
  2. you can probably get away with {param!r} (aka {repr(param)}) which will give you the quotes for strings, instead of having to special case them.

@jklymak
Copy link
Member
jklymak commented Aug 24, 2019

The default may be a bit confusing? Is it obvious this is marplotlibs default? Not sure how to improve it though. Maybe brackets? Otherwise this seems great

@tacaswell tacaswell added this to the v3.2.0 milestone Aug 24, 2019
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.

This is brilliant!

I think this is ok to go in as is (as this is a major improvement!), but holding off merging if people want to fine-tune the exact formatting.

@tacaswell tacaswell modified the milestones: v3.2.0, v3.1-doc Aug 24, 2019
@tacaswell
Copy link
Member

Also, who ever merges this, please make sure I notice and re-build the 3.1.x docs.

@ImportanceOfBeingErnest
Copy link
Member Author

Options:

  • rcParams["axes.facecolor"] = "white"
  • rcParams["axes.facecolor"] : "white"
  • rcParams["axes.facecolor"]: "white"
  • rcParams["axes.facecolor"] ("white")
  • axes.facecolor: "white"
  • rcParams (axes.facecolor: "white")

Personally I don't really care too much, so if anyone has a good argument for or against one or several of those...

@anntzer
Copy link
Contributor
anntzer commented Aug 25, 2019

preference for "=" and ":" (without space before the colon), but anything is an improvement!

@ImportanceOfBeingErnest
Copy link
Member Author

Ok, went for "=" now, because that actually gives valid python code:

image

@timhoffm
Copy link
Member

This is great! 🎉.

Ok, went for "=" now, because that actually gives valid python code:

If I was nitpicky, that is a bit misleading. Assignment is not what we want to express; and thinking of this, I have a tiny doubt if people would misunderstand the "=".

Anyway, "=" is what we are recommending in the documentation guide, so it's fine. But the documentation guide should be updated to reflect the new behavior.

@jklymak
Copy link
Member
jklymak commented Aug 25, 2019

I would do something like (def.=xx) but maybe that’s too wordy

@timhoffm
Copy link
Member

(def.=xx) is still too ambiguous. def is more commonly the abbreviation of definition rather than default; and this still has the slight equal sign issue.

If we want to be really clear (default: xx) would be the way to go. Thinking of it, I have a slight preference for that, but I'm fine to leave the current version as well.

@jklymak
Copy link
Member
jklymak commented Aug 25, 2019

Dflt?

@timhoffm
Copy link
Member

Hmmm, no. Readability counts also for the docs. We wouldn't use dflt as variable name. Why start saving letters in the documentation, which is allowed to be textually more verbose anyway.?

@tacaswell
Copy link
Member

I like = as the line can now be copy-pasted to set the rcparam back to it's default.

@tacaswell tacaswell merged commit bedb4d9 into matplotlib:master Aug 26, 2019
meeseeksmachine pushed a commit to meeseeksmachine/matplotlib that referenced this pull request Aug 26, 2019
meeseeksmachine pushed a commit to meeseeksmachine/matplotlib that referenced this pull request Aug 26, 2019
tacaswell added a commit that referenced this pull request Aug 26, 2019
…115-on-v3.1.x

Backport PR #15115 on branch v3.1.x (Doc: highlight rcparams)
tacaswell added a commit that referenced this pull request Aug 26, 2019
…115-on-v3.1.1-doc

Backport PR #15115 on branch v3.1.1-doc (Doc: highlight rcparams)
@QuLogic
Copy link
Member
QuLogic commented Sep 9, 2019

Looking at the changes in #15230, the fact that = produces valid code seems to be a point against using it. Many sentences appear to use constructs like:

Use :rc:`something` to do something.

or

You can do something by setting :rc:`something`.

These will become:

Use rcParams[something] = "default" to do something.

or

You can do something by setting rcParams[something] = "default".

This implies that you should set the rcParam to its default value, but those sentence often just mean set it to anything.

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.

6 participants
0