[docs]classAxis(AbstractMatWrap):def__init__(self,symmetric_source_centre:bool=False,**kwargs):""" Customizes the axis of the plotted figure. This object wraps the following Matplotlib method: - plt.axis: https://matplotlib.org/3.3.2/api/_as_gen/matplotlib.pyplot.axis.html Parameters ---------- symmetric_source_centre If `True`, the axis is symmetric around the centre of the plotted structure's coordinates. """super().__init__(**kwargs)self.symmetric_around_centre=symmetric_source_centre
[docs]defset(self,extent:List[float]=None,grid=None):""" Set the axis limits of the figure the grid is plotted on. Parameters ---------- extent The extent of the figure which set the axis-limits on the figure the grid is plotted, following the format [xmin, xmax, ymin, ymax]. """config_dict=self.config_dictextent_dict=config_dict.get("extent")ifextent_dictisnotNone:config_dict.pop("extent")ifself.symmetric_around_centre:ymin=np.min(grid[:,0])ymax=np.max(grid[:,0])xmin=np.min(grid[:,1])xmax=np.max(grid[:,1])x=np.max([np.abs(xmin),np.abs(xmax)])y=np.max([np.abs(ymin),np.abs(ymax)])extent_symmetric=[-x,x,-y,y]returnplt.axis(extent_symmetric,**config_dict)else:ifextent_dictisnotNone:returnplt.axis(extent_dict,**config_dict)returnplt.axis(extent,**config_dict)