8000 changed 'colors' parameter to default to rcParams['lines.color'] in l… · CSCD01-team31/matplotlib@62b6a0c · GitHub
[go: up one dir, main page]

Skip to content

Commit 62b6a0c

Browse files
committed
changed 'colors' parameter to default to rcParams['lines.color'] in line with issue matplotlib#16482
added test coverage for changes to pyplot hlines() and vlines() interface adding API changes to api_changes updated Axes.vlines and Axes.hline docstring inline with changes updated spacing to be 2 line compliant
1 parent d1f07d3 commit 62b6a0c

File tree

5 files changed

+56
-13
lines changed

5 files changed

+56
-13
lines changed

doc/api/next_api_changes/behaviour.rst

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ deprecation warning.
100100

101101
Previously setting the *ecolor* would turn off automatic color cycling for the plot, leading to the
102102
the lines and markers defaulting to whatever the first color in the color cycle was in the case of
103-
multiple plot calls.
103+
multiple plot calls.
104104

105105
`.rcsetup.validate_color_for_prop_cycle` now always raises TypeError for bytes input
106106
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -155,3 +155,17 @@ support for it will be dropped in a future Matplotlib release.
155155
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
156156
Previously, keyword arguments were silently ignored when no positional
157157
arguments were given.
158+
159+
`Axes.vlines` and `Axes.hlines` `color` parameter will now default to configured rcparams `lines.color`
160+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
161+
162+
Previously the `color` parameter in `Axes.vlines` and `Axes.hlines` would always default to 'k' if not provided.
163+
This was inconsistent with the rest of the API and now `color` will instead default to the configured rcparam's
164+
`lines.color` value, falling back to 'k' if necessary.
165+
166+
`pyplot.vlines` and `pyplot.hlines` `color` parameter will now default to configured rcparams `lines.color`
167+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
168+
169+
Previously the `color` parameter in `pyplot.vlines` and `pyplot.hlines` would always default to 'k' if not provided.
170+
This was inconsistent with the rest of the API and now `color` will instead default to the configured rcparam's
171+
`lines.color` value, falling back to 'k' if necessary.

lib/matplotlib/axes/_axes.py

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

