Skip to content

Commit 20d7d81

Browse files
Contour kwarg for negative_linestyles
1 parent 1b2a3c9 commit 20d7d81

1 file changed

Lines changed: 21 additions & 3 deletions

File tree

lib/matplotlib/contour.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -724,7 +724,7 @@ def __init__(self, ax, *args,
724724
hatches=(None,), alpha=None, origin=None, extent=None,
725725
cmap=None, colors=None, norm=None, vmin=None, vmax=None,
726726
extend='neither', antialiased=None, nchunk=0, locator=None,
727-
transform=None,
727+
transform=None, negative_linestyles=None,
728728
**kwargs):
729729
"""
730730
Draw contour lines or filled regions, depending on
@@ -809,6 +809,13 @@ def __init__(self, ax, *args,
809809

810810
self._transform = transform
811811

812+
self.negative_linestyles = negative_linestyles
813+
# If negative_linestyles was not defined as a kwarg,
814+
# define negative_linestyles with rcParams
815+
if self.negative_linestyles is None:
816+
self.negative_linestyles = \
817+
mpl.rcParams['contour.negative_linestyle']
818+
812819
kwargs = self._process_args(*args, **kwargs)
813820
self._process_levels()
814821

@@ -1299,11 +1306,10 @@ def _process_linestyles(self):
12991306
if linestyles is None:
13001307
tlinestyles = ['solid'] * Nlev
13011308
if self.monochrome:
1302-
neg_ls = mpl.rcParams['contour.negative_linestyle']
13031309
eps = - (self.zmax - self.zmin) * 1e-15
13041310
for i, lev in enumerate(self.levels):
13051311
if lev < eps:
1306-
tlinestyles[i] = neg_ls
1312+
tlinestyles[i] = self.negative_linestyles
13071313
else:
13081314
if isinstance(linestyles, str):
13091315
tlinestyles = [linestyles] * Nlev
@@ -1764,6 +1770,18 @@ def _initialize_x_y(self, z):
17641770
iterable is shorter than the number of contour levels
17651771
it will be repeated as necessary.
17661772
1773+
negative_linestyles : *None* or str, optional
1774+
{'solid', 'dashed', 'dashdot', 'dotted'}
1775+
*Only applies to* `.contour`.
1776+
1777+
If *negative_linestyles* is *None*, the default is 'dashed' for
1778+
negative contours.
1779+
1780+
*negative_linestyles* can also be an iterable of the above
1781+
strings specifying a set of linestyles to be used. If this
1782+
iterable is shorter than the number of contour levels
1783+
it will be repeated as necessary.
1784+
17671785
hatches : list[str], optional
17681786
*Only applies to* `.contourf`.
17691787

0 commit comments

Comments
 (0)