[docs]classPlotInfo:plot_type:PLOT_TYPEmetric_id_x:intmetric_id_y:intscatter_plot_mode:SCATTER_PLOT_MODEtitle:strdef__init__(self,plot_type:PLOT_TYPE,metric_id_x:int,metric_id_y:int=-1,scatter_plot_mode:SCATTER_PLOT_MODE=SCATTER_PLOT_MODE.MARKERS,title:str="",):""" This object takes Simularium trajectory data and calculates metrics that can be plotted in the Simularium Viewer. Parameters ---------- plot_type: PLOT_TYPE What type of plot to make. metric_id_x : int ID for the metric to plot on the x-axis. metric_id_y : int (Optional) ID for the metric to plot on the y-axis. If not provided, the plot will be a histogram. scatter_plot_mode : SCATTER_PLOT_MODE (Optional) If the plot is a scatterplot, how to draw the points. Default: SCATTER_PLOT_MODE.MARKERS (draw as dots) title: str Title to display above plot. """self.plot_type=plot_typeself.metric_id_x=metric_id_xself.metric_id_y=metric_id_yself.scatter_plot_mode=scatter_plot_modeself.title=titleself.display_title=title
[docs]defvalidate_plot_configuration(self,metric_info_x:MetricInfo,metric_info_y:Optional[MetricInfo])->None:""" Check that the plot type and number of metrics are consistent, and that the X and Y metrics are of the same type if this is not a histogram. Parameters ---------- metric_info_x: MetricInfo Info about the metric to plot on the x-axis. metric_info_y: MetricInfo (optional) Info about the metric to plot on the y-axis. Default: None (only for histograms) """self._check_plot_type_is_consistent()self._check_metrics_are_compatible(metric_info_x,metric_info_y)
def_check_plot_type_is_consistent(self)->None:""" Make sure the number of metrics is consistent with the plot type, 1 metric for histogram and 2 for scatter. """ifnot(self.metric_id_y<0)==(self.plot_type==PLOT_TYPE.HISTOGRAM):raiseInconsistentPlotTypeError(self.plot_type)def_check_metrics_are_compatible(self,metric_info_x:MetricInfo,metric_info_y:Optional[MetricInfo])->None:""" Check that the X and Y metrics are of the same type, if this is not a histogram. """ifmetric_info_yisNone:returnx_metric_type=metric_info_x.metric_typey_metric_type=metric_info_y.metric_typeifx_metric_type!=y_metric_type:x_metric_name=metric_info_x.display_namey_metric_name=metric_info_y.display_nameraiseIncompatibleMetricsError(x_metric_name,y_metric_name)
[docs]defset_display_title(self,metric_info_x:MetricInfo,metric_info_y:Optional[MetricInfo])->None:""" Return the title to display above the plot. If no title is provided, default to "Y metric name vs. X metric name". Parameters ---------- metric_info_x: MetricInfo Info about the metric to plot on the x-axis. metric_info_y: MetricInfo (optional) Info about the metric to plot on the y-axis. Default: None (only for histograms) """ifself.title:# use custom titleself.display_title=self.titlereturnx_metric_name=metric_info_x.display_nameifmetric_info_yisNone:# histogramself.display_title=f"{x_metric_name}"return# scatter ploty_metric_name=metric_info_y.display_nameself.display_title=f"{y_metric_name} vs. {x_metric_name.lower()}"
def__str__(self)->str:""" Get the title and type of this plot. Returns ------- str "[title] [type of plot]" """title=f"{self.display_title} "ifself.display_titleelse""pt="histogram"ifself.plot_type==PLOT_TYPE.HISTOGRAMelse"scatter plot"returnf"{title}{pt}"