-
Notifications
You must be signed in to change notification settings - Fork 287
Update plot_modifications.py #5116
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
base: main
Are you sure you want to change the base?
Conversation
Hi! Welcome, and thanks for opening this pull request. We have some guidelines for new pull requests, and soon you'll hear back about the results of our tests and continuous integration checks. Thank you for your contribution! |
@tiapac did you mean to close this one? |
Yes, I modified through the online editor, so I was worried that the indentation was not correct. I also wanted to add a bit of context to the changes for future references. I tested it locally and it's ok, so I'll reopen it. |
pre-commit.ci autofix |
for more information, see https://pre-commit.ci
@tiapac I just triggered the pre-commit bot to fix the failing style check: locally you'll want to run |
The type check test gives an error here:
I think it is because if
|
yup! that should fix it. |
Changed ``plot_args`` to ``self.plot_args`` in the if/in check
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apologies for the delay in getting back to this. But the change looks good to me. It'd great to add a test though -- I'm going to write one real quick right now, do you mind if I push to your branch?
I just went ahead and did it, hope you don't mind :) you'll want to git pull again to get the new changes locally. Also just FYI, in the future it's best practice to submit pull requests from new branches and keep your |
oh, oops, forgot to add the new test file to the nose config. i'll fix that! |
Sure, I don't mind. Thanks for the help.
Thanks for the suggestion! :) |
self.plot_args = {**(plot_args or {})} | ||
if "colors" not in self.plot_args and "cmap" not in self.plot_args: | ||
self.plot_args["colors"] = "black" | ||
if "linestyles" not in self.plot_args: | ||
self.plot_args["linestyles"] = "solid" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how about this instead ?
self.plot_args = {**(plot_args or {})} | |
if "colors" not in self.plot_args and "cmap" not in self.plot_args: | |
self.plot_args["colors"] = "black" | |
if "linestyles" not in self.plot_args: | |
self.plot_args["linestyles"] = "solid" | |
self.plot_args = { | |
"linestyles": "solid", | |
**(plot_args or {}) | |
} | |
if "cmap" not in plot_args: | |
self.plot_args.set_default("colors", "black") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for coming back at it after a while, I'm going thorugh particularly busy weeks. The change works for me, looks cleaner with set_default.
Should we do the same for linestyles
?
self.plot_args = {**(plot_args or {})} | |
if "colors" not in self.plot_args and "cmap" not in self.plot_args: | |
self.plot_args["colors"] = "black" | |
if "linestyles" not in self.plot_args: | |
self.plot_args["linestyles"] = "solid" | |
self.plot_args = {**(plot_args or {}) | |
} | |
if "cmap" not in plot_args: | |
self.plot_args.set_default("colors", "black") | |
if "linestyles" not in plot_args: | |
self.plot_args.set_default("linestyles", "solid") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No. linestyles
is already being overriden correctly, let's keep the more verbose style only for when it's really needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that the if "linestyles" not in plot_args
condition is entirely redundant in your suggestion, too.
to echo Chris' comment on branching: |
@neutrinoceros Thanks for the suggested reading, very helpful! |
I noticed that making a contour plot does not allow me to use the kwarg "cmap" in the 'plot_args' dictionary.
If I add the "cmap" key work to 'plot_args' as in
returns
The cause is that by default yt partially generate said dictionary ( in yt/visualization/plot_modifications.py, line 931 ) and then add the user supplied options:
This generate a conflict in matplotlib because when "colors" is supplied, "cmap" is not accepted.
A solution might be to only add the default values if they are not supplied by the user in
plot_args
, as also suggested by @chrishavlin .This is the content of the pull request.