Skip to content

Commit a1fbcc0

Browse files
committed
Update the time series label to inherit the line color only if it's not in the legend
1 parent 6aadec1 commit a1fbcc0

9 files changed

Lines changed: 45 additions & 13 deletions

File tree

examples/.ipynb_checkpoints/0. Styles-checkpoint.ipynb

Lines changed: 3 additions & 3 deletions
Large diffs are not rendered by default.

examples/.ipynb_checkpoints/3. Time series-checkpoint.ipynb

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

examples/0. Styles.ipynb

Lines changed: 3 additions & 3 deletions
Large diffs are not rendered by default.

examples/3. Time series.ipynb

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

examples/exports/3-time-series.png

-130 Bytes
Loading
1.07 KB
Binary file not shown.

multiplex/tests/test_time_series.py

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,22 @@ def test_label_style_legend(self):
5959
@MultiplexTest.temporary_plot
6060
def test_label_style_line(self):
6161
"""
62-
Test that when drawing a time series legend at the end of the line, the label style is used.
62+
Test that when drawing a time series label at the end of the line, the line color is used by default.
63+
"""
64+
65+
viz = drawable.Drawable(plt.figure(figsize=(10, 10)))
66+
line_style = { 'color': '#FF0000' }
67+
line, label = viz.draw_time_series([ 1 ] * 5, [ 1 ] * 5, label='A',
68+
**line_style, with_legend=False)
69+
70+
self.assertEqual(0, len(viz.legend.lines[0]))
71+
self.assertEqual('A', str(label))
72+
self.assertEqual(line_style['color'], label.lines[0][0].get_color())
73+
74+
@MultiplexTest.temporary_plot
75+
def test_label_style_line_override(self):
76+
"""
77+
Test that when drawing a time series label at the end of the line, the line style can override the color.
6378
"""
6479

6580
viz = drawable.Drawable(plt.figure(figsize=(10, 10)))
@@ -71,6 +86,22 @@ def test_label_style_line(self):
7186
self.assertEqual('A', str(label))
7287
self.assertEqual(label_style['color'], label.lines[0][0].get_color())
7388

89+
@MultiplexTest.temporary_plot
90+
def test_label_style_legend(self):
91+
"""
92+
Test that when drawing a time series label as a legend, the line color is not used.
93+
"""
94+
95+
viz = drawable.Drawable(plt.figure(figsize=(10, 10)))
96+
line_style = { 'color': '#FF0000' }
97+
line, label = viz.draw_time_series([ 1 ] * 5, [ 1 ] * 5, label='A',
98+
**line_style, with_legend=True)
99+
100+
self.assertEqual(1, len(viz.legend.lines[0]))
101+
line, label = viz.legend.lines[0][0]
102+
self.assertEqual('A', str(label))
103+
self.assertFalse(line_style['color'] == label.lines[0][0].get_color())
104+
74105
@MultiplexTest.temporary_plot
75106
def test_line_series(self):
76107
"""
0 Bytes
Binary file not shown.

multiplex/timeseries/timeseries.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,15 +103,16 @@ def draw(self, x, y, label=None, label_style=None, with_legend=False, *args, **k
103103
line = axis.plot(x, y, *args, **kwargs)[0]
104104

105105
"""
106-
Draw the label at the end of the line.
106+
Draw the label.
107+
If the label is drawn at the end of the line, by default it inherits the line's color.
107108
"""
108109
if label is not None and len(x) and len(y):
109-
default_label_style = { 'color': line.get_color() }
110-
default_label_style.update(label_style or { })
111110
if with_legend:
112-
self.drawable.legend.draw_line(label, label_style=default_label_style,
111+
self.drawable.legend.draw_line(label, label_style=label_style,
113112
*args, **kwargs)
114113
else:
114+
default_label_style = { 'color': line.get_color() }
115+
default_label_style.update(label_style or { })
115116
label = self.draw_label(label, x[-1], y[-1], **default_label_style)
116117

117118
return (line, label)

0 commit comments

Comments
 (0)