def Setup_UI_YAxisLabelParms(self):
     # Y-Axis Label Properties
     self.le_yaxislabeltext = QLineEdit()
     self.cmb_yaxislabelsize = QComboBox()
     self.cmb_yaxislabelsize.addItems([
         'xx-small', 'x-small', 'small', 'medium', 'large', 'x-large',
         'xx-large'
     ])
     self.cmb_yaxislabelsize.setCurrentIndex(3)
     self.spinbox_yaxislabelrot = QDoubleSpinBox(maximum=90,
                                                 minimum=0,
                                                 value=90,
                                                 singleStep=1)
     self.cmb_yaxislabelweight = QComboBox()
     self.cmb_yaxislabelweight.addItems(["normal", "bold"])
     self.cmb_yaxislabelweight.setCurrentIndex(0)
     self.yaxis_widgets = [
         self.le_yaxislabeltext, self.cmb_yaxislabelsize,
         self.spinbox_yaxislabelrot, self.cmb_yaxislabelweight
     ]
     self.yaxis_defaults = ["", 3, 90, 0]
     # Connect the widgets to their functions and add to the appropriate form layout
     for description, widget in zip(
         ["Text", "Fontsize", "Rotation", "Fontweight"],
             self.yaxis_widgets):
         connect_widget_to_signal(widget,
                                  self.sendSignal_yaxislabel_updateplot)
         self.formlay_yaxislabel.addRow(description, widget)
         if system() == "Darwin":
             widget.setSizePolicy(QSizePolicy.Expanding,
                                  QSizePolicy.Preferred)
 def Setup_UI_TitleParms(self):
     # Title Properties
     self.le_titletext = QLineEdit()
     self.cmb_titleloc = QComboBox()
     self.cmb_titleloc.addItems(['center', 'left', 'right'])
     self.cmb_titlesize = QComboBox()
     self.cmb_titlesize.addItems([
         'xx-small', 'x-small', 'small', 'medium', 'large', 'x-large',
         'xx-large'
     ])
     self.cmb_titlesize.setCurrentIndex(3)
     self.cmb_titleweight = QComboBox()
     self.cmb_titleweight.addItems(["normal", "bold"])
     self.cmb_titleweight.setCurrentIndex(0)
     self.title_widgets = [
         self.le_titletext, self.cmb_titleloc, self.cmb_titlesize,
         self.cmb_titleweight
     ]
     self.title_defaults = ["", 0, 3, 0]
     # Connect the widgets to their functions and add to the appropriate form layout
     for description, widget in zip(
         ["Text", "Location", "Fontsize", "Fontweight"],
             self.title_widgets):
         connect_widget_to_signal(widget, self.sendSignal_title_updateplot)
         self.formlay_title.addRow(description, widget)
         if system() == "Darwin":
             widget.setSizePolicy(QSizePolicy.Expanding,
                                  QSizePolicy.Preferred)
 def reset_labels(self):
     """
     This function resets every widget back to their defaults and then reconnects the widget to that signal.
     This avoids overhead of constantly updating a canvas as widgets are reset back to their defaults in the
     event of a new figure being implemented
     """
     for widget, signal, default in zip(self.xaxis_widgets + self.yaxis_widgets + self.title_widgets,
                                        [self.sendSignal_xaxislabel_updateplot] * 4 +
                                        [self.sendSignal_yaxislabel_updateplot] * 4 +
                                        [self.sendSignal_title_updateplot] * 4,
                                        self.xaxis_defaults + self.yaxis_defaults + self.title_defaults):
         disconnect_widget_and_reset(widget=widget, target_signal=signal, default=default)
         connect_widget_to_signal(widget=widget, target_signal=signal)
    def __init__(self, parent=None):
        super().__init__(parent=parent)
        self.parent: xASL_GUI_FacetManager = parent  # The Facet Grid Manager
        self.setWindowFlag(Qt.Window)
        self.setWindowTitle("FacetGrid Ticklabels Settings")
        self.formlay_ticks = QFormLayout(self)
        if system() == "Darwin":
            set_formlay_options(self.formlay_ticks)

        # Widgets
        self.cmb_hfontsize = QComboBox()
        self.cmb_hfontsize.addItems(["xx-small", "x-small", "small", "medium", "large", "x-large", "xx-large"])
        self.cmb_hfontsize.setCurrentIndex(2)
        self.cmb_hfontweight = QComboBox()
        self.cmb_hfontweight.addItems(["normal", "bold", "extra bold"])
        self.cmb_hfontweight.setCurrentIndex(0)
        self.cmb_hfontstyle = QComboBox()
        self.cmb_hfontstyle.addItems(["normal", "italic"])
        self.cmb_hfontstyle.setCurrentIndex(0)
        self.cmb_halign = QComboBox()
        self.cmb_halign.addItems(["center", "left", "right"])
        self.cmb_halign.setCurrentIndex(2)
        self.spinbox_hrot = QSpinBox(maximum=90, minimum=0, value=0, singleStep=1)
        self.spinbox_halpha = QDoubleSpinBox(maximum=1, minimum=0, value=1, singleStep=0.01)

        for widget, description in zip([self.cmb_hfontsize, self.cmb_hfontweight, self.cmb_hfontstyle, self.cmb_halign,
                                        self.spinbox_hrot, self.spinbox_halpha],
                                       ["Font Size", "Font Weight", "Font Style", "Alignment", "Rotation", "Opaqueness"
                                        ]):
            self.formlay_ticks.addRow(description, widget)
            connect_widget_to_signal(widget, self.sendSignal_tickparms_updateplot)
            if system() == "Darwin":
                widget.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred)

        self.xtick_kwargs = {
            "fontsize": self.cmb_hfontsize.currentText,
            "fontweight": self.cmb_hfontweight.currentText,
            "fontstyle": self.cmb_hfontstyle.currentText,
            "horizontalalignment": self.cmb_halign.currentText,
            "rotation": self.spinbox_hrot.value,
            "alpha": self.spinbox_halpha.value
        }
    def __init__(self, parent=None):
        super().__init__(parent)
        self.parent: xASL_GUI_FacetManager = parent  # The Facet Grid Manager
        self.setWindowFlag(Qt.Window)
        self.setWindowTitle("FacetGrid Legend Settings")
        self.formlay_legend = QFormLayout(self)

        # Widgets
        self.cmb_location = QComboBox()
        self.cmb_location.addItems(["best", "upper right", "upper left", "lower left", "lower right", "center left",
                                    "center right", "lower center", "upper center"])
        self.chk_manual_loc = QCheckBox(checked=False)
        self.spinbox_legend_x = QDoubleSpinBox(maximum=2, minimum=0, value=1.05, singleStep=0.01)
        self.spinbox_legend_y = QDoubleSpinBox(maximum=20, minimum=0, value=1, singleStep=0.01)
        self.cmb_fontsize = QComboBox()
        self.cmb_fontsize.addItems(["xx-small", "x-small", "small", "medium", "large", "x-large", "xx-large"])
        self.cmb_fontsize.setCurrentIndex(3)
        self.chk_frameon = QCheckBox(checked=False)
        self.chk_fancybox = QCheckBox(checked=False)
        self.chk_shadow = QCheckBox(checked=False)
        self.spinbox_markersize = QDoubleSpinBox(maximum=2, minimum=0, value=1, singleStep=0.01)
        self.chk_markerfirst = QCheckBox(checked=True)

        for widget, description in zip([self.cmb_location, self.chk_manual_loc, self.spinbox_legend_x,
                                        self.spinbox_legend_y, self.cmb_fontsize, self.chk_frameon, self.chk_fancybox,
                                        self.chk_shadow, self.spinbox_markersize, self.chk_markerfirst],
                                       ["Legend location", "Manually set location?", "Manual X position",
                                        "Manual Y Position", "Legend fontsize", "Legend frame is on?",
                                        "Legend frame has rounded corners?", "Legend frame has shadow?",
                                        "Marker size", "Marker first before label?"]):
            self.formlay_legend.addRow(description, widget)
            connect_widget_to_signal(widget, self.sendSignal_legendparms_updateplot)

        self.legend_kwargs = {
            "loc": self.cmb_location.currentText,
            "fontsize": self.cmb_fontsize.currentText,
            "frameon": self.chk_frameon.isChecked,
            "fancybox": self.chk_fancybox.isChecked,
            "shadow": self.chk_shadow.isChecked,
            "markerscale": self.spinbox_markersize.value,
            "markerfirst": self.chk_markerfirst.isChecked
        }
    def UI_Setup_AxesParms(self, plot_type):
        self.clear_axesparms()
        print(f"Selected {plot_type} as the Axes Type")

        # These are always a given
        if self.cmb_axestype.currentText() in ["Point Plot", "Bar Plot", "Strip Plot", "Swarm Plot",
                                               "Box Plot", "Violin Plot", "Boxen Plot"]:
            self.le_x = DandD_Graphing_ListWidget2LineEdit(self.parent_cw, self.categorical_dtypes)
            self.le_x.setPlaceholderText("Drag & Drop the X-axis Variable")
            self.le_x.setToolTip("Indicate the Categorical variable that should be on the x-axis")
            self.le_y = DandD_Graphing_ListWidget2LineEdit(self.parent_cw, self.numeric_dtypes)
            self.le_y.setPlaceholderText("Drag & Drop the Y-axis Variable")
            self.le_y.setToolTip("Indicate the Numberical variable that should be on the y-axis")

        elif self.cmb_axestype.currentText() in ["Scatter Plot", "Line Plot",
                                                 "Regression Plot", "Residuals Plot"]:
            self.le_x = DandD_Graphing_ListWidget2LineEdit(self.parent_cw, self.numeric_dtypes)
            self.le_x.setPlaceholderText("Drag & Drop the X-axis Variable")
            self.le_y = DandD_Graphing_ListWidget2LineEdit(self.parent_cw, self.numeric_dtypes)
            self.le_y.setPlaceholderText("Drag & Drop the Y-axis Variable")
        else:
            pass

        self.le_hue = DandD_Graphing_ListWidget2LineEdit(self.parent_cw, ["object", "category"])
        self.le_hue.setPlaceholderText("Drag & Drop the Hue Grouping Variable")
        self.le_hue.setToolTip("Indicate the Categorical variable by which data should be grouped\n "
                               "using marker color differences")
        self.axes_arg_x = self.le_x.text
        self.axes_arg_y = self.le_y.text
        self.axes_arg_hue = self.le_hue.text

        if plot_type == "Point Plot":
            # Define row widgets
            self.plotting_func = sns.pointplot
            self.ci = QDoubleSpinBox(maximum=100, minimum=0, value=95, singleStep=1)
            self.ci.setToolTip("Indicate the confidence interval that should be displayed in the error bars")
            self.dodge = QCheckBox(checked=True)
            self.dodge.setToolTip("Indicate whether, when grouping by a Hue variable, the plot should feature\n"
                                  "separate points for different levels within the Hue variable category")
            self.join = QCheckBox(checked=True)
            self.join.setToolTip("Indicate whether points across the different estimates should be join by solid lines")
            self.errwidth = QDoubleSpinBox(maximum=2, minimum=0, value=2, singleStep=0.05)
            self.errwidth.setToolTip("Indicate the thickness of the lines of the error bars. Units are arbitary")
            self.capsize = QDoubleSpinBox(maximum=1, minimum=0, value=0.05, singleStep=0.005)
            self.capsize.setToolTip("Indicate the width of the error bar cap. Units are arbitrary")
            self.cmb_palette = self.UI_Setup_PaletteCombobox()
            self.cmb_palette.setToolTip("Indicate the color palette that should be used")
            self.axes_kwargs = self.UI_Setup_AxesMappings(["ci", "dodge", "join", "errwidth", "capsize", "palette"],
                                                          [self.ci, self.dodge, self.join, self.errwidth, self.capsize,
                                                           self.cmb_palette])
            # Create the underlying widget container and form layout
            self.UI_Setup_AxesParms_Subcontainer()
            # Add widgets to form layout and connect to appropriate function/signal
            for description, widget in zip(["X Axis Variable", "Y Axis variable", "Hue Grouping Variable",
                                            "Confidence interval", "Offset points?", "Join points?",
                                            "Errorbar thickness", "Cap width", "Palette"],
                                           [self.le_x, self.le_y, self.le_hue, self.ci, self.dodge, self.join,
                                            self.errwidth, self.capsize, self.cmb_palette]):
                self.formlay_axesparms.addRow(description, widget)
                connect_widget_to_signal(widget, self.sendSignal_plotupdate_axescall)
                if system() == "Darwin":
                    widget.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred)

        elif plot_type == "Strip Plot" or plot_type == "Swarm Plot":
            if plot_type == "Strip Plot":
                self.plotting_func = sns.stripplot
            else:
                self.plotting_func = sns.swarmplot
            self.dodge = QCheckBox(checked=True)
            self.dodge.setToolTip("Indicate whether, when grouping by a Hue variable, the plot should feature\n"
                                  "separate points for different levels within the Hue variable category")
            self.size = QDoubleSpinBox(maximum=10, minimum=1, value=4.5, singleStep=0.1)
            self.size.setToolTip("Indicate the radius of the marker points. Units are arbitary.")
            self.linewidth = QDoubleSpinBox(maximum=2, minimum=0, value=0.1, singleStep=0.1)
            self.linewidth.setToolTip("Indicate the thickness of the outline around points. Units are arbitary")
            self.cmb_palette = self.UI_Setup_PaletteCombobox()
            self.cmb_palette.setToolTip("Indicate the color palette that should be used")
            self.axes_kwargs = self.UI_Setup_AxesMappings(["dodge", "size", "linewidth", "palette"],
                                                          [self.dodge, self.size, self.linewidth, self.cmb_palette])
            # Create the underlying widget container and form layout
            self.UI_Setup_AxesParms_Subcontainer()
            # Add widgets to form layout and connect to appropriate function/signal
            for description, widget in zip(["X Axis Variable", "Y Axis variable", "Hue Grouping Variable",
                                            "Separate groupings when hue nesting?", "Marker size", "Marker edge width",
                                            "Palette"],
                                           [self.le_x, self.le_y, self.le_hue, self.dodge, self.size, self.linewidth,
                                            self.cmb_palette]):
                self.formlay_axesparms.addRow(description, widget)
                connect_widget_to_signal(widget, self.sendSignal_plotupdate_axescall)
                if system() == "Darwin":
                    widget.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred)

        elif plot_type == "Box Plot":
            self.plotting_func = sns.boxplot
            self.barwidth = QDoubleSpinBox(maximum=1, minimum=0, value=0.7, singleStep=0.05)
            self.barwidth.setToolTip("Indicate the width of the bar outlines")
            self.dodge = QCheckBox(checked=True)
            self.dodge.setToolTip("Indicate whether, when grouping by a Hue variable, the plot should feature\n"
                                  "separated boxes for different levels within the Hue variable category")
            self.fliersize = QDoubleSpinBox(maximum=10, minimum=0, value=5, singleStep=0.25)
            self.fliersize.setToolTip("Indicate the size of the markers used to dictate outliers. Units are arbitrary")
            self.linewidth = QDoubleSpinBox(maximum=5, minimum=0, value=1.55, singleStep=0.05)
            self.linewidth.setToolTip("Indicate the thickness of the outline for the boxes. Units are arbitrary")
            self.whis = QDoubleSpinBox(maximum=3, minimum=0, value=1.5, singleStep=0.1)
            self.whis.setToolTip("Indicate the proportion of the IQR past the low and high quartiles\n"
                                 "to extend the plot's whiskers towards")
            self.cmb_palette = self.UI_Setup_PaletteCombobox()
            self.cmb_palette.setToolTip("Indicate the color palette that should be used")
            self.axes_kwargs = self.UI_Setup_AxesMappings(["width", "dodge", "fliersize",
                                                           "linewidth", "palette", "whis"],
                                                          [self.barwidth, self.dodge, self.fliersize,
                                                           self.linewidth, self.cmb_palette, self.whis])
            # Create the underlying widget container and form layout
            self.UI_Setup_AxesParms_Subcontainer()
            # Add widgets to form layout and connect to appropriate function/signal
            for description, widget in zip(["X Axis Variable", "Y Axis variable", "Hue Grouping Variable",
                                            "Bar width when not hue nesting?", "Shift bars when hue nesting?",
                                            "Marker size of outlier observations", "Box linewidth",
                                            "Palette",
                                            "Fraction of IQR to identify inliers"],
                                           [self.le_x, self.le_y, self.le_hue, self.barwidth, self.dodge,
                                            self.fliersize, self.linewidth, self.cmb_palette, self.whis]):
                self.formlay_axesparms.addRow(description, widget)
                connect_widget_to_signal(widget, self.sendSignal_plotupdate_axescall)
                if system() == "Darwin":
                    widget.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred)

        elif plot_type == "Violin Plot":
            self.plotting_func = sns.violinplot
            self.kernalbwalgo = QComboBox()
            self.kernalbwalgo.addItems(["scott", "silverman"])
            self.kernalbwalgo.setToolTip("Indicate the algorithm to use when computing the kernel bandwidth")
            self.scale = QComboBox()
            self.scale.setToolTip("Indicate the method used to scale each violin")
            self.scale.addItems(["area", "count", "width"])
            self.scale_hue = QCheckBox(checked=True)
            self.scale_hue.setToolTip("When nesting violins along a Hue grouping variable, whether the scaling \n"
                                      "is computed within each level of the major grouping variable (CHECKED)\n"
                                      "or across all the violins in the plot (UNCHECKED)")
            self.dodge = QCheckBox(checked=True)
            self.dodge.setToolTip("Indicate whether, when grouping by a Hue variable, the plot should feature\n"
                                  "separated violins for different levels within the Hue variable category")
            self.linewidth = QDoubleSpinBox(maximum=5, minimum=0, value=1.8, singleStep=0.1)
            self.linewidth.setToolTip("Indicate the width of the lines outlining the frame of violins")
            self.cmb_palette = self.UI_Setup_PaletteCombobox()
            self.cmb_palette.setToolTip("Indicate the color palette that should be used")
            self.axes_kwargs = self.UI_Setup_AxesMappings(["bw", "scale", "scale_hue", "dodge", "linewidth", "palette"],
                                                          [self.kernalbwalgo, self.scale, self.scale_hue, self.dodge,
                                                           self.linewidth,
                                                           self.cmb_palette])
            # Create the underlying widget container and form layout
            self.UI_Setup_AxesParms_Subcontainer()
            # Add widgets to form layout and connect to appropriate function/signal
            for description, widget in zip(["X Axis Variable", "Y Axis variable", "Hue Grouping Variable",
                                            "Kernel algorithm", "Basis of scaling width",
                                            "Recalculate scaling when hue nesting?", "Shift plots when hue nesting?",
                                            "Linewidth of outlines", "Palette"],
                                           [self.le_x, self.le_y, self.le_hue, self.kernalbwalgo, self.scale,
                                            self.scale_hue, self.dodge, self.linewidth, self.cmb_palette]):
                self.formlay_axesparms.addRow(description, widget)
                connect_widget_to_signal(widget, self.sendSignal_plotupdate_axescall)
                if system() == "Darwin":
                    widget.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred)

        elif plot_type == "Boxen Plot":
            self.plotting_func = sns.boxenplot
            self.barwidth = QDoubleSpinBox(maximum=1, minimum=0, value=0.8, singleStep=0.05)
            self.barwidth.setToolTip("Indicate the width of a boxen element when NOT using hue-based nesting")
            self.dodge = QCheckBox(checked=True)
            self.dodge.setToolTip("Indicate whether, when grouping by a Hue variable, the plot should feature\n"
                                  "separated elements for different levels within the Hue variable category")
            self.linewidth = QDoubleSpinBox(maximum=5, minimum=0, value=0.7, singleStep=0.1)
            self.linewidth.setToolTip("Indicate the width of the lines outlining the frame of the boxen elements")
            self.outlier_prop = QDoubleSpinBox(maximum=1, minimum=0, value=0.007, singleStep=0.001)
            self.outlier_prop.setToolTip("Indicate the proportion of the data believe to be outliers\n"
                                         "(0 meaning none and 1 meaning 1)")
            self.show_outliers = QCheckBox(checked=True)
            self.show_outliers.setToolTip("Indicate whether outliers should be displayed")
            self.cmb_palette = self.UI_Setup_PaletteCombobox()
            self.cmb_palette.setToolTip("Indicate the color palette that should be used")
            self.axes_kwargs = self.UI_Setup_AxesMappings(["width", "dodge", "linewidth", "outlier_prop",
                                                           "showfliers", "palette"],
                                                          [self.barwidth, self.dodge, self.linewidth, self.outlier_prop,
                                                           self.show_outliers, self.cmb_palette])
            # Create the underlying widget container and form layout
            self.UI_Setup_AxesParms_Subcontainer()
            # Add widgets to form layout and connect to appropriate function/signal
            for description, widget in zip(["X Axis Variable", "Y Axis variable", "Hue Grouping Variable",
                                            "Relative bar width", "Shift plots when hue nesting?",
                                            "Linewidth of the boxes", "Expected proportion of outliers",
                                            "Show outliers?", "Palette"],
                                           [self.le_x, self.le_y, self.le_hue, self.barwidth, self.dodge,
                                            self.linewidth, self.outlier_prop, self.show_outliers, self.cmb_palette]):
                self.formlay_axesparms.addRow(description, widget)
                connect_widget_to_signal(widget, self.sendSignal_plotupdate_axescall)
                if system() == "Darwin":
                    widget.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred)

        elif plot_type == "Scatter Plot":
            self.plotting_func = sns.scatterplot
            self.size_grouper = DandD_Graphing_ListWidget2LineEdit(self.parent_cw, self.all_dtypes)
            self.size_grouper.setPlaceholderText("(Optional) Drag & Drop the Markersize-Grouping Variable")
            self.size_grouper.setToolTip("Indicate the variable by which data should be grouped\n"
                                         "using marker size differences")
            self.style_grouper = DandD_Graphing_ListWidget2LineEdit(self.parent_cw, ["object", "category"])
            self.style_grouper.setPlaceholderText("(Optional) Drag & Drop the Markerstyle-Grouping Variable")
            self.style_grouper.setToolTip("Indicate the variable by which data should be grouped\n"
                                          "using marker style differences")
            self.cmb_palette = self.UI_Setup_PaletteCombobox()
            self.cmb_palette.setToolTip("Indicate the color palette that should be used")
            self.spinbox_markersize = QDoubleSpinBox(maximum=100, minimum=0, value=40, singleStep=1)
            self.spinbox_markersize.setToolTip("Indicate the radius of the points. Units are arbitary.")
            self.axes_kwargs = self.UI_Setup_AxesMappings(["size", "style", "palette", "s"],
                                                          [self.size_grouper, self.style_grouper,
                                                           self.cmb_palette, self.spinbox_markersize])
            # Create the underlying widget container and form layout
            self.UI_Setup_AxesParms_Subcontainer()
            # Add widgets to form layout and connect to appropriate function/signal
            for description, widget in zip(["X Axis Variable", "Y Axis variable", "Hue Grouping Variable",
                                            "Size Grouping Variable", "Marker Style Grouping Variable", "Marker size",
                                            "Palette"],
                                           [self.le_x, self.le_y, self.le_hue, self.size_grouper, self.style_grouper,
                                            self.spinbox_markersize, self.cmb_palette]):
                self.formlay_axesparms.addRow(description, widget)
                connect_widget_to_signal(widget, self.sendSignal_plotupdate_axescall)
                if system() == "Darwin":
                    widget.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred)

        # Setup the wigets associated with connecting to the legend parameters each time
        if plot_type != "Select a plot type":
            self.UI_Setup_Btn2LegendParms()
            self.UI_Setup_Btn2AxisTickLabelsParms()

        # Regardless of what type of plot was selected, the current axes should be cleared
        self.artist.clear_axes()
        self.artist.canvas.draw()
    def UI_Setup_FigureParms(self):
        # Define Widgets
        self.le_row = DandD_Graphing_ListWidget2LineEdit(self.parent_cw, ["object", "category"])
        self.le_row.setToolTip("Indicate the Categorical variable by which multiple plots should be generated, with\n"
                               "each level of the variable alloting a plot to a separate row")
        self.le_row.setPlaceholderText("Drag & Drop variable to define facet rows")
        self.le_col = DandD_Graphing_ListWidget2LineEdit(self.parent_cw, ["object", "category"])
        self.le_col.setToolTip("Indicate the Categorical variable by which multiple plots should be generated, with\n"
                               "each level of the variable alloting a plot to a separate column")
        self.le_col.setPlaceholderText("Drag & Drop variable to define facet columns")
        self.chk_sharex = QCheckBox(checked=True)
        self.chk_sharex.setToolTip("Indicate whether, when creating multiple plots on different rows, that the\n"
                                   "x-axis of which are shared between plots")
        self.chk_sharey = QCheckBox(checked=True)
        self.chk_sharey.setToolTip("Indicate whether, when creating multiple plots on different columns, that the\n"
                                   "y-axis of which are shared between plots")
        self.spinbox_facetheight = QDoubleSpinBox(maximum=10, minimum=1, value=5, singleStep=0.1)
        self.spinbox_facetheight.setToolTip("Indicate, for saving and printout, the height of the plot in inches.")
        self.spinbox_aspect = QDoubleSpinBox(maximum=2, minimum=0.5, value=1, singleStep=0.1)
        self.spinbox_aspect.setToolTip("Indicate, for saving and printout, the aspect ratio of the plot.\n"
                                       "Note that aspect_ratio * height gives the width of each facet in\n"
                                       "inches")
        self.chk_legend_out = QCheckBox(checked=True)
        self.chk_legend_out.setToolTip("Indicate whether the legend should be permitted to be plotted beyond the\n"
                                       "bounds of the facetgrid. Recommended to be checked.")
        self.chk_despine = QCheckBox(checked=True)
        self.chk_despine.setToolTip("Indicate whether the plots in this facet grid should be de-spined")
        self.chk_margin_titles = QCheckBox(checked=True)
        self.chk_margin_titles.setToolTip("Indicate whether, when create multiple plots on different rows, that the\n"
                                          "levels of the row-wise grouping variable are displayed parallel to the\n"
                                          "y-axis of each plot for that row")

        # Generate Facet Figure-level Mappings
        self.fig_kwargs = {"row": self.le_row.text,
                           "col": self.le_col.text,
                           "sharex": self.chk_sharex.isChecked,
                           "sharey": self.chk_sharey.isChecked,
                           "height": self.spinbox_facetheight.value,
                           "aspect": self.spinbox_aspect.value,
                           "legend_out": self.chk_legend_out.isChecked,
                           "despine": self.chk_despine.isChecked,
                           "margin_titles": self.chk_margin_titles.isChecked
                           }

        # Attach defined widgets to the form layout
        for description, widget in zip(["Row Grouping Variable", "Column Grouping Variable", "Share x axes?",
                                        "Share y axes?", "Height of each facet (inches)", "Aspect Ratio",
                                        "Draw legend outside grid?", "Remove top and right spines?", "Margin titles"],
                                       [self.le_row, self.le_col, self.chk_sharex, self.chk_sharey,
                                        self.spinbox_facetheight, self.spinbox_aspect,
                                        self.chk_legend_out, self.chk_despine, self.chk_margin_titles]):
            self.formlay_figparms.addRow(description, widget)
            connect_widget_to_signal(widget, self.sendSignal_plotupdate_figurecall)
            if system() == "Darwin":
                widget.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred)

        # Finally add the combobox for selecting the axes type. The connect signal will be established later in
        # UI_Setup_ConnectManager2Artist to ensure that the artist exists
        self.cmb_axestype = QComboBox()
        self.cmb_axestype.addItems(["Select a plot type", "Point Plot", "Strip Plot", "Swarm Plot", "Box Plot",
                                    "Violin Plot", "Boxen Plot", "Scatter Plot"])  # "Bar Plot", "Line Plot"
        self.cmb_axestype.setToolTip("Indicate the type of plot on which the data should be displayed")
        font = QFont()
        font.setPointSize(12)
        self.cmb_axestype.setFont(font)
        self.formlay_figparms.addRow(self.cmb_axestype)
