Skip to content

Commit 1fc1f54

Browse files
committed
Add hex color strings test
1 parent c0f5cb1 commit 1fc1f54

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

doc/source/whatsnew/v0.17.1.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ Bug Fixes
6464

6565

6666

67-
67+
- Bug in ``DataFrame.plot`` cannot use hex strings colors (:issue:`10299`)
6868

6969

7070

pandas/tests/test_graphics.py

+26
Original file line numberDiff line numberDiff line change
@@ -2689,6 +2689,18 @@ def test_line_colors(self):
26892689
self._check_colors(ax.get_lines(), linecolors=['red'] * 5)
26902690
tm.close()
26912691

2692+
# GH 10299
2693+
custom_colors = ['#FF0000', '#0000FF', '#FFFF00', '#000000', '#FFFFFF']
2694+
ax = df.plot(color=custom_colors)
2695+
self._check_colors(ax.get_lines(), linecolors=custom_colors)
2696+
tm.close()
2697+
2698+
with tm.assertRaises(ValueError):
2699+
# Color contains shorthand hex value results in ValueError
2700+
custom_colors = ['#F00', '#00F', '#FF0', '#000', '#FFF']
2701+
# Forced show plot
2702+
_check_plot_works(df.plot, color=custom_colors)
2703+
26922704
@slow
26932705
def test_line_colors_and_styles_subplots(self):
26942706
# GH 9894
@@ -2725,6 +2737,20 @@ def test_line_colors_and_styles_subplots(self):
27252737
self._check_colors(ax.get_lines(), linecolors=[c])
27262738
tm.close()
27272739

2740+
# GH 10299
2741+
custom_colors = ['#FF0000', '#0000FF', '#FFFF00', '#000000', '#FFFFFF']
2742+
axes = df.plot(color=custom_colors, subplots=True)
2743+
for ax, c in zip(axes, list(custom_colors)):
2744+
self._check_colors(ax.get_lines(), linecolors=[c])
2745+
tm.close()
2746+
2747+
with tm.assertRaises(ValueError):
2748+
# Color contains shorthand hex value results in ValueError
2749+
custom_colors = ['#F00', '#00F', '#FF0', '#000', '#FFF']
2750+
# Forced show plot
2751+
_check_plot_works(df.plot, color=custom_colors, subplots=True,
2752+
filterwarnings='ignore')
2753+
27282754
rgba_colors = lmap(cm.jet, np.linspace(0, 1, len(df)))
27292755
for cmap in ['jet', cm.jet]:
27302756
axes = df.plot(colormap=cmap, subplots=True)

0 commit comments

Comments
 (0)