Skip to content

Commit

Permalink
Merge pull request #3768 from VesnaT/fix_line_plot
Browse files Browse the repository at this point in the history
[FIX] OWLinePlot: legible bottom axis labels
  • Loading branch information
janezd authored May 17, 2019
2 parents ccd8a40 + 99573dc commit d72c4a5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
22 changes: 18 additions & 4 deletions Orange/widgets/visualize/owlineplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,18 @@ class LinePlotStyle:
MEAN_DARK_FACTOR = 110


class LinePlotAxisItem(pg.AxisItem):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self._ticks = {}

def set_ticks(self, ticks):
self._ticks = dict(enumerate(ticks, 1)) if ticks else {}

def tickStrings(self, values, scale, spacing):
return [self._ticks.get(v * scale, "") for v in values]


class LinePlotViewBox(ViewBox):
selection_changed = Signal(np.ndarray)

Expand Down Expand Up @@ -172,8 +184,10 @@ def reset(self):

class LinePlotGraph(pg.PlotWidget):
def __init__(self, parent):
self.bottom_axis = LinePlotAxisItem(orientation="bottom")
super().__init__(parent, viewBox=LinePlotViewBox(),
background="w", enableMenu=False)
background="w", enableMenu=False,
axisItems={"bottom": self.bottom_axis})
self.view_box = self.getViewBox()
self.selection = set()
self.legend = self._create_legend(((1, 0), (1, 0)))
Expand Down Expand Up @@ -213,7 +227,7 @@ def reset(self):
self.selection = set()
self.view_box.reset()
self.clear()
self.getAxis('bottom').setTicks(None)
self.getAxis('bottom').set_ticks(None)
self.legend.hide()

def select_button_clicked(self):
Expand Down Expand Up @@ -593,8 +607,8 @@ def setup_plot(self):
if self.data is None:
return

ticks = [[(i, a.name) for i, a in enumerate(self.graph_variables, 1)]]
self.graph.getAxis('bottom').setTicks(ticks)
ticks = [a.name for a in self.graph_variables]
self.graph.getAxis("bottom").set_ticks(ticks)
self.plot_groups()
self.apply_selection()
self.graph.view_box.enableAutoRange()
Expand Down
4 changes: 4 additions & 0 deletions Orange/widgets/visualize/tests/test_owlineplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,3 +290,7 @@ def test_lines_intersection(self):
for i in range(y.shape[1])])
i = line_intersects_profiles(a, b, table)
np.testing.assert_array_equal(np.array([False, True, True, True]), i)


if __name__ == "__main__":
unittest.main()

0 comments on commit d72c4a5

Please sign in to comment.