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

Skip to content

Commit dbc1fd1

Browse files
committed
Add the "contour.linewidths" configuration option
It defaults to None whcih makes it to fallback to "lines.linewidth" option.
1 parent 6372f1d commit dbc1fd1

3 files changed

Lines changed: 24 additions & 3 deletions

File tree

lib/matplotlib/contour.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1257,7 +1257,10 @@ def _process_linewidths(self):
12571257
linewidths = self.linewidths
12581258
Nlev = len(self.levels)
12591259
if linewidths is None:
1260-
tlinewidths = [(mpl.rcParams['lines.linewidth'],)] * Nlev
1260+
default_linewidth = mpl.rcParams['contour.linewidths']
1261+
if default_linewidth is None:
1262+
default_linewidth = mpl.rcParams['lines.linewidth']
1263+
tlinewidths = [(default_linewidth,)] * Nlev
12611264
else:
12621265
if not np.iterable(linewidths):
12631266
linewidths = [linewidths] * Nlev
@@ -1749,7 +1752,7 @@ def _initialize_x_y(self, z):
17491752
however introduce rendering artifacts at chunk boundaries depending
17501753
on the backend, the *antialiased* flag and value of *alpha*.
17511754
1752-
linewidths : float or sequence of float, default: :rc:`lines.linewidth`
1755+
linewidths : float or sequence of float
17531756
*Only applies to* `.contour`.
17541757
17551758
The line width of the contour lines.
@@ -1759,6 +1762,9 @@ def _initialize_x_y(self, z):
17591762
If a sequence, the levels in ascending order will be plotted with
17601763
the linewidths in the order specified.
17611764
1765+
Defaults to :rc:`contour.linewidths`. If this value is None,
1766+
it falls back to :rc:`lines.linewidth`.
1767+
17621768
linestyles : {*None*, 'solid', 'dashed', 'dashdot', 'dotted'}, optional
17631769
*Only applies to* `.contour`.
17641770

lib/matplotlib/rcsetup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1195,6 +1195,7 @@ def _convert_validator_spec(key, conv):
11951195
# contour props
11961196
'contour.negative_linestyle': ['dashed', _validate_linestyle],
11971197
'contour.corner_mask': [True, validate_bool],
1198+
'contour.linewidths': [None, validate_float_or_None],
11981199

11991200
# errorbar props
12001201
'errorbar.capsize': [0, validate_float],

lib/matplotlib/tests/test_contour.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from numpy.testing import assert_array_almost_equal
66
import matplotlib as mpl
77
from matplotlib.testing.decorators import image_comparison
8-
from matplotlib import pyplot as plt
8+
from matplotlib import pyplot as plt, rc_context
99
from matplotlib.colors import LogNorm
1010
import pytest
1111

@@ -375,3 +375,17 @@ def test_contour_uneven():
375375
ax = axs[1]
376376
cs = ax.contourf(z, levels=[2, 4, 6, 10, 20])
377377
fig.colorbar(cs, ax=ax, spacing='uniform')
378+
379+
380+
@pytest.mark.parametrize("rcll, rccl, fcl, expected", [
381+
(1.23, None, None, 1.23),
382+
(1.23, 4.24, None, 4.24),
383+
(1.23, 4.24, 5.02, 5.02)
384+
])
385+
def test_contour_linewidths(rcll, rccl, fcl, expected):
386+
387+
with rc_context(rc={"lines.linewidth": rcll, "contour.linewidths": rccl}):
388+
fig, ax = plt.subplots()
389+
X = np.arange(4*3).reshape(4, 3)
390+
cs = ax.contour(X, linewidths=fcl)
391+
assert cs.tlinewidths[0][0] == expected

0 commit comments

Comments
 (0)