Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix box(en)plot colour tests #2693

Merged
merged 1 commit into from
Nov 26, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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