Skip to content

Commit

Permalink
Merge pull request #4828 from VesnaT/customize_plots
Browse files Browse the repository at this point in the history
[ENH] Projection plots: Customize labels
  • Loading branch information
ajdapretnar authored Jul 6, 2020
2 parents 2655592 + 0f0ae8e commit c11ec5e
Show file tree
Hide file tree
Showing 14 changed files with 815 additions and 143 deletions.
43 changes: 42 additions & 1 deletion Orange/widgets/evaluate/owcalibrationplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

import pyqtgraph as pg

from orangewidget.utils.visual_settings_dlg import VisualSettingsDialog

from Orange.base import Model
from Orange.classification import ThresholdClassifier, CalibratedLearner
from Orange.evaluation import Results
Expand All @@ -17,6 +19,9 @@
from Orange.widgets.evaluate.utils import results_for_preview
from Orange.widgets.utils import colorpalettes
from Orange.widgets.utils.widgetpreview import WidgetPreview
from Orange.widgets.visualize.utils.customizableplot import Updater, \
BaseParameterSetter as Setter
from Orange.widgets.visualize.utils.plotutils import AxisItem
from Orange.widgets.widget import Input, Output, Msg
from Orange.widgets import report

Expand Down Expand Up @@ -58,6 +63,32 @@
)]


class ParameterSetter(Setter):
initial_settings = {
Setter.LABELS_BOX: {
Setter.FONT_FAMILY_LABEL: Updater.FONT_FAMILY_SETTING,
Setter.TITLE_LABEL: Updater.FONT_SETTING,
Setter.AXIS_TITLE_LABEL: Updater.FONT_SETTING,
Setter.AXIS_TICKS_LABEL: Updater.FONT_SETTING,
},
Setter.ANNOT_BOX: {
Setter.TITLE_LABEL: {Setter.TITLE_LABEL: ("", "")},
}
}

@property
def title_item(self):
return self.titleLabel

@property
def axis_items(self):
return [value["item"] for value in self.axes.values()]


class PlotItem(pg.PlotItem, ParameterSetter):
pass


class OWCalibrationPlot(widget.OWWidget):
name = "Calibration Plot"
description = "Calibration plot based on evaluation of classifiers."
Expand Down Expand Up @@ -100,6 +131,7 @@ class Information(widget.OWWidget.Information):
fold_curves = settings.Setting(False)
display_rug = settings.Setting(True)
threshold = settings.Setting(0.5)
visual_settings = settings.Setting({}, schema_only=True)
auto_commit = settings.Setting(True)

graph_name = "plot"
Expand Down Expand Up @@ -157,7 +189,9 @@ def __init__(self):
gui.auto_apply(self.controlArea, self, "auto_commit", commit=self.apply)

self.plotview = pg.GraphicsView(background="w")
self.plot = pg.PlotItem(enableMenu=False)
axes = {"bottom": AxisItem(orientation="bottom"),
"left": AxisItem(orientation="left")}
self.plot = PlotItem(enableMenu=False, axisItems=axes)
self.plot.setMouseEnabled(False, False)
self.plot.hideButtons()

Expand All @@ -177,6 +211,8 @@ def __init__(self):
self.mainArea.layout().addWidget(self.plotview)
self._set_explanation()

VisualSettingsDialog(self, PlotItem.initial_settings)

@Inputs.evaluation_results
def set_results(self, results):
self.closeContext()
Expand Down Expand Up @@ -435,6 +471,7 @@ def elided(s):
text += "</tr>"
text += "<table>"
return text
return None

def _update_info(self):
self.info_label.setText(self.get_info_text(short=True))
Expand Down Expand Up @@ -498,6 +535,10 @@ def send_report(self):
if self.score != 0:
self.report_raw(self.get_info_text(short=False))

def set_visual_settings(self, key, value):
self.plot.set_parameter(key, value)
self.visual_settings[key] = value


def gaussian_smoother(x, y, sigma=1.0):
x = np.asarray(x)
Expand Down
9 changes: 4 additions & 5 deletions Orange/widgets/visualize/owboxplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,17 +174,16 @@ class Warning(widget.OWWidget.Warning):
_pen_axis_tick.setCapStyle(Qt.FlatCap)

_box_brush = QBrush(QColor(0x33, 0x88, 0xff, 0xc0))

_axis_font = QFont()
_axis_font.setPixelSize(12)
_label_font = QFont()
_label_font.setPixelSize(11)
_attr_brush = QBrush(QColor(0x33, 0x00, 0xff))

graph_name = "box_scene"

def __init__(self):
super().__init__()
self._axis_font = QFont()
self._axis_font.setPixelSize(12)
self._label_font = QFont()
self._label_font.setPixelSize(11)
self.dataset = None
self.stats = []
self.dist = self.conts = None
Expand Down
2 changes: 2 additions & 0 deletions Orange/widgets/visualize/owfreeviz.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,15 @@ def update_anchors(self):
anchor = AnchorItem(line=QLineF(0, 0, *point), text=label)
anchor.setVisible(np.linalg.norm(point) > r)
anchor.setPen(pg.mkPen((100, 100, 100)))
anchor.setFont(self.anchor_font)
self.plot_widget.addItem(anchor)
self.anchor_items.append(anchor)
else:
for anchor, point, label in zip(self.anchor_items, points, labels):
anchor.setLine(QLineF(0, 0, *point))
anchor.setText(label)
anchor.setVisible(np.linalg.norm(point) > r)
anchor.setFont(self.anchor_font)

def update_circle(self):
super().update_circle()
Expand Down
7 changes: 5 additions & 2 deletions Orange/widgets/visualize/owlinearprojection.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ def update_anchors(self):
anchor._label.setToolTip(f"<b>{label}</b>")
label = label[:MAX_LABEL_LEN - 3] + "..." if len(label) > MAX_LABEL_LEN else label
anchor.setText(label)
anchor.setFont(self.anchor_font)

visible = self.always_show_axes or np.linalg.norm(point) > r
anchor.setVisible(visible)
Expand All @@ -236,6 +237,7 @@ def update_anchors(self):
anchor.setLine(QLineF(0, 0, *point))
visible = self.always_show_axes or np.linalg.norm(point) > r
anchor.setVisible(visible)
anchor.setFont(self.anchor_font)

def update_circle(self):
super().update_circle()
Expand Down Expand Up @@ -544,5 +546,6 @@ def get_components(self, X, Y):


if __name__ == "__main__": # pragma: no cover
data = Table("iris")
WidgetPreview(OWLinearProjection).run(set_data=data, set_subset_data=data[::10])
iris = Table("iris")
WidgetPreview(OWLinearProjection).run(set_data=iris,
set_subset_data=iris[::10])
Loading

0 comments on commit c11ec5e

Please sign in to comment.