Skip to content

Commit

Permalink
Calibration Plot: Customizable labels
Browse files Browse the repository at this point in the history
  • Loading branch information
VesnaT committed Jun 4, 2020
1 parent 11fbd9f commit e4ded42
Showing 1 changed file with 41 additions and 2 deletions.
43 changes: 41 additions & 2 deletions Orange/widgets/evaluate/owcalibrationplot.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from collections import namedtuple
from collections import namedtuple, OrderedDict

import numpy as np

Expand All @@ -17,6 +17,8 @@
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 BaseSetter, \
AxisFontUpdater, Customizable
from Orange.widgets.widget import Input, Output, Msg
from Orange.widgets import report

Expand Down Expand Up @@ -58,13 +60,47 @@
)]


# Axis part
class AxisFontUpdater(AxisFontUpdater):
@property
def axis_items(self):
return [value["item"] for value in self.parent.axes.values()]


# Labels box
class FontSetter(BaseSetter, AxisFontUpdater):
def __init__(self, parent):
super().__init__(parent)
self.setter = {
self.FONT_FAMILY_LABEL: self._update_font_family,
self.AXIS_TITLE: self._update_axes_titles_font,
self.AXIS_TICKS: self._update_axes_ticks_font,
}


# Customizable plot item
class PlotItem(pg.PlotItem, Customizable):
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.setters = {self.BOXES[0]: FontSetter(self)}


class OWCalibrationPlot(widget.OWWidget):
name = "Calibration Plot"
description = "Calibration plot based on evaluation of classifiers."
icon = "icons/CalibrationPlot.svg"
priority = 1030
keywords = []

initial_visual_settings = OrderedDict({
PlotItem.BOXES[0]:
OrderedDict({name: values for name, values in (
(FontSetter.FONT_FAMILY_LABEL, FontSetter.FONT_FAMILY_SETTING),
(FontSetter.AXIS_TITLE, FontSetter.SETTING),
(FontSetter.AXIS_TICKS, {FontSetter.IS_ITALIC_LABEL: (None, False)}),
)})
})

class Inputs:
evaluation_results = Input("Evaluation Results", Results)

Expand Down Expand Up @@ -157,7 +193,7 @@ 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)
self.plot = PlotItem(enableMenu=False)
self.plot.setMouseEnabled(False, False)
self.plot.hideButtons()

Expand Down Expand Up @@ -498,6 +534,9 @@ def send_report(self):
if self.score != 0:
self.report_raw(self.get_info_text(short=False))

def set_visual_settings(self, *args):
self.plot.set_parameter(*args)


def gaussian_smoother(x, y, sigma=1.0):
x = np.asarray(x)
Expand Down

0 comments on commit e4ded42

Please sign in to comment.