11031103
@_preprocess_data(replace_names=["y", "xmin", "xmax", "colors"],
11041104
label_namer="y")
1105-
def hlines(self, y, xmin, xmax, colors='k', linestyles='solid',
1106-
label='', **kwargs):
1105+
def hlines(self, y, xmin, xmax, colors=rcParams['lines.color'] or 'k',
1106+
linestyles='solid', label='', **kwargs):
11071107
"""
11081108
Plot horizontal lines at each *y* from *xmin* to *xmax*.
11091109
@@ -1116,7 +1116,7 @@ def hlines(self, y, xmin, xmax, colors='k', linestyles='solid',
11161116
Respective beginning and end of each line. If scalars are
11171117
provided, all lines will have same length.
11181118
1119-
colors : array-like of colors, default: 'k'
1119+
colors : array-like of colors, default: rcParams['lines.color'] or 'k'
11201120
11211121
linestyles : {'solid', 'dashed', 'dashdot', 'dotted'}, optional
11221122
@@ -1182,8 +1182,8 @@ def hlines(self, y, xmin, xmax, colors='k', linestyles='solid',
11821182

11831183
@_preprocess_data(replace_names=["x", "ymin", "ymax", "colors"],
11841184
label_namer="x")
1185-
def vlines(self, x, ymin, ymax, colors='k', linestyles='solid',
1186-
label='', **kwargs):
1185+
def vlines(self, x, ymin, ymax, colors=rcParams['lines.color'] or 'k',
1186+
linestyles='solid', label='', **kwargs):
11871187
"""
11881188
Plot vertical lines.
11891189
@@ -1198,7 +1198,7 @@ def vlines(self, x, ymin, ymax, colors='k', linestyles='solid',
11981198
Respective beginning and end of each line. If scalars are
11991199
provided, all lines will have same length.
12001200
1201-
colors : array-like of colors, default: 'k'
1201+
colors : array-like of colors, default: rcParams['lines.color'] or 'k'
12021202
12031203
linestyles : {'solid', 'dashed', 'dashdot', 'dotted'}, optional
12041204

lib/matplotlib/pyplot.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2533,8 +2533,8 @@ def hist2d(
25332533
# Autogenerated by boilerplate.py. Do not edit as changes will be lost.
25342534
@_copy_docstring_and_deprecators(Axes.hlines)
25352535
def hlines(
2536-
y, xmin, xmax, colors='k', linestyles='solid', label='', *,
2537-
data=None, **kwargs):
2536+
y, xmin, xmax, colors=rcParams['lines.color'] or 'k',
2537+
linestyles='solid', label='', *, data=None, **kwargs):
25382538
return gca().hlines(
25392539
y, xmin, xmax, colors=colors, linestyles=linestyles,
25402540
label=label, **({"data": data} if data is not None else {}),
@@ -2904,8 +2904,8 @@ def violinplot(
29042904
# Autogenerated by boilerplate.py. Do not edit as changes will be lost.
29052905
@_copy_docstring_and_deprecators(Axes.vlines)
29062906
def vlines(
2907-
x, ymin, ymax, colors='k', linestyles='solid', label='', *,
2908-
data=None, **kwargs):
2907+
x, ymin, ymax, colors=rcParams['lines.color'] or 'k',
2908+
linestyles='solid', label='', *, data=None, **kwargs):
29092909
return gca().vlines(
29102910
x, ymin, ymax, colors=colors, linestyles=linestyles,
29112911
label=label, **({"data": data} if data is not None else {}),

lib/matplotlib/tests/test_axes.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3963,7 +3963,7 @@ def test_axline_args():
39633963
ax.axline((0, 0), slope=1)
39643964

39653965

3966-
@image_comparison(['vlines_basic', 'vlines_with_nan', 'vlines_masked'],
3966+
@image_comparison(['vlines_basic', 'vlines_with_nan', 'vlines_masked', 'vlines_rc_params'],
39673967
extensions=['png'])
39683968
def test_vlines():
39693969
# normal
@@ -4002,8 +4002,14 @@ def test_vlines():
40024002
ax5.vlines(x5, ymin5, ymax5, colors='k', linewidth=2)
40034003
ax5.set_xlim(0, 15)
40044004

4005+
# check that vlines() correctly defaults to rcParams['lines.color']
4006+
fig4, ax6 = plt.subplots()
4007+
with mpl.rc_context({'lines.color': 'blue'}):
4008+
ax6.vlines(0.5, 0, 1)
4009+
ax6.hlines(0.5, 0, 1, colors='k')
40054010

4006-
@image_comparison(['hlines_basic', 'hlines_with_nan', 'hlines_masked'],
4011+
4012+
@image_comparison(['hlines_basic', 'hlines_with_nan', 'hlines_masked', 'hlines_rc_params'],
40074013
extensions=['png'])
40084014
def test_hlines():
40094015
# normal
@@ -4042,6 +4048,12 @@ def test_hlines():
40424048
ax5.hlines(y5, xmin5, xmax5, colors='k', linewidth=2)
40434049
ax5.set_ylim(0, 15)
40444050

4051+
# check that hlines() correctly defaults to rcParams['lines.color']
4052+
fig4, ax6 = plt.subplots()
4053+
with mpl.rc_context({'lines.color': 'blue'}):
4054+
ax6.hlines(0.5, 0, 1)
4055+
ax6.vlines(0.5, 0, 1, colors='k')
4056+
40454057

40464058
@pytest.mark.parametrize('data', [[1, 2, 3, np.nan, 5],
40474059
np.ma.masked_equal([1, 2, 3, 4, 5], 4)])

lib/matplotlib/tests/test_pyplot.py

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

88
import matplotlib as mpl
9+
from matplotlib.testing.decorators import image_comparison
910
from matplotlib import pyplot as plt
1011
from matplotlib.cbook import MatplotlibDeprecationWarning
1112

@@ -81,3 +82,19 @@ def test_nrows_error():
8182
plt.subplot(nrows=1)
8283
with pytest.raises(TypeError):
8384
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)
0