pymatgen
pymatgen copied to clipboard
[Feature Request] Better compatibility between PDPlotter and matplotlib subplots
Is your feature request related to a problem? Please describe.
It would be nice to be able to pass matplotlib axes objects to PDPlotter when using the matplotlib backend such that they can be easily incorporated into subplots.
Describe the solution you'd like
a kwarg called axes in PDPlotter that gives the axes to plot the phase diagram on in a subplots
Additional context
there is a kwarg called plt in PDPlotter that may have similar functionality but I haven't managed to use it for this use case successfully
+1 . I agree this would be very useful.
I think it might be nicer to just change the plt argument to ax as I feel that is more natural to work with.
That said, to use the existing plt argument with subplots often the only thing you have to do is set the current axis to the axis you want to plot to. I.e.,
import matplotlib.pyplot as plt
fig, (ax1, ax2) = plt.subplots(2, 1)
# ... generate PDPlotter object...
plt.sca(ax2) # set the current axis to ax2
plotter.get_plot(..., plt=plt)
I don't have a problem with this. Can @utf implement and submit a PR?
Yes I can implement this.
@utf I submitted a similar PR that adds an ax kwarg to plot_brillouin. Could you have a look at #2039?
I just updated PDPlotter in https://github.com/materialsproject/pymatgen/pull/3032 but this is still not addressed. I don't feel particularly good about touching some of the matplotlib code, so if anyone is interested in improving it sometime, please feel free!