Skip to content

Commit

Permalink
Fix box(en)plot colour tests
Browse files Browse the repository at this point in the history
As was noted in
#2663 (comment),
the `test_box_colors` tests are broken because `zip` only iterates to
the shortest input.

For boxplot, there are in fact 3 copies of the palette not 2.

For boxenplot, it doesn't add `Patch` at all but `PatchCollection`, as
can be seen in the related tests.
  • Loading branch information
QuLogic committed Nov 4, 2021
1 parent b13dfdb commit 7fa9a37
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions seaborn/tests/test_categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import pandas as pd
import matplotlib as mpl
import matplotlib.pyplot as plt
from matplotlib.colors import rgb2hex, to_rgb, to_rgba
from matplotlib.colors import rgb2hex, same_color, to_rgb, to_rgba

import pytest
from pytest import approx
Expand Down Expand Up @@ -876,15 +876,15 @@ def test_box_colors(self):

ax = cat.boxplot(x="g", y="y", data=self.df, saturation=1)
pal = palettes.color_palette(n_colors=3)
for patch, color in zip(self.get_box_artists(ax), pal):
assert patch.get_facecolor()[:3] == color
assert same_color([patch.get_facecolor() for patch in self.get_box_artists(ax)],
pal)

plt.close("all")

ax = cat.boxplot(x="g", y="y", hue="h", data=self.df, saturation=1)
pal = palettes.color_palette(n_colors=2)
for patch, color in zip(self.get_box_artists(ax), pal * 2):
assert patch.get_facecolor()[:3] == color
assert same_color([patch.get_facecolor() for patch in self.get_box_artists(ax)],
pal * 3)

plt.close("all")

Expand Down Expand Up @@ -3143,17 +3143,19 @@ def test_axes_data(self):

def test_box_colors(self):

fig = plt.figure()
ax = cat.boxenplot(x="g", y="y", data=self.df, saturation=1)
fig.canvas.draw()
pal = palettes.color_palette(n_colors=3)
for patch, color in zip(self.get_box_artists(ax), pal):
assert patch.get_facecolor()[:3] == color

plt.close("all")
patches = filter(self.ispatch, ax.collections)
assert same_color([patch.get_facecolor()[0] for patch in patches], pal)

fig = plt.figure()
ax = cat.boxenplot(x="g", y="y", hue="h", data=self.df, saturation=1)
fig.canvas.draw()
pal = palettes.color_palette(n_colors=2)
for patch, color in zip(self.get_box_artists(ax), pal * 2):
assert patch.get_facecolor()[:3] == color
patches = filter(self.ispatch, ax.collections)
assert same_color([patch.get_facecolor()[0] for patch in patches], pal * 3)

plt.close("all")

Expand Down

0 comments on commit 7fa9a37

Please sign in to comment.