Example #8
0
    def UI_Setup_AxesParms(self, plot_type):
        self.clear_axesparms()
        print(f"Selected {plot_type} as the Axes Type")

        if plot_type == "Strip Plot":
            self.plotting_func = sns.stripplot
            self.le_x = DandD_Graphing_ListWidget2LineEdit(self.parent_cw, self.categorical_dtypes)
            self.le_x.setToolTip("Indicate the Categorical variable that should be on the x-axis")
            self.le_x.setPlaceholderText("Drag & Drop the X-axis Variable")
            self.le_y = DandD_Graphing_ListWidget2LineEdit(self.parent_cw, self.numeric_dtypes)
            self.le_y.setToolTip("Indicate the Numberical variable that should be on the y-axis")
            self.le_y.setPlaceholderText("Drag & Drop the Y-axis Variable")
            self.le_hue = DandD_Graphing_ListWidget2LineEdit(self.parent_cw, ["object", "category"])
            self.le_hue.setToolTip("Indicate the Categorical variable by which data should be grouped\n "
                                   "using marker color differences")
            self.le_hue.setPlaceholderText("Drag & Drop the Hue Grouping Variable")
            self.axes_arg_x = self.le_x.text
            self.axes_arg_y = self.le_y.text
            self.axes_arg_hue = self.le_hue.text

            self.dodge = QCheckBox(checked=True)
            self.dodge.setToolTip("Indicate whether, when grouping by a Hue variable, the stripplot should feature\n"
                                  "separate columns of points for different levels within the Hue variable category")
            self.size = QDoubleSpinBox(maximum=10, minimum=1, value=4.5, singleStep=0.1)
            self.size.setToolTip("Indicate the radius of the marker points. Units are arbitary.")
            self.linewidth = QDoubleSpinBox(maximum=2, minimum=0, value=0.1, singleStep=0.1)
            self.linewidth.setToolTip("Indicate the thickness of the outline around points. Units are arbitary")
            self.cmb_palette = self.UI_Setup_PaletteCombobox()
            self.cmb_palette.setToolTip("Indicate the color palette that should be used")
            self.axes_kwargs = self.UI_Setup_AxesMappings(["dodge", "size", "linewidth", "palette"],
                                                          [self.dodge, self.size, self.linewidth, self.cmb_palette])
            # Create the underlying widget container and form layout
            self.UI_Setup_AxesParms_Subcontainer()
            # Add widgets to form layout and connect to appropriate function/signal
            for description, widget in zip(["X Axis Variable", "Y Axis variable", "Hue Grouping Variable",
                                            "Separate groupings when hue nesting?", "Marker size", "Marker edge width",
                                            "Palette"],
                                           [self.le_x, self.le_y, self.le_hue, self.dodge, self.size, self.linewidth,
                                            self.cmb_palette]):
                self.formlay_axesparms.addRow(description, widget)
                connect_widget_to_signal(widget, self.sendSignal_plotupdate_axescall)
                if system() == "Darwin":
                    widget.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred)

            # xticklabels rotation has a different connection
            self.spinbox_xticksrot = QSpinBox(minimum=0, maximum=90, value=0, singleStep=1)
            connect_widget_to_signal(self.spinbox_xticksrot, self.sendSignal_plotupdate_xticksrot)
            connect_widget_to_signal(self.le_x, self.artist.plotupdate_xticklabels_from_le)
            connect_widget_to_signal(self.le_y, self.artist.plotupdate_xticklabels_from_le)
            connect_widget_to_signal(self.le_hue, self.artist.plotupdate_xticklabels_from_le)
            self.formlay_axesparms.addRow("X Axis Ticklabels Rotation", self.spinbox_xticksrot)
            if system() == "Darwin":
                self.spinbox_xticksrot.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred)

            # Don't forget to remove the spacer item
            self.vlay_axesparms.removeItem(self.spacer)

        elif plot_type == "Scatter Plot":
            self.plotting_func = sns.scatterplot
            self.le_x = DandD_Graphing_ListWidget2LineEdit(self.parent_cw, self.numeric_dtypes)
            self.le_x.setToolTip("Indicate the Categorical variable that should be on the x-axis")
            self.le_x.setPlaceholderText("Drag & Drop the X-axis Variable")
            self.le_y = DandD_Graphing_ListWidget2LineEdit(self.parent_cw, self.numeric_dtypes)
            self.le_y.setToolTip("Indicate the Numberical variable that should be on the y-axis")
            self.le_y.setPlaceholderText("Drag & Drop the Y-axis Variable")
            self.le_hue = DandD_Graphing_ListWidget2LineEdit(self.parent_cw, ["object", "category"])
            self.le_hue.setToolTip("Indicate the Categorical variable by which data should be grouped\n "
                                   "using marker color differences")
            self.le_hue.setPlaceholderText("Drag & Drop the Hue Grouping Variable")
            self.axes_arg_x = self.le_x.text
            self.axes_arg_y = self.le_y.text
            self.axes_arg_hue = self.le_hue.text

            self.size_grouper = DandD_Graphing_ListWidget2LineEdit(self.parent_cw, self.all_dtypes)
            self.size_grouper.setToolTip("Indicate the variable by which data should be grouped\n"
                                         "using marker size differences")
            self.size_grouper.setPlaceholderText("(Optional) Drag & Drop the Markersize-Grouping Variable")
            self.style_grouper = DandD_Graphing_ListWidget2LineEdit(self.parent_cw, ["object", "category"])
            self.style_grouper.setToolTip("Indicate the variable by which data should be grouped\n"
                                          "using marker style differences")
            self.style_grouper.setPlaceholderText("(Optional) Drag & Drop the Markerstyle-Grouping Variable")
            self.cmb_palette = self.UI_Setup_PaletteCombobox()
            self.cmb_palette.setToolTip("Indicate the color palette that should be used")
            self.spinbox_markersize = QDoubleSpinBox(maximum=100, minimum=0, value=40, singleStep=1)
            self.spinbox_markersize.setToolTip("Indicate the radius of the points. Units are arbitary.")
            self.axes_kwargs = self.UI_Setup_AxesMappings(["size", "style", "palette", "s"],
                                                          [self.size_grouper, self.style_grouper,
                                                           self.cmb_palette, self.spinbox_markersize])
            # Create the underlying widget container and form layout
            self.UI_Setup_AxesParms_Subcontainer()
            # Add widgets to form layout and connect to appropriate function/signal
            for description, widget in zip(["X Axis Variable", "Y Axis variable", "Hue Grouping Variable",
                                            "Size Grouping Variable", "Marker Style Grouping Variable", "Marker size",
                                            "Palette"],
                                           [self.le_x, self.le_y, self.le_hue, self.size_grouper, self.style_grouper,
                                            self.spinbox_markersize, self.cmb_palette]):
                self.formlay_axesparms.addRow(description, widget)
                connect_widget_to_signal(widget, self.sendSignal_plotupdate_axescall)
                if system() == "Darwin":
                    widget.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred)

            self.vlay_axesparms.removeItem(self.spacer)

        else:
            self.axes_arg_x = ''
            self.axes_arg_y = ''
            self.axes_arg_hue = ''

        # Regardless of what type of plot was selected, the current axes should be cleared
        self.artist.clear_axes()
        self.artist.plotting_canvas.draw()
        self.cmb_selectsubject.setCurrentIndex(0)