def test_plot_style_copy_style(self): style = PlotStyle("Test", "red", 0.5, ".", "o", 2.5) style.setEnabled(False) copy_style = PlotStyle("Copy") copy_style.copyStyleFrom(style) self.assertNotEqual(style.name, copy_style.name) self.assertEqual(style.color, copy_style.color) self.assertEqual(style.alpha, copy_style.alpha) self.assertEqual(style.line_style, copy_style.line_style) self.assertEqual(style.marker, copy_style.marker) self.assertEqual(style.width, copy_style.width) self.assertNotEqual(style.isEnabled(), copy_style.isEnabled()) another_copy_style = PlotStyle("Another Copy") another_copy_style.copyStyleFrom(style, copy_enabled_state=True) self.assertEqual(style.isEnabled(), another_copy_style.isEnabled())
def distributionStyle(self): """ @rtype: PlotStyle """ style = PlotStyle("Distribution Style") style.copyStyleFrom(self.__distribution_style) style.color = self.currentColor() return style
def histogramStyle(self): """ @rtype: PlotStyle """ style = PlotStyle("Histogram Style") style.copyStyleFrom(self.__histogram_style) style.color = self.currentColor() return style
class PlotConfig(object): def __init__(self, title="Unnamed", x_label=None, y_label=None): super(PlotConfig, self).__init__() self._title = title self._line_color_cycle_colors = ["#000000"] self._line_color_cycle = itertools.cycle(self._line_color_cycle_colors) #Black # Blueish, Greenlike, Beigeoid, Pinkness, Orangy-Brown self.setLineColorCycle(["#386CB0", "#7FC97F", "#FDC086", "#F0027F", "#BF5B17"]) # self.setLineColorCycle(["#e41a1c", "#377eb8", "#4daf4a", "#984ea3", "#ff7f00", "#ffff33", "#a65628", "#f781bf" ,"#386CB0", "#7FC97F", "#FDC086", "#F0027F", "#BF5B17"]) self._legend_items = [] self._legend_labels = [] self._x_label = x_label self._y_label = y_label self._limits = PlotLimits() self._default_style = PlotStyle(name="Default", color=None, alpha=0.8) self._refcase_style = PlotStyle(name="Refcase", alpha=0.8, marker="x", width=2.0) self._history_style = PlotStyle(name="History", alpha=0.8, marker="D", width=2.0) # Insanely ugly implementation of user preferences. if os.getenv("ERT_SHOW_HISTORY_VECTORS"): self._history_style.setEnabled(True) else: self._history_style.setEnabled(False) self._observation_style = PlotStyle(name="Observations") self._histogram_style = PlotStyle(name="Histogram", width=2.0) self._distribution_style = PlotStyle(name="Distribution", line_style="", marker="o", alpha=0.5, size=10.0) self._distribution_line_style = PlotStyle(name="Distribution Lines", line_style="-", alpha=0.25, width=1.0) self._distribution_line_style.setEnabled(False) self._current_color = None self._legend_enabled = True self._grid_enabled = True self._statistics_style = { "mean": PlotStyle("Mean", line_style=""), "p50": PlotStyle("P50", line_style=""), "min-max": PlotStyle("Min/Max", line_style=""), "p10-p90": PlotStyle("P10-P90", line_style=""), "p33-p67": PlotStyle("P33-P67", line_style=""), "std": PlotStyle("Std dev", line_style="") } self._std_dev_factor = 1 # sigma 1 is default std dev def currentColor(self): if self._current_color is None: self.nextColor() return self._current_color def nextColor(self): self._current_color = self._line_color_cycle.next() return self._current_color def setLineColorCycle(self, color_list): self._line_color_cycle_colors = color_list self._line_color_cycle = itertools.cycle(color_list) def lineColorCycle(self): return list(self._line_color_cycle_colors) def addLegendItem(self, label, item): self._legend_items.append(item) self._legend_labels.append(label) def title(self): """ :rtype: str """ return self._title if self._title is not None else "Unnamed" def setTitle(self, title): self._title = title def isUnnamed(self): return self._title is None def defaultStyle(self): style = PlotStyle("Default Style") style.copyStyleFrom(self._default_style) style.color = self.currentColor() return style def observationsStyle(self): """ @rtype: PlotStyle """ style = PlotStyle("Observations Style") style.copyStyleFrom(self._observation_style) return style def refcaseStyle(self): """ @rtype: PlotStyle """ style = PlotStyle("Refcase Style") style.copyStyleFrom(self._refcase_style) return style def historyStyle(self): """ @rtype: PlotStyle """ style = PlotStyle("History Style") style.copyStyleFrom(self._history_style) return style def histogramStyle(self): """ @rtype: PlotStyle """ style = PlotStyle("Histogram Style") style.copyStyleFrom(self._histogram_style) style.color = self.currentColor() return style def distributionStyle(self): """ @rtype: PlotStyle """ style = PlotStyle("Distribution Style") style.copyStyleFrom(self._distribution_style) style.color = self.currentColor() return style def distributionLineStyle(self): """ @rtype: ert_gui.plottery.PlotStyle """ style = PlotStyle("Distribution Line Style") style.copyStyleFrom(self._distribution_line_style) return style def xLabel(self): return self._x_label def yLabel(self): return self._y_label def legendItems(self): return self._legend_items def legendLabels(self): return self._legend_labels def setXLabel(self, label): self._x_label = label def setYLabel(self, label): self._y_label = label def setObservationsEnabled(self, enabled): self._observation_style.setEnabled(enabled) def isObservationsEnabled(self): return self._observation_style.isEnabled() def setRefcaseEnabled(self, enabled): self._refcase_style.setEnabled(enabled) def isRefcaseEnabled(self): return self._refcase_style.isEnabled() def setHistoryEnabled(self, enabled): self._history_style.setEnabled(enabled) def isHistoryEnabled(self): return self._history_style.isEnabled() def isLegendEnabled(self): return self._legend_enabled def isDistributionLineEnabled(self): return self._distribution_line_style.isEnabled() def setDistributionLineEnabled(self, enabled): self._distribution_line_style.setEnabled(enabled) def setStandardDeviationFactor(self, value): self._std_dev_factor = value def getStandardDeviationFactor(self): return self._std_dev_factor def setLegendEnabled(self, enabled): self._legend_enabled = enabled def isGridEnabled(self): return self._grid_enabled def setGridEnabled(self, enabled): self._grid_enabled = enabled def setStatisticsStyle(self, statistic, style): """ @type statistic: str @type style: PlotStyle """ statistics_style = self._statistics_style[statistic] statistics_style.line_style = style.line_style statistics_style.marker = style.marker statistics_style.width = style.width statistics_style.size = style.size def getStatisticsStyle(self, statistic): style = self._statistics_style[statistic] copy_style = PlotStyle(style.name) copy_style.copyStyleFrom(style) copy_style.color = self.currentColor() return copy_style def setRefcaseStyle(self, style): """ @type style: PlotStyle """ self._refcase_style.line_style = style.line_style self._refcase_style.marker = style.marker self._refcase_style.width = style.width self._refcase_style.size = style.size def setHistoryStyle(self, style): """ @type style: PlotStyle """ self._history_style.line_style = style.line_style self._history_style.marker = style.marker self._history_style.width = style.width self._history_style.size = style.size def setDefaultStyle(self, style): """ @type style: PlotStyle """ self._default_style.line_style = style.line_style self._default_style.marker = style.marker self._default_style.width = style.width self._default_style.size = style.size @property def limits(self): """ @rtype: PlotLimits """ limits = PlotLimits() limits.copyLimitsFrom(self._limits) return limits @limits.setter def limits(self, value): """ @type value: PlotLimits """ self._limits.copyLimitsFrom(value) def copyConfigFrom(self, other): """ :type other: PlotConfig """ self._default_style.copyStyleFrom(other._default_style, copy_enabled_state=True) self._refcase_style.copyStyleFrom(other._refcase_style, copy_enabled_state=True) self._history_style.copyStyleFrom(other._history_style, copy_enabled_state=True) self._histogram_style.copyStyleFrom(other._histogram_style, copy_enabled_state=True) self._observation_style.copyStyleFrom(other._observation_style, copy_enabled_state=True) self._distribution_style.copyStyleFrom(other._distribution_style, copy_enabled_state=True) self._distribution_line_style.copyStyleFrom(other._distribution_line_style, copy_enabled_state=True) self._statistics_style["mean"].copyStyleFrom(other._statistics_style["mean"], copy_enabled_state=True) self._statistics_style["p50"].copyStyleFrom(other._statistics_style["p50"], copy_enabled_state=True) self._statistics_style["min-max"].copyStyleFrom(other._statistics_style["min-max"], copy_enabled_state=True) self._statistics_style["p10-p90"].copyStyleFrom(other._statistics_style["p10-p90"], copy_enabled_state=True) self._statistics_style["p33-p67"].copyStyleFrom(other._statistics_style["p33-p67"], copy_enabled_state=True) self._statistics_style["std"].copyStyleFrom(other._statistics_style["std"], copy_enabled_state=True) self._std_dev_factor = other._std_dev_factor self._legend_enabled = other._legend_enabled self._grid_enabled = other._grid_enabled self.setLineColorCycle(other._line_color_cycle_colors) self._legend_items = other._legend_items[:] self._legend_labels = other._legend_labels[:] self._x_label = other._x_label self._y_label = other._y_label self._limits.copyLimitsFrom(other._limits) if other._title is not None: self._title = other._title @classmethod def createCopy(cls, other): copy = PlotConfig(None) copy.copyConfigFrom(other) return copy
def getStatisticsStyle(self, statistic): style = self._statistics_style[statistic] copy_style = PlotStyle(style.name) copy_style.copyStyleFrom(style) copy_style.color = self.currentColor() return copy_style
def distributionStyle(self): """@rtype: PlotStyle""" style = PlotStyle("Distribution Style") style.copyStyleFrom(self._distribution_style) style.color = self.currentColor() return style
def historyStyle(self): """@rtype: PlotStyle""" style = PlotStyle("History Style") style.copyStyleFrom(self._history_style) return style
def observationsStyle(self): """@rtype: PlotStyle""" style = PlotStyle("Observations Style") style.copyStyleFrom(self._observs_style) return style
def distributionLineStyle(self): """ @rtype: ert_gui.plottery.PlotStyle """ style = PlotStyle("Distribution Line Style") style.copyStyleFrom(self.__distribution_line_style) return style
class StyleChooser(QWidget): def __init__(self, area_supported=False): QWidget.__init__(self) self._style = PlotStyle("StyleChooser Internal Style") self._styles = STYLES if area_supported else STYLES_LINE_ONLY self.setMinimumWidth(140) self.setMaximumHeight(25) layout = QHBoxLayout() layout.setMargin(0) layout.setSpacing(2) self.line_chooser = QComboBox() self.line_chooser.setToolTip("Select line style.") for style in self._styles: self.line_chooser.addItem(*style) self.marker_chooser = QComboBox() self.marker_chooser.setToolTip("Select marker style.") for marker in MARKERS: self.marker_chooser.addItem(*marker) self.thickness_spinner = QDoubleSpinBox() self.thickness_spinner.setToolTip("Line thickness") self.thickness_spinner.setMinimum(0.1) self.thickness_spinner.setDecimals(1) self.thickness_spinner.setSingleStep(0.1) self.size_spinner = QDoubleSpinBox() self.size_spinner.setToolTip("Marker Size") self.size_spinner.setMinimum(0.1) self.size_spinner.setDecimals(1) self.size_spinner.setSingleStep(0.1) layout.addWidget(self.line_chooser) layout.addWidget(self.thickness_spinner) layout.addWidget(self.marker_chooser) layout.addWidget(self.size_spinner) self.setLayout(layout) self.line_chooser.currentIndexChanged.connect(self._updateStyle) self.marker_chooser.currentIndexChanged.connect(self._updateStyle) self.thickness_spinner.valueChanged.connect(self._updateStyle) self.size_spinner.valueChanged.connect(self._updateStyle) self._updateLineStyleAndMarker(self._style.line_style, self._style.marker, self._style.width, self._style.size) self._layout = layout def getItemSizes(self): line_style_combo_width = self._layout.itemAt(0).sizeHint().width() thickness_spinner_width = self._layout.itemAt(1).sizeHint().width() marker_combo_width = self._layout.itemAt(2).sizeHint().width() size_spinner_width = self._layout.itemAt(3).sizeHint().width() return line_style_combo_width, thickness_spinner_width, marker_combo_width, size_spinner_width def _findLineStyleIndex(self, line_style): for index, style in enumerate(self._styles): if style[1] == line_style: return index elif style[1] is None and line_style == "": return index return -1 def _findMarkerStyleIndex(self, marker): for index, style in enumerate(MARKERS): if style[1] == marker: return index elif style[1] is None and marker == "": return index return -1 def _updateLineStyleAndMarker(self, line_style, marker, thickness, size): self.line_chooser.setCurrentIndex(self._findLineStyleIndex(line_style)) self.marker_chooser.setCurrentIndex(self._findMarkerStyleIndex(marker)) self.thickness_spinner.setValue(thickness) self.size_spinner.setValue(size) def _updateStyle(self): self.marker_chooser.setEnabled(self.line_chooser.currentText() != "Area") line_style = self.line_chooser.itemData(self.line_chooser.currentIndex()) marker_style = self.marker_chooser.itemData(self.marker_chooser.currentIndex()) thickness = float(self.thickness_spinner.value()) size = float(self.size_spinner.value()) self._style.line_style = str(line_style.toString()) self._style.marker = str(marker_style.toString()) self._style.width = thickness self._style.size = size def setStyle(self, style): """ @type style: PlotStyle """ self._style.copyStyleFrom(style) self._updateLineStyleAndMarker(style.line_style, style.marker, style.width, style.size) def getStyle(self): """ @rtype: PlotStyle """ style = PlotStyle("Generated Style from StyleChooser") style.copyStyleFrom(self._style) return style def createLabelLayout(self, layout=None): if layout is None: layout = QHBoxLayout() titles = ["Line Style", "Width", "Marker Style", "Size"] sizes = self.getItemSizes() for title, size in zip(titles, sizes): label = QLabel(title) label.setFixedWidth(size) layout.addWidget(label) return layout
def getStyle(self): """ @rtype: PlotStyle """ style = PlotStyle("Generated Style from StyleChooser") style.copyStyleFrom(self._style) return style
class StyleChooser(QWidget): def __init__(self, line_style_set=STYLESET_DEFAULT): QWidget.__init__(self) self._style = PlotStyle("StyleChooser internal style") self._styles = (STYLES["default"] if line_style_set not in STYLES else STYLES[line_style_set]) self.setMinimumWidth(140) self.setMaximumHeight(25) layout = QHBoxLayout() layout.setContentsMargins(0, 0, 0, 0) layout.setSpacing(2) self.line_chooser = QComboBox() self.line_chooser.setToolTip("Select line style.") for style in self._styles: self.line_chooser.addItem(*style) self.marker_chooser = QComboBox() self.marker_chooser.setToolTip("Select marker style.") for marker in MARKERS: self.marker_chooser.addItem(*marker) self.thickness_spinner = QDoubleSpinBox() self.thickness_spinner.setToolTip("Line thickness") self.thickness_spinner.setMinimum(0.1) self.thickness_spinner.setDecimals(1) self.thickness_spinner.setSingleStep(0.1) self.size_spinner = QDoubleSpinBox() self.size_spinner.setToolTip("Marker size") self.size_spinner.setMinimum(0.1) self.size_spinner.setDecimals(1) self.size_spinner.setSingleStep(0.1) # the text content of the spinner varies, but shouldn't push the control # out of boundaries self.line_chooser.setMinimumWidth(110) layout.addWidget(self.line_chooser) layout.addWidget(self.thickness_spinner) layout.addWidget(self.marker_chooser) layout.addWidget(self.size_spinner) self.setLayout(layout) self.line_chooser.currentIndexChanged.connect(self._updateStyle) self.marker_chooser.currentIndexChanged.connect(self._updateStyle) self.thickness_spinner.valueChanged.connect(self._updateStyle) self.size_spinner.valueChanged.connect(self._updateStyle) self._updateLineStyleAndMarker( self._style.line_style, self._style.marker, self._style.width, self._style.size, ) self._layout = layout def getItemSizes(self): line_style_combo_width = self._layout.itemAt(0).sizeHint().width() thickness_spinner_width = self._layout.itemAt(1).sizeHint().width() marker_combo_width = self._layout.itemAt(2).sizeHint().width() size_spinner_width = self._layout.itemAt(3).sizeHint().width() return ( line_style_combo_width, thickness_spinner_width, marker_combo_width, size_spinner_width, ) def _findLineStyleIndex(self, line_style): for index, style in enumerate(self._styles): if style[1] == line_style: return index elif style[1] is None and line_style == "": return index return -1 def _findMarkerStyleIndex(self, marker): for index, style in enumerate(MARKERS): if style[1] == marker: return index elif style[1] is None and marker == "": return index return -1 def _updateLineStyleAndMarker(self, line_style, marker, thickness, size): self.line_chooser.setCurrentIndex(self._findLineStyleIndex(line_style)) self.marker_chooser.setCurrentIndex(self._findMarkerStyleIndex(marker)) self.thickness_spinner.setValue(thickness) self.size_spinner.setValue(size) def _updateStyle(self): self.marker_chooser.setEnabled( self.line_chooser.currentText() != "Area") line_style = self.line_chooser.itemData( self.line_chooser.currentIndex()) marker_style = self.marker_chooser.itemData( self.marker_chooser.currentIndex()) thickness = float(self.thickness_spinner.value()) size = float(self.size_spinner.value()) self._style.line_style = line_style self._style.marker = marker_style self._style.width = thickness self._style.size = size def setStyle(self, style): """@type style: PlotStyle""" self._style.copyStyleFrom(style) self._updateLineStyleAndMarker(style.line_style, style.marker, style.width, style.size) def getStyle(self): """@rtype: PlotStyle""" style = PlotStyle("Generated style from StyleChooser") style.copyStyleFrom(self._style) return style def createLabelLayout(self, layout=None): if layout is None: layout = QHBoxLayout() titles = ["Line style", "Width", "Marker style", "Size"] sizes = self.getItemSizes() for title, size in zip(titles, sizes): label = QLabel(title) label.setFixedWidth(size) layout.addWidget(label) return layout
def getStyle(self): """@rtype: PlotStyle""" style = PlotStyle("Generated style from StyleChooser") style.copyStyleFrom(self._style) return style
class PlotConfig(object): def __init__(self, title="Unnamed", x_label=None, y_label=None): super(PlotConfig, self).__init__() self._title = title self._line_color_cycle_colors = ["#000000"] self._line_color_cycle = itertools.cycle( self._line_color_cycle_colors) #Black # Blueish, Greenlike, Beigeoid, Pinkness, Orangy-Brown self.setLineColorCycle( ["#386CB0", "#7FC97F", "#FDC086", "#F0027F", "#BF5B17"]) self._legend_items = [] self._legend_labels = [] self._x_label = x_label self._y_label = y_label self._limits = PlotLimits() self._default_style = PlotStyle(name="Default", color=None, alpha=0.8) self._refcase_style = PlotStyle(name="Refcase", alpha=0.8, marker="x", width=2.0) self._history_style = PlotStyle(name="History", alpha=0.8, marker="D", width=2.0) # Insanely ugly implementation of user preferences. if os.getenv("ERT_SHOW_HISTORY_VECTORS"): self._history_style.setEnabled(True) else: self._history_style.setEnabled(False) self._observation_style = PlotStyle(name="Observations") self._histogram_style = PlotStyle(name="Histogram", width=2.0) self._distribution_style = PlotStyle(name="Distribution", line_style="", marker="o", alpha=0.5, size=10.0) self._distribution_line_style = PlotStyle(name="Distribution Lines", line_style="-", alpha=0.25, width=1.0) self._distribution_line_style.setEnabled(False) self._current_color = None self._legend_enabled = True self._grid_enabled = True self._statistics_style = { "mean": PlotStyle("Mean", line_style=""), "p50": PlotStyle("P50", line_style=""), "min-max": PlotStyle("Min/Max", line_style=""), "p10-p90": PlotStyle("P10-P90", line_style=""), "p33-p67": PlotStyle("P33-P67", line_style=""), "std": PlotStyle("Std dev", line_style="") } self._std_dev_factor = 1 # sigma 1 is default std dev def currentColor(self): if self._current_color is None: self.nextColor() return self._current_color def nextColor(self): self._current_color = self._line_color_cycle.next() return self._current_color def setLineColorCycle(self, color_list): self._line_color_cycle_colors = color_list self._line_color_cycle = itertools.cycle(color_list) def lineColorCycle(self): return list(self._line_color_cycle_colors) def addLegendItem(self, label, item): self._legend_items.append(item) self._legend_labels.append(label) def title(self): """ :rtype: str """ return self._title if self._title is not None else "Unnamed" def setTitle(self, title): self._title = title def isUnnamed(self): return self._title is None def defaultStyle(self): style = PlotStyle("Default Style") style.copyStyleFrom(self._default_style) style.color = self.currentColor() return style def observationsStyle(self): """ @rtype: PlotStyle """ style = PlotStyle("Observations Style") style.copyStyleFrom(self._observation_style) return style def refcaseStyle(self): """ @rtype: PlotStyle """ style = PlotStyle("Refcase Style") style.copyStyleFrom(self._refcase_style) return style def historyStyle(self): """ @rtype: PlotStyle """ style = PlotStyle("History Style") style.copyStyleFrom(self._history_style) return style def histogramStyle(self): """ @rtype: PlotStyle """ style = PlotStyle("Histogram Style") style.copyStyleFrom(self._histogram_style) style.color = self.currentColor() return style def distributionStyle(self): """ @rtype: PlotStyle """ style = PlotStyle("Distribution Style") style.copyStyleFrom(self._distribution_style) style.color = self.currentColor() return style def distributionLineStyle(self): """ @rtype: ert_gui.plottery.PlotStyle """ style = PlotStyle("Distribution Line Style") style.copyStyleFrom(self._distribution_line_style) return style def xLabel(self): return self._x_label def yLabel(self): return self._y_label def legendItems(self): return self._legend_items def legendLabels(self): return self._legend_labels def setXLabel(self, label): self._x_label = label def setYLabel(self, label): self._y_label = label def setObservationsEnabled(self, enabled): self._observation_style.setEnabled(enabled) def isObservationsEnabled(self): return self._observation_style.isEnabled() def setRefcaseEnabled(self, enabled): self._refcase_style.setEnabled(enabled) def isRefcaseEnabled(self): return self._refcase_style.isEnabled() def setHistoryEnabled(self, enabled): self._history_style.setEnabled(enabled) def isHistoryEnabled(self): return self._history_style.isEnabled() def isLegendEnabled(self): return self._legend_enabled def isDistributionLineEnabled(self): return self._distribution_line_style.isEnabled() def setDistributionLineEnabled(self, enabled): self._distribution_line_style.setEnabled(enabled) def setStandardDeviationFactor(self, value): self._std_dev_factor = value def getStandardDeviationFactor(self): return self._std_dev_factor def setLegendEnabled(self, enabled): self._legend_enabled = enabled def isGridEnabled(self): return self._grid_enabled def setGridEnabled(self, enabled): self._grid_enabled = enabled def setStatisticsStyle(self, statistic, style): """ @type statistic: str @type style: PlotStyle """ statistics_style = self._statistics_style[statistic] statistics_style.line_style = style.line_style statistics_style.marker = style.marker statistics_style.width = style.width statistics_style.size = style.size def getStatisticsStyle(self, statistic): style = self._statistics_style[statistic] copy_style = PlotStyle(style.name) copy_style.copyStyleFrom(style) copy_style.color = self.currentColor() return copy_style def setRefcaseStyle(self, style): """ @type style: PlotStyle """ self._refcase_style.line_style = style.line_style self._refcase_style.marker = style.marker self._refcase_style.width = style.width self._refcase_style.size = style.size def setHistoryStyle(self, style): """ @type style: PlotStyle """ self._history_style.line_style = style.line_style self._history_style.marker = style.marker self._history_style.width = style.width self._history_style.size = style.size def setDefaultStyle(self, style): """ @type style: PlotStyle """ self._default_style.line_style = style.line_style self._default_style.marker = style.marker self._default_style.width = style.width self._default_style.size = style.size @property def limits(self): """ @rtype: PlotLimits """ limits = PlotLimits() limits.copyLimitsFrom(self._limits) return limits @limits.setter def limits(self, value): """ @type value: PlotLimits """ self._limits.copyLimitsFrom(value) def copyConfigFrom(self, other): """ :type other: PlotConfig """ self._default_style.copyStyleFrom(other._default_style, copy_enabled_state=True) self._refcase_style.copyStyleFrom(other._refcase_style, copy_enabled_state=True) self._history_style.copyStyleFrom(other._history_style, copy_enabled_state=True) self._histogram_style.copyStyleFrom(other._histogram_style, copy_enabled_state=True) self._observation_style.copyStyleFrom(other._observation_style, copy_enabled_state=True) self._distribution_style.copyStyleFrom(other._distribution_style, copy_enabled_state=True) self._distribution_line_style.copyStyleFrom( other._distribution_line_style, copy_enabled_state=True) self._statistics_style["mean"].copyStyleFrom( other._statistics_style["mean"], copy_enabled_state=True) self._statistics_style["p50"].copyStyleFrom( other._statistics_style["p50"], copy_enabled_state=True) self._statistics_style["min-max"].copyStyleFrom( other._statistics_style["min-max"], copy_enabled_state=True) self._statistics_style["p10-p90"].copyStyleFrom( other._statistics_style["p10-p90"], copy_enabled_state=True) self._statistics_style["p33-p67"].copyStyleFrom( other._statistics_style["p33-p67"], copy_enabled_state=True) self._statistics_style["std"].copyStyleFrom( other._statistics_style["std"], copy_enabled_state=True) self._std_dev_factor = other._std_dev_factor self._legend_enabled = other._legend_enabled self._grid_enabled = other._grid_enabled self.setLineColorCycle(other._line_color_cycle_colors) self._legend_items = other._legend_items[:] self._legend_labels = other._legend_labels[:] self._x_label = other._x_label self._y_label = other._y_label self._limits.copyLimitsFrom(other._limits) if other._title is not None: self._title = other._title @classmethod def createCopy(cls, other): copy = PlotConfig(None) copy.copyConfigFrom(other) return copy
class StyleChooser(QWidget): def __init__(self, area_supported=False): QWidget.__init__(self) self._style = PlotStyle("StyleChooser Internal Style") self._styles = STYLES if area_supported else STYLES_LINE_ONLY self.setMinimumWidth(140) self.setMaximumHeight(25) layout = QHBoxLayout() layout.setMargin(0) layout.setSpacing(2) self.line_chooser = QComboBox() self.line_chooser.setToolTip("Select line style.") for style in self._styles: self.line_chooser.addItem(*style) self.marker_chooser = QComboBox() self.marker_chooser.setToolTip("Select marker style.") for marker in MARKERS: self.marker_chooser.addItem(*marker) self.thickness_spinner = QDoubleSpinBox() self.thickness_spinner.setToolTip("Line thickness") self.thickness_spinner.setMinimum(0.1) self.thickness_spinner.setDecimals(1) self.thickness_spinner.setSingleStep(0.1) self.size_spinner = QDoubleSpinBox() self.size_spinner.setToolTip("Marker Size") self.size_spinner.setMinimum(0.1) self.size_spinner.setDecimals(1) self.size_spinner.setSingleStep(0.1) layout.addWidget(self.line_chooser) layout.addWidget(self.thickness_spinner) layout.addWidget(self.marker_chooser) layout.addWidget(self.size_spinner) self.setLayout(layout) self.line_chooser.currentIndexChanged.connect(self._updateStyle) self.marker_chooser.currentIndexChanged.connect(self._updateStyle) self.thickness_spinner.valueChanged.connect(self._updateStyle) self.size_spinner.valueChanged.connect(self._updateStyle) self._updateLineStyleAndMarker(self._style.line_style, self._style.marker, self._style.width, self._style.size) self._layout = layout def getItemSizes(self): line_style_combo_width = self._layout.itemAt(0).sizeHint().width() thickness_spinner_width = self._layout.itemAt(1).sizeHint().width() marker_combo_width = self._layout.itemAt(2).sizeHint().width() size_spinner_width = self._layout.itemAt(3).sizeHint().width() return line_style_combo_width, thickness_spinner_width, marker_combo_width, size_spinner_width def _findLineStyleIndex(self, line_style): for index, style in enumerate(self._styles): if style[1] == line_style: return index elif style[1] is None and line_style == "": return index return -1 def _findMarkerStyleIndex(self, marker): for index, style in enumerate(MARKERS): if style[1] == marker: return index elif style[1] is None and marker == "": return index return -1 def _updateLineStyleAndMarker(self, line_style, marker, thickness, size): self.line_chooser.setCurrentIndex(self._findLineStyleIndex(line_style)) self.marker_chooser.setCurrentIndex(self._findMarkerStyleIndex(marker)) self.thickness_spinner.setValue(thickness) self.size_spinner.setValue(size) def _updateStyle(self): self.marker_chooser.setEnabled( self.line_chooser.currentText() != "Area") line_style = self.line_chooser.itemData( self.line_chooser.currentIndex()) marker_style = self.marker_chooser.itemData( self.marker_chooser.currentIndex()) thickness = float(self.thickness_spinner.value()) size = float(self.size_spinner.value()) self._style.line_style = str(line_style.toString()) self._style.marker = str(marker_style.toString()) self._style.width = thickness self._style.size = size def setStyle(self, style): """ @type style: PlotStyle """ self._style.copyStyleFrom(style) self._updateLineStyleAndMarker(style.line_style, style.marker, style.width, style.size) def getStyle(self): """ @rtype: PlotStyle """ style = PlotStyle("Generated Style from StyleChooser") style.copyStyleFrom(self._style) return style def createLabelLayout(self, layout=None): if layout is None: layout = QHBoxLayout() titles = ["Line Style", "Width", "Marker Style", "Size"] sizes = self.getItemSizes() for title, size in zip(titles, sizes): label = QLabel(title) label.setFixedWidth(size) layout.addWidget(label) return layout
def getStatisticsStyle(self, statistic): style = self.__statistics_style[statistic] copy_style = PlotStyle(style.name) copy_style.copyStyleFrom(style) copy_style.color = self.currentColor() return copy_style
def defaultStyle(self): style = PlotStyle("Default Style") style.copyStyleFrom(self._default_style) style.color = self.currentColor() return style
class PlotConfig(object): def __init__(self, title="Unnamed", x_label=None, y_label=None): super(PlotConfig, self).__init__() self.__title = title self.__line_color_cycle_colors = ["#000000"] self.__line_color_cycle = itertools.cycle(self.__line_color_cycle_colors) #Black # Blueish, Greenlike, Beigeoid, Pinkness, Orangy-Brown self.setLineColorCycle(["#386CB0", "#7FC97F", "#FDC086", "#F0027F", "#BF5B17"]) self.__legend_items = [] self.__legend_labels = [] self.__x_label = x_label self.__y_label = y_label self.__default_style = PlotStyle(name="Default", color=None, alpha=0.8) self.__refcase_style = PlotStyle(name="Refcase", alpha=0.8, marker="x", width=2.0) self.__observation_style = PlotStyle(name="Observations") self.__histogram_style = PlotStyle(name="Histogram", width=2.0) self.__distribution_style = PlotStyle(name="Distribution", line_style="", marker="o", alpha=0.5, width=10.0) self.__distribution_line_style = PlotStyle(name="Distribution Lines", line_style="-", alpha=0.25, width=1.0) self.__distribution_line_style.setEnabled(False) self.__current_color = None self.__legend_enabled = True self.__grid_enabled = True self.__date_support_active = True self.__statistics_style = { "mean": PlotStyle("Mean", line_style=""), "p50": PlotStyle("P50", line_style=""), "min-max": PlotStyle("Min/Max", line_style=""), "p10-p90": PlotStyle("P10-P90", line_style=""), "p33-p67": PlotStyle("P33-P67", line_style="") } def currentColor(self): if self.__current_color is None: self.nextColor() return self.__current_color def nextColor(self): self.__current_color = self.__line_color_cycle.next() return self.__current_color def setLineColorCycle(self, color_list): self.__line_color_cycle_colors = color_list self.__line_color_cycle = itertools.cycle(color_list) def addLegendItem(self, label, item): self.__legend_items.append(item) self.__legend_labels.append(label) def title(self): """ :rtype: str """ return self.__title if self.__title is not None else "Unnamed" def setTitle(self, title): self.__title = title def isUnnamed(self): return self.__title is None def defaultStyle(self): style = PlotStyle("Default Style") style.copyStyleFrom(self.__default_style) style.color = self.currentColor() return style def observationsStyle(self): """ @rtype: PlotStyle """ style = PlotStyle("Observations Style") style.copyStyleFrom(self.__observation_style) return style def refcaseStyle(self): """ @rtype: PlotStyle """ style = PlotStyle("Refcase Style") style.copyStyleFrom(self.__refcase_style) return style def histogramStyle(self): """ @rtype: PlotStyle """ style = PlotStyle("Histogram Style") style.copyStyleFrom(self.__histogram_style) style.color = self.currentColor() return style def distributionStyle(self): """ @rtype: PlotStyle """ style = PlotStyle("Distribution Style") style.copyStyleFrom(self.__distribution_style) style.color = self.currentColor() return style def distributionLineStyle(self): """ @rtype: ert_gui.plottery.PlotStyle """ style = PlotStyle("Distribution Line Style") style.copyStyleFrom(self.__distribution_line_style) return style def xLabel(self): return self.__x_label def yLabel(self): return self.__y_label def legendItems(self): return self.__legend_items def legendLabels(self): return self.__legend_labels def setXLabel(self, label): self.__x_label = label def setYLabel(self, label): self.__y_label = label def setObservationsEnabled(self, enabled): self.__observation_style.setEnabled(enabled) def isObservationsEnabled(self): return self.__observation_style.isEnabled() def setRefcaseEnabled(self, enabled): self.__refcase_style.setEnabled(enabled) def isRefcaseEnabled(self): return self.__refcase_style.isEnabled() def isLegendEnabled(self): return self.__legend_enabled def isDistributionLineEnabled(self): return self.__distribution_line_style.isEnabled() def setDistributionLineEnabled(self, enabled): self.__distribution_line_style.setEnabled(enabled) def setLegendEnabled(self, enabled): self.__legend_enabled = enabled def isGridEnabled(self): return self.__grid_enabled def setGridEnabled(self, enabled): self.__grid_enabled = enabled def deactivateDateSupport(self): self.__date_support_active = False def isDateSupportActive(self): return self.__date_support_active def setStatisticsStyle(self, statistic, line_style, marker): style = self.__statistics_style[statistic] style.line_style = line_style style.marker = marker def getStatisticsStyle(self, statistic): style = self.__statistics_style[statistic] copy_style = PlotStyle(style.name) copy_style.copyStyleFrom(style) copy_style.color = self.currentColor() return copy_style def setRefcaseStyle(self, line_style, marker): self.__refcase_style.line_style = line_style self.__refcase_style.marker = marker def setDefaultStyle(self, line_style, marker): self.__default_style.line_style = line_style self.__default_style.marker = marker def copyConfigFrom(self, other): """ :type other: PlotConfig """ self.__default_style.copyStyleFrom(other.__default_style, copy_enabled_state=True) self.__refcase_style.copyStyleFrom(other.__refcase_style, copy_enabled_state=True) self.__histogram_style.copyStyleFrom(other.__histogram_style, copy_enabled_state=True) self.__observation_style.copyStyleFrom(other.__observation_style, copy_enabled_state=True) self.__distribution_style.copyStyleFrom(other.__distribution_style, copy_enabled_state=True) self.__distribution_line_style.copyStyleFrom(other.__distribution_line_style, copy_enabled_state=True) self.__statistics_style["mean"].copyStyleFrom(other.__statistics_style["mean"], copy_enabled_state=True) self.__statistics_style["p50"].copyStyleFrom(other.__statistics_style["p50"], copy_enabled_state=True) self.__statistics_style["min-max"].copyStyleFrom(other.__statistics_style["min-max"], copy_enabled_state=True) self.__statistics_style["p10-p90"].copyStyleFrom(other.__statistics_style["p10-p90"], copy_enabled_state=True) self.__statistics_style["p33-p67"].copyStyleFrom(other.__statistics_style["p33-p67"], copy_enabled_state=True) self.__legend_enabled = other.__legend_enabled self.__grid_enabled = other.__grid_enabled self.__date_support_active = other.__date_support_active self.__line_color_cycle_colors = other.__line_color_cycle_colors[:] self.__legend_items = other.__legend_items[:] self.__legend_labels = other.__legend_labels[:] self.__x_label = other.__x_label self.__y_label = other.__y_label self.__title = other.__title
def refcaseStyle(self): """@rtype: PlotStyle""" style = PlotStyle("Refcase Style") style.copyStyleFrom(self._refcase_style) return style
def defaultStyle(self): style = PlotStyle("Default Style") style.copyStyleFrom(self.__default_style) style.color = self.currentColor() return style
def histogramStyle(self): """@rtype: PlotStyle""" style = PlotStyle("Histogram Style") style.copyStyleFrom(self._histogram_style) style.color = self.currentColor() return style
def observationsStyle(self): """ @rtype: PlotStyle """ style = PlotStyle("Observations Style") style.copyStyleFrom(self.__observation_style) return style
def distributionLineStyle(self): """@rtype: ert_gui.plottery.PlotStyle""" style = PlotStyle("Distribution Line Style") style.copyStyleFrom(self._distribution_line_style) return style
def refcaseStyle(self): """ @rtype: PlotStyle """ style = PlotStyle("Refcase Style") style.copyStyleFrom(self.__refcase_style) return style
class PlotConfig(object): # The plot_settings input argument is an internalisation of the (quite few) plot # policy settings which can be set in the configuration file. def __init__(self, plot_settings=None, title="Unnamed", x_label=None, y_label=None): self._title = title self._plot_settings = plot_settings if self._plot_settings is None: self._plot_settings = {"SHOW_REFCASE": True, "SHOW_HISTORY": True} self._line_color_cycle_colors = ["#000000"] self._line_color_cycle = itertools.cycle(self._line_color_cycle_colors) # Black # Blueish, Greenlike, Beigeoid, Pinkness, Orangy-Brown self.setLineColorCycle(["#386CB0", "#7FC97F", "#FDC086", "#F0027F", "#BF5B17"]) # alternative color cycle: # ["#e41a1c", "#377eb8", "#4daf4a", "#984ea3", "#ff7f00", "#ffff33", # "#a65628", "#f781bf" ,"#386CB0", "#7FC97F", "#FDC086", "#F0027F", "#BF5B17"] self._legend_items = [] self._legend_labels = [] self._x_label = x_label self._y_label = y_label self._limits = PlotLimits() self._default_style = PlotStyle( name="Default", color=None, marker="", alpha=0.8 ) self._refcase_style = PlotStyle( name="Refcase", alpha=0.8, line_style="--", marker="", width=2.0, enabled=self._plot_settings["SHOW_REFCASE"], ) self._history_style = PlotStyle( name="History", alpha=0.8, marker=".", width=2.0, enabled=self._plot_settings["SHOW_HISTORY"], ) self._observs_style = PlotStyle( name="Observations", line_style="-", alpha=0.8, marker=".", width=1.0, color="#000000", ) self._histogram_style = PlotStyle(name="Histogram", width=2.0) self._distribution_style = PlotStyle( name="Distribution", line_style="", marker="o", alpha=0.5, size=10.0 ) self._distribution_line_style = PlotStyle( name="Distribution Lines", line_style="-", alpha=0.25, width=1.0 ) self._distribution_line_style.setEnabled(False) self._current_color = None self._legend_enabled = True self._grid_enabled = True self._statistics_style = { "mean": PlotStyle("Mean", line_style=""), "p50": PlotStyle("P50", line_style=""), "min-max": PlotStyle("Min/Max", line_style=""), "p10-p90": PlotStyle("P10-P90", line_style=""), "p33-p67": PlotStyle("P33-P67", line_style=""), "std": PlotStyle("Std dev", line_style=""), } self._std_dev_factor = 1 # sigma 1 is default std dev def currentColor(self): if self._current_color is None: self.nextColor() return self._current_color def nextColor(self): self._current_color = next(self._line_color_cycle) return self._current_color def setLineColorCycle(self, color_list): self._line_color_cycle_colors = color_list self._line_color_cycle = itertools.cycle(color_list) def lineColorCycle(self): return list(self._line_color_cycle_colors) def addLegendItem(self, label, item): self._legend_items.append(item) self._legend_labels.append(label) def title(self): """:rtype: str""" return self._title if self._title is not None else "Unnamed" def setTitle(self, title): self._title = title def isUnnamed(self): return self._title is None def defaultStyle(self): style = PlotStyle("Default Style") style.copyStyleFrom(self._default_style) style.color = self.currentColor() return style def observationsColor(self): return self._observs_style.color def observationsStyle(self): """@rtype: PlotStyle""" style = PlotStyle("Observations Style") style.copyStyleFrom(self._observs_style) return style def refcaseStyle(self): """@rtype: PlotStyle""" style = PlotStyle("Refcase Style") style.copyStyleFrom(self._refcase_style) return style def historyStyle(self): """@rtype: PlotStyle""" style = PlotStyle("History Style") style.copyStyleFrom(self._history_style) return style def histogramStyle(self): """@rtype: PlotStyle""" style = PlotStyle("Histogram Style") style.copyStyleFrom(self._histogram_style) style.color = self.currentColor() return style def distributionStyle(self): """@rtype: PlotStyle""" style = PlotStyle("Distribution Style") style.copyStyleFrom(self._distribution_style) style.color = self.currentColor() return style def distributionLineStyle(self): """@rtype: ert_gui.plottery.PlotStyle""" style = PlotStyle("Distribution Line Style") style.copyStyleFrom(self._distribution_line_style) return style def xLabel(self): return self._x_label def yLabel(self): return self._y_label def legendItems(self): return self._legend_items def legendLabels(self): return self._legend_labels def setXLabel(self, label): self._x_label = label def setYLabel(self, label): self._y_label = label def setObservationsEnabled(self, enabled): self._observs_style.setEnabled(enabled) def isObservationsEnabled(self): return self._observs_style.isEnabled() def setRefcaseEnabled(self, enabled): self._refcase_style.setEnabled(enabled) def isRefcaseEnabled(self): return self._refcase_style.isEnabled() def setHistoryEnabled(self, enabled): self._history_style.setEnabled(enabled) def isHistoryEnabled(self): return self._history_style.isEnabled() def isLegendEnabled(self): return self._legend_enabled def isDistributionLineEnabled(self): return self._distribution_line_style.isEnabled() def setDistributionLineEnabled(self, enabled): self._distribution_line_style.setEnabled(enabled) def setStandardDeviationFactor(self, value): self._std_dev_factor = value def getStandardDeviationFactor(self): return self._std_dev_factor def setLegendEnabled(self, enabled): self._legend_enabled = enabled def isGridEnabled(self): return self._grid_enabled def setGridEnabled(self, enabled): self._grid_enabled = enabled def setStatisticsStyle(self, statistic, style): """ @type statistic: str @type style: PlotStyle """ statistics_style = self._statistics_style[statistic] statistics_style.line_style = style.line_style statistics_style.marker = style.marker statistics_style.width = style.width statistics_style.size = style.size def getStatisticsStyle(self, statistic): style = self._statistics_style[statistic] copy_style = PlotStyle(style.name) copy_style.copyStyleFrom(style) copy_style.color = self.currentColor() return copy_style def setRefcaseStyle(self, style): """@type style: PlotStyle""" self._refcase_style.line_style = style.line_style self._refcase_style.marker = style.marker self._refcase_style.width = style.width self._refcase_style.size = style.size def setHistoryStyle(self, style): """@type style: PlotStyle""" self._history_style.line_style = style.line_style self._history_style.marker = style.marker self._history_style.width = style.width self._history_style.size = style.size def setObservationsColor(self, color): self._observs_style.color = color def setObservationsStyle(self, style): """@type style: PlotStyle""" self._observs_style.line_style = style.line_style self._observs_style.marker = style.marker self._observs_style.width = style.width self._observs_style.size = style.size def setDefaultStyle(self, style): """@type style: PlotStyle""" self._default_style.line_style = style.line_style self._default_style.marker = style.marker self._default_style.width = style.width self._default_style.size = style.size @property def limits(self): """@rtype: PlotLimits""" limits = PlotLimits() limits.copyLimitsFrom(self._limits) return limits @limits.setter def limits(self, value): """@type value: PlotLimits""" self._limits.copyLimitsFrom(value) def copyConfigFrom(self, other): """ :type other: PlotConfig """ self._default_style.copyStyleFrom(other._default_style, copy_enabled_state=True) self._refcase_style.copyStyleFrom(other._refcase_style, copy_enabled_state=True) self._history_style.copyStyleFrom(other._history_style, copy_enabled_state=True) self._histogram_style.copyStyleFrom( other._histogram_style, copy_enabled_state=True ) self._observs_style.copyStyleFrom(other._observs_style, copy_enabled_state=True) self._distribution_style.copyStyleFrom( other._distribution_style, copy_enabled_state=True ) self._distribution_line_style.copyStyleFrom( other._distribution_line_style, copy_enabled_state=True ) self._statistics_style["mean"].copyStyleFrom( other._statistics_style["mean"], copy_enabled_state=True ) self._statistics_style["p50"].copyStyleFrom( other._statistics_style["p50"], copy_enabled_state=True ) self._statistics_style["min-max"].copyStyleFrom( other._statistics_style["min-max"], copy_enabled_state=True ) self._statistics_style["p10-p90"].copyStyleFrom( other._statistics_style["p10-p90"], copy_enabled_state=True ) self._statistics_style["p33-p67"].copyStyleFrom( other._statistics_style["p33-p67"], copy_enabled_state=True ) self._statistics_style["std"].copyStyleFrom( other._statistics_style["std"], copy_enabled_state=True ) self._std_dev_factor = other._std_dev_factor self._legend_enabled = other._legend_enabled self._grid_enabled = other._grid_enabled self.setLineColorCycle(other._line_color_cycle_colors) self._legend_items = other._legend_items[:] self._legend_labels = other._legend_labels[:] self._x_label = other._x_label self._y_label = other._y_label self._limits.copyLimitsFrom(other._limits) if other._title is not None: self._title = other._title @classmethod def createCopy(cls, other): copy = PlotConfig(other._plot_settings) copy.copyConfigFrom(other) return copy
def historyStyle(self): """ @rtype: PlotStyle """ style = PlotStyle("History Style") style.copyStyleFrom(self._history_style) return style