-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2145 from SasView/2107-idf-plot-selection
All bugs fixed, doable changes made
- Loading branch information
Showing
18 changed files
with
1,182 additions
and
986 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
from __future__ import annotations | ||
|
||
from abc import ABCMeta, abstractmethod | ||
|
||
from typing import Optional, Union, List, Iterable, TYPE_CHECKING | ||
|
||
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas | ||
from matplotlib.figure import Figure | ||
|
||
from sas.sascalc.dataloader.data_info import Data1D | ||
|
||
|
||
if TYPE_CHECKING: | ||
from sas.qtgui.Perspectives.Corfunc.CorfuncPerspective import CorfuncWindow | ||
|
||
|
||
class CorfuncCanvasMeta(type(FigureCanvas), ABCMeta): | ||
""" Metaclass for both ABC and matplotlib figure | ||
This is needed to enable the mixin of CorfuncCanvas | ||
""" | ||
|
||
|
||
class CorfuncCanvas(FigureCanvas, metaclass=CorfuncCanvasMeta): | ||
""" Base class for the canvases in corfunc""" | ||
|
||
def __init__(self, parent: CorfuncWindow, width=5, height=4, dpi=100): | ||
self.parent = parent | ||
self.fig = Figure(figsize=(width, height), dpi=dpi) | ||
self.axes = self.fig.add_subplot(111) | ||
|
||
FigureCanvas.__init__(self, self.fig) | ||
|
||
self._data: Optional[List[Data1D]] = None | ||
|
||
def clear(self): | ||
""" Remove data from plots""" | ||
self._data = None | ||
|
||
@abstractmethod | ||
def draw_data(self): | ||
pass | ||
|
||
@property | ||
def data(self) -> Optional[List[Data1D]]: | ||
""" The data currently shown by the plots """ | ||
return self._data | ||
|
||
@data.setter | ||
def data(self, target_data: Optional[Union[Data1D, Iterable[Data1D]]]): | ||
# I'm not 100% sure this is good practice, but it will make things cleaner in the short term | ||
if target_data is None: | ||
self._data = None | ||
elif isinstance(target_data, Data1D): | ||
self._data = [target_data] | ||
else: | ||
self._data = list(target_data) | ||
|
||
self.draw_data() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
|
||
from sas.qtgui.Perspectives.Corfunc.CorfuncCanvas import CorfuncCanvas | ||
|
||
|
||
class IDFCanvas(CorfuncCanvas): | ||
""" Canvas for displaying real space representation""" | ||
|
||
def draw_data(self): | ||
""" | ||
This function draws the real space data onto the plot | ||
The 1d correlation function in self.data, the 3d correlation function | ||
in self.data3, and the interface distribution function in self.data_idf | ||
are all draw in on the plot in linear cooredinates.""" | ||
|
||
|
||
self.fig.clf() | ||
|
||
self.axes = self.fig.add_subplot(111) | ||
self.axes.set_xscale("linear") | ||
self.axes.set_yscale("linear") | ||
self.axes.set_xlabel("Z [$\AA$]") | ||
self.axes.set_ylabel("IDF") | ||
self.axes.set_title("Interface Distribution Function") | ||
self.fig.tight_layout() | ||
|
||
if self.data is not None and len(self.data) > 0: | ||
self.axes.plot(self.data[0].x, self.data[0].y) | ||
self.axes.set_xlim(0, max(self.data[0].x) / 4) | ||
|
||
self.draw() | ||
|
Oops, something went wrong.