-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
Functions that plot should take an ax
argument
#15416
Comments
@rohitgr7 What do you think, should we add this? @davidgilbertson are you interested in contributing this? |
I've got a full schedule at the moment, sorry. Actually after I logged this I remembered that I've monkey-patched |
@awaelchli I am new to the lightning codebase, can I work on this issue? Just to confirm, the solution would be to change this line: to this(as suggested by @davidgilbertson): if ax is None:
fig, ax = plt.subplots()
else:
fig, ax = ax.figure, ax |
Oh, I just realised my initial snippet got the wrong order, good catch @bipinKrishnan . Actually it can just be: if ax is None:
fig, ax = plt.subplots()
else:
fig = ax.figure And in case you didn't know, this parameter can be typed as |
Yes @bipinKrishnan, feel free to open a PR and we will be very happy to review it! |
🚀 Feature
Currently, functions like
trainer.tuner.lr_find().plot()
will generate a new Matplotlib figure and axes. I believe best practice is for such functions to accept anax
so that the user may pass in their own ax.Motivation
lr_find().plot()
(not super compelling in the case of LR finder)figure
andaxes
each time.Pitch
Just add
ax
as an optional arg to any function that plots, which I believe is just the LR finder ATM.Since the function returns a figure, you can pluck that from the ax if provided, so it wouldn't be a breaking change. Something like:
Alternatives
Can't think of any.
Additional context
There's a page somewhere in the Matplotlib docs that describes general best practices for writing functions that produce charts but I can't find it!
cc @Borda @akihironitta @rohitgr7
The text was updated successfully, but these errors were encountered: