Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a56811c

Browse files
committed
Deleted baseline images, changed test
1 parent f0c6544 commit a56811c

File tree

4 files changed

+29
-23
lines changed

4 files changed

+29
-23
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7214,11 +7214,12 @@ def hist(self, x, bins=None, range=None, density=False, weights=None,
72147214
# cast each element to str, but keep a single str as it.
72157215
labels = [] if label is None else np.atleast_1d(np.asarray(label, str))
72167216

7217-
if histtype.startswith('bar') or histtype == 'stepfilled':
7218-
edgecolors = itertools.cycle(np.atleast_1d(kwargs.get('edgecolor', None)))
7219-
else:
7217+
if histtype == "step":
72207218
edgecolors = itertools.cycle(np.atleast_1d(kwargs.get('edgecolor',
72217219
colors)))
7220+
else:
7221+
edgecolors = itertools.cycle(np.atleast_1d(kwargs.get("edgecolor", None)))
7222+
72227223
facecolors = itertools.cycle(np.atleast_1d(kwargs.get('facecolor', colors)))
72237224
hatches = itertools.cycle(np.atleast_1d(kwargs.get('hatch', None)))
72247225
linewidths = itertools.cycle(np.atleast_1d(kwargs.get('linewidth', None)))
Binary file not shown.
Binary file not shown.

lib/matplotlib/tests/test_axes.py

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4603,29 +4603,34 @@ def test_hist_stacked_bar():
46034603
ax.legend(loc='upper right', bbox_to_anchor=(1.0, 1.0), ncols=1)
46044604

46054605

4606-
@image_comparison(['hist_vectorized_params_bar', 'hist_vectorized_params_step'],
4607-
extensions=["png"], remove_text=True)
4608-
def test_hist_vectorized_params():
4606+
@pytest.mark.parametrize("histtype", ["step", "stepfilled"])
4607+
@pytest.mark.parametrize("color", [["blue", "green", "brown"], [None]*3])
4608+
@pytest.mark.parametrize("edgecolor", [["red", "black", "blue"], [None]*3])
4609+
@pytest.mark.parametrize("facecolor", [["blue", "green", "brown"], [None]*3])
4610+
@pytest.mark.parametrize("linewidth", [[1, 1.5, 2], [None]*3])
4611+
@pytest.mark.parametrize("hatch", [["/", "\\", "."], [None]*3])
4612+
@pytest.mark.parametrize("linestyle", [["-", "--", ":"], [None]*3])
4613+
@check_figures_equal(extensions=["png"])
4614+
def test_hist_vectorized_params(fig_test, fig_ref, histtype, color, edgecolor,
4615+
facecolor, linewidth, hatch, linestyle):
46094616
np.random.seed(19680801)
46104617
x = [np.random.randn(n) for n in [2000, 5000, 10000]]
46114618

4612-
for histtype in ['bar', 'step']:
4613-
fig, axs = plt.subplots(2, 3, figsize=(8, 6))
4614-
fig.delaxes(axs[1, 1])
4615-
ax1, ax2, ax3, ax4, _, ax6 = axs.flatten()
4616-
4617-
# Only linestyle
4618-
ax1.hist(x, bins=10, histtype=histtype, linestyle=["-", "--", ":"])
4619-
# Only edgecolor
4620-
ax2.hist(x, bins=10, histtype=histtype,
4621-
edgecolor=["red", "black", "blue"])
4622-
# Only facecolor
4623-
ax3.hist(x, bins=10, histtype=histtype,
4624-
facecolor=["blue", "yellow", "brown"])
4625-
# Only linewidth
4626-
ax4.hist(x, bins=10, histtype=histtype, linewidth=[1, 1.5, 2])
4627-
# Only hatch
4628-
ax6.hist(x, bins=10, histtype=histtype, hatch=["/", "\\", "."])
4619+
facecolor = facecolor if facecolor[0] is not None else color
4620+
if histtype == "step":
4621+
edgecolor = edgecolor if edgecolor[0] is not None else color
4622+
4623+
_, bins, _ = fig_test.subplots().hist(x, bins=10, histtype=histtype, color=color,
4624+
edgecolor=edgecolor, facecolor=facecolor,
4625+
linewidth=linewidth, hatch=hatch,
4626+
linestyle=linestyle)
4627+
ref_ax = fig_ref.subplots()
4628+
4629+
for xi, c, ec, fc, lw, hs, ls in zip(x, color[::-1], edgecolor[::-1],
4630+
facecolor[::-1], linewidth[::-1],
4631+
hatch[::-1], linestyle[::-1]):
4632+
ref_ax.hist(xi, bins=bins, histtype=histtype, color=c, edgecolor=ec,
4633+
facecolor=fc, linewidth=lw, hatch=hs, linestyle=ls)
46294634

46304635

46314636
def test_hist_barstacked_bottom_unchanged():

0 commit comments

Comments
 (0)