Skip to content

Commit da9dae8

Browse files
Tests for BUG-7023 allow style when using errorbars
1 parent d55b429 commit da9dae8

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

pandas/tests/plotting/frame/test_frame.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1959,6 +1959,47 @@ def _check_errorbar_color(containers, expected, has_err="has_xerr"):
19591959
_check_has_errorbars(ax, xerr=0, yerr=1)
19601960
_check_errorbar_color(ax.containers, "green", has_err="has_yerr")
19611961

1962+
def test_errorbar_plot_line_style(self):
1963+
def _check_line_style(ax, expected):
1964+
for line_num, line_data in enumerate(ax.get_lines()):
1965+
received = [
1966+
line_data.get_linestyle(),
1967+
line_data.get_color(),
1968+
line_data.get_marker(),
1969+
line_data.get_markeredgecolor(),
1970+
line_data.get_markerfacecolor(),
1971+
]
1972+
assert received == expected[line_num]
1973+
1974+
# GH 7023
1975+
data1 = np.array([9, 3, 5, 1, 7])
1976+
data2 = np.array([1, 2, 2, 8, 4])
1977+
err1 = data1 * 0.1
1978+
err2 = data2 * 0.1
1979+
df = DataFrame({"data1": data1, "data2": data2})
1980+
err_x = DataFrame({"data1": err1, "data2": err2})
1981+
err_y = DataFrame({"data1": err2, "data2": err1})
1982+
expected = [[":", "r", "o", "r", "r"], ["--", "g", "v", "g", "g"]]
1983+
1984+
# check for single line
1985+
ax = df["data1"].plot(xerr=err_x["data1"], yerr=err_y["data1"], style="or:")
1986+
num_lines = len(ax.get_lines())
1987+
_check_has_errorbars(ax, xerr=num_lines, yerr=num_lines)
1988+
_check_line_style(ax, expected)
1989+
1990+
# check for two lines on a single plot
1991+
ax = df.plot(xerr=err_x, yerr=err_y, style=["or:", "vg--"], subplots=False)
1992+
num_lines = len(ax.get_lines())
1993+
_check_has_errorbars(ax, xerr=num_lines, yerr=num_lines)
1994+
_check_line_style(ax, expected)
1995+
1996+
# check for two lines, each on separate subplots
1997+
axes = df.plot(xerr=err_x, yerr=err_y, style=["or:", "vg--"], subplots=True)
1998+
for ax_num, ax in enumerate(axes):
1999+
num_lines = len(ax.get_lines())
2000+
_check_has_errorbars(ax, xerr=num_lines, yerr=num_lines)
2001+
_check_line_style(ax, [expected[ax_num]])
2002+
19622003
def test_scatter_unknown_colormap(self):
19632004
# GH#48726
19642005
df = DataFrame({"a": [1, 2, 3], "b": 4})

0 commit comments

Comments
 (0)