uafgeotools / rtm

A Python package for locating infrasound sources using reverse time migration
https://uaf-rtm.readthedocs.io/
MIT License
38 stars 13 forks source link

return figure handle for plot_time_slice? #72

Closed davidfee5 closed 2 years ago

davidfee5 commented 2 years ago

I often find myself wanting to modify the default plot in plot_time_slice. I think it would be helpful to return the figure handle h in addition to the fig instance. It would be easy to add here: https://github.com/uafgeotools/rtm/blob/0d100ea142fa4200579a21da8169eaeec42b7b20/rtm/plotting.py#L269 but we would have to modify the example and some other codes probably. What do you think?

liamtoney commented 2 years ago

I think it would be helpful to return the figure handle h in addition to the fig instance.

I don't think I understand what you mean. What is a figure handle? Usually, to modify the output figure I'll just do, e.g.,

fig = plot_time_slice(...)
fig.axes[0].set_title(...)

etc.

davidfee5 commented 2 years ago

It is for modifying things that have already been plotted, such as the grid center. h is defined here: https://github.com/uafgeotools/rtm/blob/0d100ea142fa4200579a21da8169eaeec42b7b20/rtm/plotting.py#L198

and say I want to remove the grid center I'd want to access the handle h to do something like

h[0].remove()
h=h[1:]
liamtoney commented 2 years ago

Ah, I see. Yeah, we could return them, or you could use

fig = plot_time_slice(...)
h, _ = fig.axes[0].get_legend_handles_labels()

per get_legend_handles_labels() docs...

If the issue was that we can't access the handles, then the above is the solution and no modification is required. If the above is too hacky, and we're modifying things frequently, then I suppose we could refactor. I've just never personally had to do that!

davidfee5 commented 2 years ago

Aha! That works just fine. I looked around for a way to do that but couldn't figure it out for some reason. I think this will work and will close this issue. Thanks!