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

Skip to content

Commit 2d6d820

Browse files
committed
updated implementation for iss-16482 inline with review comments
removed unnecessary import of image_comparator decorator running boilerplate.py to update vlines/hlines methods
1 parent 101aaf6 commit 2d6d820

File tree

4 files changed

+36
-39
lines changed

4 files changed

+36
-39
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1116,8 +1116,8 @@ def axvspan(self, xmin, xmax, ymin=0, ymax=1, **kwargs):
11161116

11171117
@_preprocess_data(replace_names=["y", "xmin", "xmax", "colors"],
11181118
label_namer="y")
1119-
def hlines(self, y, xmin, xmax, colors=rcParams['lines.color'] or 'k',
1120-
linestyles='solid', label='', **kwargs):
1119+
def hlines(self, y, xmin, xmax, colors=None, linestyles='solid',
1120+
label='', **kwargs):
11211121
"""
11221122
Plot horizontal lines at each *y* from *xmin* to *xmax*.
11231123
@@ -1130,7 +1130,7 @@ def hlines(self, y, xmin, xmax, colors=rcParams['lines.color'] or 'k',
11301130
Respective beginning and end of each line. If scalars are
11311131
provided, all lines will have same length.
11321132
1133-
colors : array-like of colors, default: rcParams['lines.color'] or 'k'
1133+
colors : array-like of colors, default: None
11341134
11351135
linestyles : {'solid', 'dashed', 'dashdot', 'dotted'}, optional
11361136
@@ -1157,6 +1157,8 @@ def hlines(self, y, xmin, xmax, colors=rcParams['lines.color'] or 'k',
11571157
xmin = self.convert_xunits(xmin)
11581158
xmax = self.convert_xunits(xmax)
11591159

1160+
colors = rcParams['lines.color'] or 'k' if colors is None else colors
1161+
11601162
if not np.iterable(y):
11611163
y = [y]
11621164
if not np.iterable(xmin):
@@ -1196,8 +1198,8 @@ def hlines(self, y, xmin, xmax, colors=rcParams['lines.color'] or 'k',
11961198

11971199
@_preprocess_data(replace_names=["x", "ymin", "ymax", "colors"],
11981200
label_namer="x")
1199-
def vlines(self, x, ymin, ymax, colors=rcParams['lines.color'] or 'k',
1200-
linestyles='solid', label='', **kwargs):
1201+
def vlines(self, x, ymin, ymax, colors=None, linestyles='solid',
1202+
label='', **kwargs):
12011203
"""
12021204
Plot vertical lines.
12031205
@@ -1212,7 +1214,7 @@ def vlines(self, x, ymin, ymax, colors=rcParams['lines.color'] or 'k',
12121214
Respective beginning and end of each line. If scalars are
12131215
provided, all lines will have same length.
12141216
1215-
colors : array-like of colors, default: rcParams['lines.color'] or 'k'
1217+
colors : array-like of colors, default: None
12161218
12171219
linestyles : {'solid', 'dashed', 'dashdot', 'dotted'}, optional
12181220
@@ -1239,6 +1241,8 @@ def vlines(self, x, ymin, ymax, colors=rcParams['lines.color'] or 'k',
12391241
ymin = self.convert_yunits(ymin)
12401242
ymax = self.convert_yunits(ymax)
12411243

1244+
colors = rcParams['lines.color'] or 'k' if colors is None else colors
1245+
12421246
if not np.iterable(x):
12431247
x = [x]
12441248
if not np.iterable(ymin):

lib/matplotlib/pyplot.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2547,8 +2547,8 @@ def hist2d(
25472547
# Autogenerated by boilerplate.py. Do not edit as changes will be lost.
25482548
@_copy_docstring_and_deprecators(Axes.hlines)
25492549
def hlines(
2550-
y, xmin, xmax, colors=rcParams['lines.color'] or 'k',
2551-
linestyles='solid', label='', *, data=None, **kwargs):
2550+
y, xmin, xmax, colors=None, linestyles='solid', label='', *,
2551+
data=None, **kwargs):
25522552
return gca().hlines(
25532553
y, xmin, xmax, colors=colors, linestyles=linestyles,
25542554
label=label, **({"data": data} if data is not None else {}),
@@ -2918,8 +2918,8 @@ def violinplot(
29182918
# Autogenerated by boilerplate.py. Do not edit as changes will be lost.
29192919
@_copy_docstring_and_deprecators(Axes.vlines)
29202920
def vlines(
2921-
x, ymin, ymax, colors=rcParams['lines.color'] or 'k',
2922-
linestyles='solid', label='', *, data=None, **kwargs):
2921+
x, ymin, ymax, colors=None, linestyles='solid', label='', *,
2922+
data=None, **kwargs):
29232923
return gca().vlines(
29242924
x, ymin, ymax, colors=colors, linestyles=linestyles,
29252925
label=label, **({"data": data} if data is not None else {}),

lib/matplotlib/tests/test_axes.py

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3745,7 +3745,7 @@ def test_axline_args():
37453745
ax.axline((0, 0), slope=1)
37463746

37473747

3748-
@image_comparison(['vlines_basic', 'vlines_with_nan', 'vlines_masked', 'vlines_rc_params'],
3748+
@image_comparison(['vlines_basic', 'vlines_with_nan', 'vlines_masked'],
37493749
extensions=['png'])
37503750
def test_vlines():
37513751
# normal
@@ -3784,14 +3784,19 @@ def test_vlines():
37843784
ax5.vlines(x5, ymin5, ymax5, colors='k', linewidth=2)
37853785
ax5.set_xlim(0, 15)
37863786

3787-
# check that vlines() correctly defaults to rcParams['lines.color']
3788-
fig4, ax6 = plt.subplots()
3789-
with mpl.rc_context({'lines.color': 'blue'}):
3790-
ax6.vlines(0.5, 0, 1)
3791-
ax6.hlines(0.5, 0, 1, colors='k')
3787+
3788+
@check_figures_equal(extensions=["png"])
3789+
def test_vlines_default(fig_test, fig_ref):
3790+
ax_test = fig_test.subplots()
3791+
ax_ref = fig_ref.subplots()
3792+
3793+
# compare constructing the reference with given value to configured rcParams on test
3794+
ax_ref.vlines(0.5, 0, 1, colors='red')
3795+
with mpl.rc_context({'lines.color': 'red'}):
3796+
ax_test.vlines(0.5, 0, 1)
37923797

37933798

3794-
@image_comparison(['hlines_basic', 'hlines_with_nan', 'hlines_masked', 'hlines_rc_params'],
3799+
@image_comparison(['hlines_basic', 'hlines_with_nan', 'hlines_masked'],
37953800
extensions=['png'])
37963801
def test_hlines():
37973802
# normal
@@ -3830,11 +3835,16 @@ def test_hlines():
38303835
ax5.hlines(y5, xmin5, xmax5, colors='k', linewidth=2)
38313836
ax5.set_ylim(0, 15)
38323837

3833-
# check that hlines() correctly defaults to rcParams['lines.color']
3834-
fig4, ax6 = plt.subplots()
3835-
with mpl.rc_context({'lines.color': 'blue'}):
3836-
ax6.hlines(0.5, 0, 1)
3837-
ax6.vlines(0.5, 0, 1, colors='k')
3838+
3839+
@check_figures_equal(extensions=["png"])
3840+
def test_hlines_default(fig_test, fig_ref):
3841+
ax_test = fig_test.subplots()
3842+
ax_ref = fig_ref.subplots()
3843+
3844+
# compare constructing the reference with given value to configured rcParams on test
3845+
ax_ref.hlines(0.5, 0, 1, colors='red')
3846+
with mpl.rc_context({'lines.color': 'red'}):
3847+
ax_test.hlines(0.5, 0, 1)
38383848

38393849

38403850
@pytest.mark.parametrize('data', [[1, 2, 3, np.nan, 5],

lib/matplotlib/tests/test_pyplot.py

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import pytest
77

88
import matplotlib as mpl
9-
from matplotlib.testing.decorators import image_comparison
109
from matplotlib import pyplot as plt
1110
from matplotlib.cbook import MatplotlibDeprecationWarning
1211

@@ -82,19 +81,3 @@ def test_nrows_error():
8281
plt.subplot(nrows=1)
8382
with pytest.raises(TypeError):
8483
plt.subplot(ncols=1)
85-
86-
87-
@image_comparison(['vlines_rc_params'], extensions=['png'])
88-
def test_vlines():
89-
plt.figure()
90-
with mpl.rc_context({'lines.color': 'blue'}):
91-
plt.vlines(0.5, 0, 1)
92-
plt.hlines(0.5, 0, 1, colors='k')
93-
94-
95-
@image_comparison(['hlines_rc_params'], extensions=['png'])
96-
def test_hlines():
97-
plt.figure()
98-
with mpl.rc_context({'lines.color': 'blue'}):
99-
plt.hlines(0.5, 0, 1)
100-
plt.vlines(0.5, 0, 1, colors='k')

0 commit comments

Comments
 (0)