dipc-cc / hubbard

Python tools for mean-field Hubbard models
https://dipc-cc.github.io/hubbard/
GNU Lesser General Public License v3.0
21 stars 8 forks source link

enh: trying to make plots more customizable #70

Closed zerothi closed 3 years ago

zerothi commented 3 years ago

This partially fixes something for #69

fig = plt.figure()
for U in ...:
    ...
    p = plot.DOS(H, egrid, eta=1e-2, spin=[0], figure=fig)
    ...
p.savefig("all.png")

should hopefully work.

However, I think the problem is they way the DOS(Plot) class, and all the others are used. Basically all they do is in their __init__ routine, making them extremely static.

To me the DOS(Plot) class could just as well be this:

def DOSPlot(..., **kwargs):
    plot = Plot(**kwargs)
    if np.any(sites):
        DOS = HubbardHamiltonian.PDOS(egrid, eta=eta, spin=spin)
        offset = 0.*np.average(DOS[sites[0]])
        for i, s in enumerate(sites):
            plot.axes.plot(egrid, DOS[s]+offset*i, label='site %i'%i)
        plot.legend()
    else:
        DOS = HubbardHamiltonian.DOS(egrid, eta=eta, spin=spin)
        plot.axes.plot(egrid, DOS, label='TDOS')

    plot.set_xlabel(r'E-E$_\mathrm{midgap}$ [eV]')
    plot.set_ylabel(r'DOS [1/eV]')
    return plot

Basically all your Plot sub-classes only uses the Plot class to hold the axes and figure, nothing more.

This is a bit counter-intuitive of what a class should do, I think. I think this is what is causing the confusing in #69?

I don't know how you else want this to be done. One could for instance do a HubbardPlot that does something like this:

chrg = ChargeDifference(realspace=True)
sppol = SpinPolarization(realspace=True)
plot = HubbardPlot([chrg, sppol])
# now plot has 2 axes in one plot utility. To add a plot do
chrg.plot(HH, ext_geom, spin=0)
sppol(HH, ext_geom)
plot.savefig(...)

or something (note, this isn't carefully thought through, and perhaps not the best way).

But this would force the plotting work to be done in a separate plot method that does the heavy lifting and allows re-use of the same axes.

tfrederiksen commented 3 years ago

Thanks Nick, looks good to me!

sofiasanz commented 3 years ago

Hi Nick! Thank you for the pull request and comments! Looks good to me too :-). I agree that it would probably be better if we eliminate the classes and build just functions instead... I will give it a thought!