pymatgen icon indicating copy to clipboard operation
pymatgen copied to clipboard

[Feature Request] Better compatibility between PDPlotter and matplotlib subplots

Open CompRhys opened this issue 5 years ago • 5 comments

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

CompRhys avatar Oct 17 '20 15:10 CompRhys

+1 . I agree this would be very useful.

rkingsbury avatar Oct 30 '20 16:10 rkingsbury

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)

utf avatar Oct 30 '20 17:10 utf

I don't have a problem with this. Can @utf implement and submit a PR?

shyuep avatar Oct 30 '20 19:10 shyuep

Yes I can implement this.

utf avatar Oct 30 '20 23:10 utf

@utf I submitted a similar PR that adds an ax kwarg to plot_brillouin. Could you have a look at #2039?

janosh avatar Feb 04 '21 12:02 janosh

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!

mattmcdermott avatar Jun 02 '23 23:06 mattmcdermott