# -*- coding: utf-8 -*-# plotting.pyimportmatplotlibimportmatplotlib.pyplotaspltfrom.readdataimportreadPDHtry:# increase the limit for the warning to pop upmatplotlib.rcParams["figure.max_open_warning"]=50exceptTypeError:# ignore the error with Sphinxpass
[docs]definitFigure(fig,width=80,aspectRatio=4.0/3.0,quiet=False):mmInch=25.4fig.set_size_inches(width/mmInch,width/aspectRatio/mmInch)w,h=fig.get_size_inches()ifnotquiet:print("initFigure() with ({w:.1f}x{h:.1f}) mm".format(w=w*mmInch,h=h*mmInch))returnfig
[docs]defcreateFigure(width=80,aspectRatio=4.0/3.0,quiet=False,**kwargs):"""output figure width in mm"""fig=plt.figure(# tight_layout=dict(pad=0.05),**kwargs)initFigure(fig,width,aspectRatio,quiet)returnfig
[docs]defplotPDH(filename,label,**kwargs):"""Plot a given .PDH file with the given label (shown in legend) using pandas and readPDH()."""q_range=kwargs.pop("q_range",None)print_filename=kwargs.pop("print_filename",True)# default value from readdata()df,_=readPDH(filename,q_range=q_range,print_filename=print_filename)df["e"]=df["e"].clip(lower=0)defaults=dict(yerr="e",logx=True,logy=True,label=label,grid=True,figsize=(10,5),xlabel=r"$q$ (nm$^{{-1}}$)",ylabel="Intensity",ecolor="lightgray",)fork,vindefaults.items():ifknotinkwargs:kwargs[k]=vdf.plot("q","I",**kwargs)