Skip to content

Commit d72c4a5

Browse files
authored
Merge pull request #3768 from VesnaT/fix_line_plot
[FIX] OWLinePlot: legible bottom axis labels
2 parents ccd8a40 + 99573dc commit d72c4a5

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

Orange/widgets/visualize/owlineplot.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,18 @@ class LinePlotStyle:
9191
MEAN_DARK_FACTOR = 110
9292

9393

94+
class LinePlotAxisItem(pg.AxisItem):
95+
def __init__(self, *args, **kwargs):
96+
super().__init__(*args, **kwargs)
97+
self._ticks = {}
98+
99+
def set_ticks(self, ticks):
100+
self._ticks = dict(enumerate(ticks, 1)) if ticks else {}
101+
102+
def tickStrings(self, values, scale, spacing):
103+
return [self._ticks.get(v * scale, "") for v in values]
104+
105+
94106
class LinePlotViewBox(ViewBox):
95107
selection_changed = Signal(np.ndarray)
96108

@@ -172,8 +184,10 @@ def reset(self):
172184

173185
class LinePlotGraph(pg.PlotWidget):
174186
def __init__(self, parent):
187+
self.bottom_axis = LinePlotAxisItem(orientation="bottom")
175188
super().__init__(parent, viewBox=LinePlotViewBox(),
176-
background="w", enableMenu=False)
189+
background="w", enableMenu=False,
190+
axisItems={"bottom": self.bottom_axis})
177191
self.view_box = self.getViewBox()
178192
self.selection = set()
179193
self.legend = self._create_legend(((1, 0), (1, 0)))
@@ -213,7 +227,7 @@ def reset(self):
213227
self.selection = set()
214228
self.view_box.reset()
215229
self.clear()
216-
self.getAxis('bottom').setTicks(None)
230+
self.getAxis('bottom').set_ticks(None)
217231
self.legend.hide()
218232

219233
def select_button_clicked(self):
@@ -593,8 +607,8 @@ def setup_plot(self):
593607
if self.data is None:
594608
return
595609

596-
ticks = [[(i, a.name) for i, a in enumerate(self.graph_variables, 1)]]
597-
self.graph.getAxis('bottom').setTicks(ticks)
610+
ticks = [a.name for a in self.graph_variables]
611+
self.graph.getAxis("bottom").set_ticks(ticks)
598612
self.plot_groups()
599613
self.apply_selection()
600614
self.graph.view_box.enableAutoRange()

Orange/widgets/visualize/tests/test_owlineplot.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,3 +290,7 @@ def test_lines_intersection(self):
290290
for i in range(y.shape[1])])
291291
i = line_intersects_profiles(a, b, table)
292292
np.testing.assert_array_equal(np.array([False, True, True, True]), i)
293+
294+
295+
if __name__ == "__main__":
296+
unittest.main()

0 commit comments

Comments
 (0)