Improve matplotlib interface
Created by: thuiop
This PR does two different things, which are both related to interfacing with matplotlib, but technically independent.
-
Modifying the
Plot
object to use composition instead of inheritance, i.e. containing aFigure
instead of being aFigure
. The motivation for this is to improve interaction with matplotlib. In particular, it allows the use to pass a figure on which the plot will be made; this enables for instance the use of subfigures, and overall gives the use more control on the underlying objects. I have done this in the minimal amount of code, but it could benefit from a more thorough rewrite. The drawback is that if someone tries to manually modify one of the attributes of the figure (which should not be common behavior), they have to access it through<Plot object>.fig
beforehand. -
Remove the monkeypatching of the
Axes
, switching to defining a new projection. This was already mentioned in #1187, and has always seemed crazy to me. This PR keeps the current behavior when using thePlot
class (including through.plot
method); it will not however keep the current behavior when callingplt.plot
or equivalent; it requires the user to manually specify the projection (withprojection="gwpy"
orsubplot_kw={"projection":"gwpy"}
, depending on the case). I am happy to document this if needed; there could also be a utility function for doing the monkeypatching anyway and recovering the old behaviour, in a way where it is not forced on the user.
I am happy to discuss any of these changes; I have not tested them extensively, meaning that there should definitely be additional checks before merging (I do not know if there is a CI or anything).